diff --git a/src/js/components/Scope/DatasetScopePicker.tsx b/src/js/components/Scope/DatasetScopePicker.tsx index 06a3f5ea..0416c7ba 100644 --- a/src/js/components/Scope/DatasetScopePicker.tsx +++ b/src/js/components/Scope/DatasetScopePicker.tsx @@ -1,10 +1,14 @@ -import React from 'react'; +import React, { useMemo } from 'react'; import { List, Avatar, Space, Typography } from 'antd'; import { useAppSelector, useTranslationCustom, useTranslationDefault } from '@/hooks'; import { Link, useLocation } from 'react-router-dom'; import { FaDatabase } from 'react-icons/fa'; import { getCurrentPage } from '@/utils/router'; -import type { Project } from '@/types/metadata'; +import type { Dataset, Project } from '@/types/metadata'; + +const datasetIconColor = (dataset: Dataset, selectedID: string) => { + return dataset.identifier === selectedID ? '#33ffaa' : 'grey'; +}; type DatasetScopePickerProps = { parentProject: Project; @@ -18,16 +22,29 @@ const DatasetScopePicker = ({ parentProject, isSingleProject }: DatasetScopePick const page = getCurrentPage(); const selectedScope = useAppSelector((state) => state.metadata.selectedScope); + const showClearDataset = useMemo(() => { + // only show the clear dataset option if the selected dataset belongs to the parentProject + return selectedScope.dataset && parentProject.datasets.some((d) => d.identifier == selectedScope.dataset); + }, [selectedScope, parentProject]); + return ( {td('Project')}: {t(parentProject.title)} - {!isSingleProject && ( - - {td('Select')} + {isSingleProject && selectedScope.project ? ( + // project scope clearing when projects tab is hidden + + {td('Clear project selection')} + ) : ( + // project selection if not selected already + parentProject.identifier != selectedScope?.project && ( + + {td('Select')} + + ) )} {t(parentProject.description)} @@ -35,9 +52,9 @@ const DatasetScopePicker = ({ parentProject, isSingleProject }: DatasetScopePick {td('Datasets')} - {selectedScope?.dataset && ( - - {td('Clear selection')} + {showClearDataset && ( + + {td('Clear dataset selection')} )} @@ -48,7 +65,12 @@ const DatasetScopePicker = ({ parentProject, isSingleProject }: DatasetScopePick } />} + avatar={ + } + /> + } title={ {t(item.title)}