Skip to content

Commit

Permalink
Austenem/CAT-899 Add access levels (#3574)
Browse files Browse the repository at this point in the history
* add access levels

* add changelog

* rely on processed dataset access level

* update readme
  • Loading branch information
austenem authored Oct 16, 2024
1 parent eec31fa commit 6d47a5e
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG-add-access-levels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add access levels to processed dataset helper panels.
- Use relevant access levels when determining whether or not to show workspace buttons on dataset detail pages.
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ import { SecondaryBackgroundTooltip } from 'js/shared-styles/tooltips';

import { formatDate } from 'date-fns/format';
import { HelperPanelPortal } from '../../DetailLayout/DetailLayout';
import useProcessedDataStore from '../store';
import StatusIcon from '../../StatusIcon';
import { getDateLabelAndValue } from '../../utils';
import { getDateLabelAndValue, useCurrentDataset } from '../../utils';
import { HelperPanelButton } from './styles';
import { useTrackEntityPageEvent } from '../../useTrackEntityPageEvent';
import ProcessedDataWorkspaceMenu from '../ProcessedDataWorkspaceMenu';

function useCurrentDataset() {
return useProcessedDataStore((state) => state.currentDataset);
}

function HelperPanelHeader() {
const currentDataset = useCurrentDataset();
if (!currentDataset) {
Expand All @@ -47,7 +42,7 @@ function HelperPanelStatus() {
return (
<Stack direction="row" alignItems="center">
<StatusIcon status={currentDataset.status} />
<Typography variant="body2">{currentDataset.status}</Typography>
<Typography variant="body2">{`${currentDataset.status} (${currentDataset.mapped_data_access_level})`}</Typography>
</Stack>
);
}
Expand Down Expand Up @@ -99,7 +94,7 @@ function HelperPanelActions() {
return null;
}

const { hubmap_id, uuid, status } = currentDataset;
const { hubmap_id, uuid, status, mapped_data_access_level } = currentDataset;

return (
<>
Expand All @@ -109,7 +104,7 @@ function HelperPanelActions() {
<HelperPanelButton startIcon={<WorkspacesIcon color="primary" />}>Workspace</HelperPanelButton>
</SecondaryBackgroundTooltip>
}
datasetDetails={{ hubmap_id, uuid, status }}
datasetDetails={{ hubmap_id, uuid, status, mapped_data_access_level }}
dialogType="ADD_DATASETS_FROM_HELPER_PANEL"
/>
<SecondaryBackgroundTooltip title="Scroll down to the Bulk Data Transfer Section.">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ import AddRounded from '@mui/icons-material/AddRounded';
import { WorkspacesIcon } from 'js/shared-styles/icons';
import { useOpenDialog } from 'js/components/workspaces/WorkspacesDropdownMenu/WorkspacesDropdownMenu';
import { useCreateWorkspaceForm } from 'js/components/workspaces/NewWorkspaceDialog/useCreateWorkspaceForm';
import { useAppContext, useFlaskDataContext } from 'js/components/Contexts';
import { useAppContext } from 'js/components/Contexts';
import { useTrackEntityPageEvent } from 'js/components/detailPage/useTrackEntityPageEvent';
import NewWorkspaceDialog from 'js/components/workspaces/NewWorkspaceDialog/NewWorkspaceDialog';
import { DialogType } from 'js/stores/useWorkspaceModalStore';
import AddDatasetsFromDetailDialog from 'js/components/workspaces/AddDatasetsFromDetailDialog';

interface ProcessedDataWorkspaceMenuProps {
button: React.ReactNode;
datasetDetails: { hubmap_id: string; uuid: string; status: string };
datasetDetails: { hubmap_id: string; uuid: string; status: string; mapped_data_access_level: string };
dialogType: DialogType;
}

function ProcessedDataWorkspaceMenu({
button,
datasetDetails: { hubmap_id, uuid, status },
datasetDetails: { hubmap_id, uuid, status, mapped_data_access_level },
dialogType,
}: ProcessedDataWorkspaceMenuProps) {
const {
entity: { mapped_data_access_level },
} = useFlaskDataContext();

const { isWorkspacesUser } = useAppContext();
const [anchorEl, setAnchorEl] = React.useState<null | HTMLElement>(null);
const open = Boolean(anchorEl);
Expand Down Expand Up @@ -86,9 +82,7 @@ function ProcessedDataWorkspaceMenu({
'aria-expanded': open ? 'true' : undefined,
});

const showWorkspaceButton = mapped_data_access_level && hubmap_id && isWorkspacesUser && status === 'Published';

if (!showWorkspaceButton) {
if (!isWorkspacesUser || !hubmap_id || mapped_data_access_level !== 'Public' || status !== 'Published') {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type ProcessedDatasetDetails = ProcessedDatasetInfo &
| 'protocol_url' // TODO: This is present for non-dataset entities, but not for datasets.
| 'dataset_type'
| 'mapped_consortium'
| 'mapped_data_access_level'
>;

export function useProcessedDatasetDetails(uuid: string) {
Expand Down Expand Up @@ -54,6 +55,7 @@ export function useProcessedDatasetDetails(uuid: string) {
'mapped_consortium',
'contributors',
'contacts',
'mapped_data_access_level',
],
size: 10000,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function EntityHeaderActionButtons({
disabled={disabled}
/>
}
datasetDetails={{ hubmap_id, uuid, status }}
datasetDetails={{ hubmap_id, uuid, status, mapped_data_access_level }}
dialogType="ADD_DATASETS_FROM_HEADER"
/>
</Stack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ function EntityHeaderContent({ view, setView }: { view: SummaryViewsType; setVie
<RightDiv>
{vizIsFullscreen ? (
<>
{vizNotebookId && <VisualizationWorkspaceButton uuid={vizNotebookId} />}
{vizNotebookId && <VisualizationWorkspaceButton />}
<VisualizationShareButtonWrapper />
<VizualizationThemeSwitch />
<VisualizationCollapseButton />
Expand Down
5 changes: 5 additions & 0 deletions context/app/static/js/components/detailPage/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Dataset, Donor, isDataset, isDonor, isSample, Sample } from 'js/components/types';
import useProcessedDataStore from 'js/components/detailPage/ProcessedData/store';
import { ProcessedDatasetDetails } from './ProcessedData/ProcessedDataset/hooks';

export function getSectionOrder(
Expand Down Expand Up @@ -48,3 +49,7 @@ export function getOriginSampleAndMappedOrgan(entity: Sample | Dataset) {
const origin_sample = entity.origin_samples[0];
return { origin_sample, mapped_organ: origin_sample.mapped_organ };
}

export function useCurrentDataset() {
return useProcessedDataStore((state) => state.currentDataset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ function Visualization({
leftText={shouldDisplayHeader ? <StyledSectionHeader>Visualization</StyledSectionHeader> : undefined}
buttons={
<Stack direction="row" spacing={1}>
{hasNotebook && <VisualizationWorkspaceButton uuid={uuid} />}
{hasNotebook && <VisualizationWorkspaceButton />}
<VisualizationDownloadButton uuid={uuid} hasNotebook={hasNotebook} parentUuid={parentUuid} />
<VisualizationShareButton />
<VisualizationThemeSwitch />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,21 @@ import NewWorkspaceDialog from 'js/components/workspaces/NewWorkspaceDialog';
import { useCreateWorkspaceForm } from 'js/components/workspaces/NewWorkspaceDialog/useCreateWorkspaceForm';
import { WhiteBackgroundIconTooltipButton } from 'js/shared-styles/buttons';
import { useAppContext } from 'js/components/Contexts';
import { useDetailContext } from 'js/components/detailPage/DetailContext';
import { useProcessedDatasetDetails } from 'js/components/detailPage/ProcessedData/ProcessedDataset/hooks';
import { useCurrentDataset } from 'js/components/detailPage/utils';

const tooltip = 'Launch New Workspace';

interface VisualizationWorkspaceButtonProps {
uuid?: string;
}

function VisualizationWorkspaceButton({ uuid = '' }: VisualizationWorkspaceButtonProps) {
const { mapped_data_access_level } = useDetailContext();
const {
datasetDetails: { hubmap_id },
} = useProcessedDatasetDetails(uuid);
function VisualizationWorkspaceButton() {
const currentDataset = useCurrentDataset();
const { isWorkspacesUser } = useAppContext();

const { setDialogIsOpen, removeDatasets, ...rest } = useCreateWorkspaceForm({
defaultName: hubmap_id,
defaultName: currentDataset?.hubmap_id,
defaultTemplate: 'visualization',
initialSelectedDatasets: [uuid],
initialSelectedDatasets: currentDataset ? [currentDataset.uuid] : [],
});

if (!isWorkspacesUser || !hubmap_id || mapped_data_access_level !== 'Public') {
if (!isWorkspacesUser || !currentDataset?.hubmap_id || currentDataset?.mapped_data_access_level !== 'Public') {
return null;
}

Expand Down

0 comments on commit 6d47a5e

Please sign in to comment.