Skip to content

Commit 9ebb459

Browse files
committed
fix(FR-1324): Preserve query parameters when navigating via breadcrumb in FileExplorer (#4071)
resolves #4059 ([FR-1324](https://lablup.atlassian.net/browse/FR-1324)) Implement path persistence in file explorer using URL query parameters. This allows users to: - Navigate through folders and maintain the current path in the URL Todo in next step: - Return to the same folder location when reopening the file explorer - Share links that open directly to specific folder locations Additional implementations: - Delete LegacyFolderExplorer component > Replace with FolderExplorer component - Delete unused explorer-related components The implementation uses the `use-query-params` library to synchronize the file explorer's current path with the URL query parameters. When navigating through folders, the path is updated in the URL, and when reopening the explorer, it restores the last viewed path. **Checklist:** (if applicable) - [x] Documentation - [ ] Minium required manager version - [ ] Specific setting for review (eg., KB link, endpoint or how to setup) - [ ] Minimum requirements to check during review - [ ] Test case(s) to demonstrate the difference of before/after [FR-1324]: https://lablup.atlassian.net/browse/FR-1324?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent 327e6ba commit 9ebb459

File tree

29 files changed

+378
-559
lines changed

29 files changed

+378
-559
lines changed

packages/backend.ai-ui/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
},
5656
"peerDependencies": {
5757
"@ant-design/icons": "^5.6.1",
58+
"@tanstack/react-query": "^5.69.0",
59+
"ahooks": "^3.8.4",
5860
"antd": "^5.24.5",
5961
"antd-style": "^3.7.1",
6062
"graphql": "^16.10.0",
@@ -77,10 +79,11 @@
7779
"dayjs": "^1.11.13",
7880
"lodash": "^4.17.21",
7981
"lucide-react": "^0.484.0",
82+
"relay-runtime": "^20.1.0",
8083
"react-resizable": "^3.0.5",
8184
"react-copy-to-clipboard": "^5.1.0",
82-
"tus-js-client": "^4.1.0",
83-
"@tanstack/react-query": "^5.69.0"
85+
"@tanstack/react-query": "^5.69.0",
86+
"use-query-params": "^2.2.1"
8487
},
8588
"devDependencies": {
8689
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
@@ -116,7 +119,6 @@
116119
"jest-environment-jsdom": "^29.7.0",
117120
"storybook": "^9.1.1",
118121
"ts-jest": "^29.2.5",
119-
"tus-js-client": "^4.1.0",
120122
"typescript": "^5.7.2",
121123
"vite": "^6.3.5",
122124
"vite-plugin-dts": "^4.5.4",

packages/backend.ai-ui/src/components/baiClient/FileExplorer/BAIFileExplorer.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ const BAIFileExplorer: React.FC<BAIFileExplorerProps> = ({
105105
const items: Array<ItemType> = [
106106
{
107107
title: <HomeOutlined />,
108-
href: '',
109108
onClick: () => {
110109
navigateToPath('.');
111110
setSelectedItems([]);
@@ -143,7 +142,6 @@ const BAIFileExplorer: React.FC<BAIFileExplorerProps> = ({
143142

144143
items.push({
145144
title: part,
146-
href: '',
147145
onClick: () => {
148146
navigateToPath(navigatePath);
149147
setSelectedItems([]);
@@ -248,7 +246,14 @@ const BAIFileExplorer: React.FC<BAIFileExplorerProps> = ({
248246
<FolderInfoContext.Provider value={{ targetVFolderId, currentPath }}>
249247
<BAIFlex direction="column" align="stretch" gap="md">
250248
<BAIFlex align="center" justify="between">
251-
<Breadcrumb items={breadCrumbItems} />
249+
<Breadcrumb
250+
items={breadCrumbItems}
251+
itemRender={(item) => (
252+
<Typography.Link onClick={item.onClick}>
253+
{item.title}
254+
</Typography.Link>
255+
)}
256+
/>
252257
<ExplorerActionControls
253258
selectedFiles={selectedItems}
254259
onUpload={(files, currentPath) => onUpload(files, currentPath)}
@@ -303,7 +308,7 @@ const BAIFileExplorer: React.FC<BAIFileExplorerProps> = ({
303308
);
304309
if (isSelected) {
305310
setSelectedItems(
306-
selectedItems.filter((item) => item.name !== record.name),
311+
selectedItems?.filter((item) => item.name !== record.name),
307312
);
308313
} else {
309314
setSelectedItems([...selectedItems, record]);

packages/backend.ai-ui/src/components/baiClient/FileExplorer/hooks.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@ import useConnectedBAIClient from '../../provider/BAIClientProvider/hooks/useCon
22
import { VFolderFile } from '../../provider/BAIClientProvider/types';
33
import { useQuery } from '@tanstack/react-query';
44
import { useState } from 'react';
5+
import { StringParam, useQueryParam, withDefault } from 'use-query-params';
56

67
export const useSearchVFolderFiles = (vfolder: string) => {
78
const baiClient = useConnectedBAIClient();
89
const [currentPath, setCurrentPath] = useState<string>('.');
10+
const [, setCurrentPathParam] = useQueryParam(
11+
'path',
12+
withDefault(StringParam, '.'),
13+
);
914
const [directoryTree, setDirectoryTree] = useState<
1015
Record<string, Array<VFolderFile>>
1116
>({});
@@ -14,18 +19,26 @@ export const useSearchVFolderFiles = (vfolder: string) => {
1419
const newPath =
1520
currentPath === '.' ? folderName : `${currentPath}/${folderName}`;
1621
setCurrentPath(newPath);
22+
setCurrentPathParam(newPath);
1723
};
1824

1925
const navigateUp = () => {
2026
const pathParts = currentPath.split('/');
2127
if (pathParts.length > 1) {
28+
const newPath = pathParts.join('/');
2229
pathParts.pop();
23-
setCurrentPath(pathParts.join('/') || '.');
30+
setCurrentPath(newPath || '.');
31+
newPath === '.'
32+
? setCurrentPathParam(null, 'replaceIn')
33+
: setCurrentPathParam(newPath);
2434
}
2535
};
2636

2737
const navigateToPath = (path: string) => {
2838
setCurrentPath(path);
39+
path === '.'
40+
? setCurrentPathParam(null, 'replaceIn')
41+
: setCurrentPathParam(path);
2942
};
3043

3144
const {

pnpm-lock.yaml

Lines changed: 132 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

react/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"typescript": "^5.7.2",
7373
"use-query-params": "^2.2.1",
7474
"uuid": "^9.0.1",
75-
"web-vitals": "^3.5.2"
75+
"web-vitals": "^3.5.2",
76+
"tus-js-client": "^4.1.0"
7677
},
7778
"scripts": {
7879
"start": "craco start",

react/src/components/FolderDownloadButton.tsx

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)