Skip to content

Commit e594eda

Browse files
tcnichollongshuicylmarini
authored
202 file breadcrumb folders not in breadcrumb for files fixed (#214)
* folder.folderPath not dataset.folderPath * fix one bug * fix the other bug * This fixes the breadcrumb navigation after file is uploaded. Previously folder was not passed in. * Fixed a bug when passing in folder=null to the file page. * Fixed bad merge. * add back missing folder id * add another missing import * Fixed bad merge. * add breadcrumb back for dataset Co-authored-by: Chen Wang <[email protected]> Co-authored-by: Luigi Marini <[email protected]>
1 parent 8a358ac commit e594eda

File tree

4 files changed

+55
-11
lines changed

4 files changed

+55
-11
lines changed

frontend/src/components/datasets/Dataset.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Layout from "../Layout";
2424
import {ActionsMenu} from "./ActionsMenu";
2525
import {DatasetDetails} from "./DatasetDetails";
2626
import {FormatListBulleted, InsertDriveFile} from "@material-ui/icons";
27+
import {MainBreadcrumbs} from "../navigation/BreadCrumb";
2728

2829
const tab = {
2930
fontStyle: "normal",
@@ -57,7 +58,6 @@ export const Dataset = (): JSX.Element => {
5758
// mapStateToProps
5859
const reason = useSelector((state: RootState) => state.error.reason);
5960
const stack = useSelector((state: RootState) => state.error.stack);
60-
const folderPath = useSelector((state: RootState) => state.folder.folderPath);
6161
const about = useSelector((state: RootState) => state.dataset.about);
6262

6363
// state
@@ -134,12 +134,41 @@ export const Dataset = (): JSX.Element => {
134134
setEnableAddMetadata(false);
135135
};
136136

137+
// for breadcrumb
138+
const paths = [
139+
{
140+
"name": "Explore",
141+
"url": "/",
142+
},
143+
{
144+
"name": about["name"],
145+
"url": `/datasets/${datasetId}`
146+
}
147+
];
148+
// add folder path to breadcrumbs
149+
const folderPath = useSelector((state: RootState) => state.folder.folderPath);
150+
if (folderPath != null) {
151+
for (const folderBread of folderPath) {
152+
paths.push({
153+
"name": folderBread["folder_name"],
154+
"url": `/datasets/${datasetId}?folder=${folderBread["folder_id"]}`
155+
})
156+
}
157+
} else {
158+
paths.slice(0, 1)
159+
}
160+
137161
return (
138162
<Layout>
139163
{/*Error Message dialogue*/}
140164
<ActionModal actionOpen={errorOpen} actionTitle="Something went wrong..." actionText={reason}
141165
actionBtnName="Report" handleActionBtnClick={handleErrorReport}
142166
handleActionCancel={handleErrorCancel}/>
167+
<Grid container>
168+
<Grid item xs={10} sx={{display: 'flex', alignItems: 'center'}}>
169+
<MainBreadcrumbs paths={paths}/>
170+
</Grid>
171+
</Grid>
143172
<Grid container>
144173
<Grid item xs={8} sx={{display: 'flex', alignItems: 'center'}}>
145174
<Typography variant="h3" paragraph>{about["name"]}</Typography>
@@ -157,7 +186,7 @@ export const Dataset = (): JSX.Element => {
157186
label="Metadata" {...a11yProps(1)} disabled={false}/>
158187
</Tabs>
159188
<TabPanel value={selectedTabIndex} index={0}>
160-
<FilesTable datasetId={datasetId}/>
189+
<FilesTable datasetId={datasetId} folderId={folderId}/>
161190
</TabPanel>
162191
<TabPanel value={selectedTabIndex} index={1}>
163192
{

frontend/src/components/files/File.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import config from "../../app.config";
33
import {Button, Grid, Tab, Tabs, Typography} from "@mui/material";
44
import {downloadResource, parseDate} from "../../utils/common";
55
import {PreviewConfiguration, RootState} from "../../types/data";
6-
import {useLocation, useParams} from "react-router-dom";
6+
import {useParams, useSearchParams} from "react-router-dom";
77
import {useDispatch, useSelector} from "react-redux";
88
import {resetFailedReason} from "../../actions/common"
99

@@ -24,15 +24,19 @@ import Layout from "../Layout";
2424
import {fetchDatasetAbout} from "../../actions/dataset";
2525
import {Download} from "@mui/icons-material";
2626
import {FileDetails} from "./FileDetails";
27+
import {fetchFolderPath} from "../../actions/folder";
28+
2729

2830
export const File = (): JSX.Element => {
2931

3032
// path parameter
3133
const {fileId} = useParams<{ fileId?: string }>();
3234

33-
// query parameter get dataset id
34-
const search = useLocation().search;
35-
const datasetId = new URLSearchParams(search).get("dataset");
35+
// search parameters
36+
let [searchParams] = useSearchParams();
37+
const folderId = searchParams.get("folder");
38+
const datasetId = searchParams.get("dataset");
39+
3640
const listDatasetAbout = (datasetId: string | undefined) => dispatch(fetchDatasetAbout(datasetId));
3741
const about = useSelector((state: RootState) => state.dataset.about);
3842

@@ -45,6 +49,7 @@ export const File = (): JSX.Element => {
4549
const updateFileMetadata = (fileId: string | undefined, metadata: object) => dispatch(patchFileMetadataAction(fileId, metadata));
4650
const deleteFileMetadata = (fileId: string | undefined, metadata: object) => dispatch(deleteFileMetadataAction(fileId, metadata));
4751
const downloadFile = (fileId: string | undefined, filename: string | undefined) => dispatch(fileDownloaded(fileId, filename))
52+
const getFolderPath = (folderId: string | null) => dispatch(fetchFolderPath(folderId));
4853

4954
const fileSummary = useSelector((state: RootState) => state.file.fileSummary);
5055
const filePreviews = useSelector((state: RootState) => state.file.previews);
@@ -62,7 +67,13 @@ export const File = (): JSX.Element => {
6267
// load file information
6368
listFileSummary(fileId);
6469
listFileVersions(fileId);
65-
listDatasetAbout(datasetId); // get dataset name
70+
// FIXME replace checks for null with logic to load this info from redux instead of the page parameters
71+
if (datasetId != "null" && datasetId != "undefined") {
72+
listDatasetAbout(datasetId); // get dataset name
73+
}
74+
if (folderId != "null" && folderId != "undefined") {
75+
getFolderPath(folderId); // get folder path
76+
}
6677
}, []);
6778

6879

@@ -165,7 +176,7 @@ export const File = (): JSX.Element => {
165176
];
166177

167178
// add folder path to breadcrumbs
168-
const folderPath = useSelector((state: RootState) => state.dataset.folderPath);
179+
const folderPath = useSelector((state: RootState) => state.folder.folderPath);
169180
if (folderPath != null) {
170181
for (const folderBread of folderPath) {
171182
paths.push({

frontend/src/components/files/FilesTable.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import FolderMenu from "./FolderMenu";
1717

1818
type FilesTableProps = {
1919
datasetId: string | undefined,
20+
folderId: string | null
2021
}
2122

2223
const iconStyle = {
@@ -30,9 +31,11 @@ export default function FilesTable(props: FilesTableProps) {
3031
const foldersInDataset = useSelector((state: RootState) => state.folder.folders);
3132
// use history hook to redirect/navigate between routes
3233
const history = useNavigate();
34+
// get existing folder
35+
const parentFolderId = props.folderId;
3336
const selectFile = (selectedFileId: string | undefined) => {
34-
// Redirect to file route with file Id and dataset id
35-
history(`/files/${selectedFileId}?dataset=${props.datasetId}`);
37+
// Redirect to file route with file Id and dataset id and folderId
38+
history(`/files/${selectedFileId}?dataset=${props.datasetId}&folder=${parentFolderId}`);
3639
};
3740
const selectFolder = (selectedFolderId: string | undefined) => {
3841
// Redirect to file route with file Id and dataset id

frontend/src/components/files/UploadFile.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const UploadFile:React.FC<UploadFileProps> = (props: UploadFileProps) =>
2626
const createFileMetadata = (fileId: string|undefined, metadata:MetadataIn) => dispatch(postFileMetadata(fileId, metadata));
2727
const uploadFile = (selectedDatasetId: string|undefined, selectedFolderId: string|undefined, formData: FormData) => dispatch(fileCreated(selectedDatasetId, selectedFolderId, formData));
2828
const newFile = useSelector((state:RootState) => state.dataset.newFile);
29+
const folderPath = useSelector((state: RootState) => state.folder.folderPath);
2930

3031
useEffect(() => {
3132
getMetadatDefinitions(null, 0, 100);
@@ -83,7 +84,7 @@ export const UploadFile:React.FC<UploadFileProps> = (props: UploadFileProps) =>
8384
setFileRequestForm({});
8485

8586
// Redirect to file route with file Id and dataset id
86-
history(`/files/${file.id}?dataset=${selectedDatasetId}&name=${selectedDatasetName}`);
87+
history(`/files/${file.id}?dataset=${selectedDatasetId}&folder=${folderId}`);
8788
}
8889

8990
},[newFile]);

0 commit comments

Comments
 (0)