diff --git a/backend/app/routers/datasets.py b/backend/app/routers/datasets.py index 7b14411a9..cf149b154 100644 --- a/backend/app/routers/datasets.py +++ b/backend/app/routers/datasets.py @@ -219,7 +219,7 @@ async def get_datasets( admin=Depends(get_admin), admin_mode: bool = Depends(get_admin_mode), ): - if admin and admin_mode: + if admin and admin_mode and not mine: datasets_and_count = await DatasetDBViewList.aggregate( [_get_page_query(skip, limit, sort_field="created", ascending=False)], ).to_list() diff --git a/frontend/src/actions/dataset.js b/frontend/src/actions/dataset.js index 7a1242857..541da8b8b 100644 --- a/frontend/src/actions/dataset.js +++ b/frontend/src/actions/dataset.js @@ -261,6 +261,25 @@ export function fetchDatasets(skip = 0, limit = 21, mine = false) { }; } +export const RECEIVE_MY_DATASETS = "RECEIVE_MY_DATASETS"; + +export function fetchMyDatasets(skip = 0, limit = 21, mine = true) { + return (dispatch) => { + // TODO: Parameters for dates? paging? + return V2.DatasetsService.getDatasetsApiV2DatasetsGet(skip, limit, mine) + .then((json) => { + dispatch({ + type: RECEIVE_MY_DATASETS, + datasets: json, + receivedAt: Date.now(), + }); + }) + .catch((reason) => { + dispatch(handleErrors(reason, fetchMyDatasets(skip, limit, mine))); + }); + }; +} + export const CREATE_DATASET = "CREATE_DATASET"; export function datasetCreated(formData, licenseId, licenseFormData) { diff --git a/frontend/src/components/Explore.tsx b/frontend/src/components/Explore.tsx index 5946d5eba..eebc9c104 100644 --- a/frontend/src/components/Explore.tsx +++ b/frontend/src/components/Explore.tsx @@ -43,20 +43,30 @@ export const Explore = (): JSX.Element => { const [currPageNum, setCurrPageNum] = useState(1); const [limit] = useState(config.defaultDatasetPerPage); // TODO add switch to turn on and off "mine" dataset - const [mine] = useState(false); + const [mine, setMine] = useState(false); const [selectedTabIndex, setSelectedTabIndex] = useState(0); const [errorOpen, setErrorOpen] = useState(false); // Admin mode will fetch all datasets useEffect(() => { - listDatasets((currPageNum - 1) * limit, limit, mine); - }, [adminMode, deletedDataset]); + if (adminMode) listDatasets(0, limit, true); + else listDatasets((currPageNum - 1) * limit, limit, mine); + }, [adminMode, deletedDataset, mine, currPageNum, limit]); // switch tabs const handleTabChange = ( _event: React.ChangeEvent<{}>, newTabIndex: number ) => { + if (newTabIndex === 1) { + setMine(true); + setCurrPageNum(1); + listDatasets(0, limit, true); + } else { + setMine(false); + setCurrPageNum(1); + listDatasets(0, limit, false); + } setSelectedTabIndex(newTabIndex); }; @@ -80,6 +90,7 @@ export const Explore = (): JSX.Element => { aria-label="dashboard tabs" > + @@ -137,6 +148,61 @@ export const Explore = (): JSX.Element => { <> )} + + + {datasets !== undefined ? ( + datasets.map((dataset: DatasetOut) => { + return ( + + + + ); + }) + ) : ( + <> + )} + {datasets.length === 0 ? ( + + +

+ Nobody has created any datasets on this instance. Click + below to create a dataset! +

+ +
+
+ ) : ( + <> + )} +
+ {datasets.length !== 0 ? ( + + + + ) : ( + <> + )} +
diff --git a/frontend/src/reducers/dataset.ts b/frontend/src/reducers/dataset.ts index d714dde94..fa9a0b3d7 100644 --- a/frontend/src/reducers/dataset.ts +++ b/frontend/src/reducers/dataset.ts @@ -8,6 +8,7 @@ import { RECEIVE_DATASET_ROLES, RECEIVE_DATASETS, RECEIVE_FOLDERS_FILES_IN_DATASET, + RECEIVE_MY_DATASETS, REMOVE_DATASET_GROUP_ROLE, REMOVE_DATASET_USER_ROLE, RESET_CREATE_DATASET, @@ -51,6 +52,7 @@ const defaultState: DatasetState = { about: { creator: {} }, datasetRole: {}, datasets: { metadata: {}, data: [] }, + myDatasets: { metadata: {}, data: [] }, newDataset: {}, newFile: {}, newFiles: [], @@ -112,6 +114,8 @@ const dataset = (state = defaultState, action: DataAction) => { return Object.assign({}, state, { about: action.about }); case RECEIVE_DATASETS: return Object.assign({}, state, { datasets: action.datasets }); + case RECEIVE_MY_DATASETS: + return Object.assign({}, state, { myDatasets: action.myDatasets }); case CREATE_DATASET: return Object.assign({}, state, { newDataset: action.dataset }); case RESET_CREATE_DATASET: diff --git a/frontend/src/types/action.ts b/frontend/src/types/action.ts index aca31c12b..dbbfce979 100644 --- a/frontend/src/types/action.ts +++ b/frontend/src/types/action.ts @@ -88,6 +88,11 @@ interface RECEIVE_DATASETS { datasets: Paged; } +interface RECEIVE_MY_DATASETS { + type: "RECEIVE_MY_DATASETS"; + myDatasets: Paged; +} + interface RECEIVE_PUBLIC_DATASETS { type: "RECEIVE_PUBLIC_DATASETS"; publicDatasets: Dataset[]; @@ -661,6 +666,7 @@ export type DataAction = | RECEIVE_DATASET_ABOUT | RECEIVE_DATASET_ROLE | RECEIVE_DATASETS + | RECEIVE_MY_DATASETS | RECEIVE_PUBLIC_DATASETS | RECEIVE_PUBLIC_DATASET_ABOUT | RECEIVE_FILES_IN_PUBLIC_DATASET diff --git a/frontend/src/types/data.ts b/frontend/src/types/data.ts index 0df67cabf..ddb897931 100644 --- a/frontend/src/types/data.ts +++ b/frontend/src/types/data.ts @@ -123,6 +123,7 @@ export interface DatasetState { files: Paged; folders: Paged; datasets: Paged; + myDatasets: Paged; deletedDataset: DatasetOut; deletedFolder: FolderOut; deletedFile: FileOut;