Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Austenem/CAT-929 double dialog bug #3553

Merged
merged 8 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG-double-dialog-bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fix "Add to workspace" bug on dataset detail pages.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ function HelperPanelActions() {
</SecondaryBackgroundTooltip>
}
datasetDetails={{ hubmap_id, uuid, status }}
dialogType="ADD_DATASETS_FROM_HELPER_PANEL"
/>
<SecondaryBackgroundTooltip title="Scroll down to the Bulk Data Transfer Section.">
<HelperPanelButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@ import MenuItem from '@mui/material/MenuItem';
import ListItemIcon from '@mui/material/ListItemIcon';
import AddRounded from '@mui/icons-material/AddRounded';

import SelectableTableProvider from 'js/shared-styles/tables/SelectableTableProvider';
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 { useTrackEntityPageEvent } from 'js/components/detailPage/useTrackEntityPageEvent';
import NewWorkspaceDialog from 'js/components/workspaces/NewWorkspaceDialog/NewWorkspaceDialog';
import AddDatasetsFromSearchDialog from 'js/components/workspaces/AddDatasetsFromSearchDialog/AddDatasetsFromSearchDialog';
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 };
dialogType: DialogType;
}

function ProcessedDataWorkspaceMenu({
button,
datasetDetails: { hubmap_id, uuid, status },
dialogType,
}: ProcessedDataWorkspaceMenuProps) {
const {
entity: { mapped_data_access_level },
Expand Down Expand Up @@ -56,7 +58,7 @@ function ProcessedDataWorkspaceMenu({
initialSelectedDatasets: [uuid].filter(Boolean),
});

const openEditWorkspaceDialog = useOpenDialog('ADD_DATASETS_FROM_SEARCH');
const openEditWorkspaceDialog = useOpenDialog(dialogType);

const createWorkspace = useEventCallback(() => {
track({
Expand Down Expand Up @@ -105,29 +107,27 @@ function ProcessedDataWorkspaceMenu({

// The selectable table provider is used here since a lot of the workspace logic relies on the selected rows
return (
<SelectableTableProvider tableLabel="Current Dataset" selectedRows={new Set([uuid])}>
<>
{buttonWithClickHandler}
<>
<Menu
open={open}
onClose={handleClose}
anchorEl={anchorEl}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right',
}}
>
{options.map(({ children, onClick, icon }) => (
<MenuItem key={children} onClick={onClick}>
<ListItemIcon>{icon}</ListItemIcon>
{children}
</MenuItem>
))}
</Menu>
<NewWorkspaceDialog dialogIsOpen={createWorkspaceIsOpen} control={control} errors={errors} {...rest} />
<AddDatasetsFromSearchDialog />
</>
</SelectableTableProvider>
<Menu
open={open}
onClose={handleClose}
anchorEl={anchorEl}
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right',
}}
>
{options.map(({ children, onClick, icon }) => (
<MenuItem key={children} onClick={onClick}>
<ListItemIcon>{icon}</ListItemIcon>
{children}
</MenuItem>
))}
</Menu>
<AddDatasetsFromDetailDialog uuid={uuid} dialogType={dialogType} />
<NewWorkspaceDialog dialogIsOpen={createWorkspaceIsOpen} control={control} errors={errors} {...rest} />
</>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ function EntityHeaderActionButtons({
/>
}
datasetDetails={{ hubmap_id, uuid, status }}
dialogType="ADD_DATASETS_FROM_HEADER"
/>
</Stack>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from 'react';

import SelectableTableProvider from 'js/shared-styles/tables/SelectableTableProvider';
import AddDatasetsFromSearchDialog from 'js/components/workspaces/AddDatasetsFromSearchDialog';
import { DialogType, useEditWorkspaceStore } from 'js/stores/useWorkspaceModalStore';

interface AddDatasetsFromDetailDialogProps {
uuid: string;
dialogType: DialogType;
}

function AddDatasetsFromDetailDialog({ uuid, dialogType }: AddDatasetsFromDetailDialogProps) {
const { dialogType: currentDialogType } = useEditWorkspaceStore();

if (currentDialogType !== dialogType) {
return null;
}

return (
// We're populating the table provider with the dataset from the detail page so as not to duplicate logic from the search dialog
<SelectableTableProvider tableLabel="Add Datasets From Detail Dialog" selectedRows={new Set([uuid])}>
<AddDatasetsFromSearchDialog />
</SelectableTableProvider>
);
}

export default AddDatasetsFromDetailDialog;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AddDatasetsFromDetailDialog from './AddDatasetsFromDetailDialog';

export default AddDatasetsFromDetailDialog;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { useAppContext } from 'js/components/Contexts';
import { NewWorkspaceDialogFromSelections } from 'js/components/workspaces/NewWorkspaceDialog';
import { StyledDropdownMenuButton } from 'js/components/searchPage/MetadataMenu/style';
import { DialogType, useEditWorkspaceStore } from 'js/stores/useWorkspaceModalStore';
import WorkspacesIcon from 'assets/svg/workspaces.svg';
import { AddIcon } from 'js/shared-styles/icons';
import AddDatasetsFromSearchDialog from '../AddDatasetsFromSearchDialog';
import AddDatasetsFromSearchDialog from 'js/components/workspaces/AddDatasetsFromSearchDialog';
import WorkspacesIcon from 'assets/svg/workspaces.svg';

const menuID = 'workspace-menu';

Expand All @@ -28,15 +28,14 @@ function WorkspaceSearchDialogs() {
}
}

type DialogTypes = Extract<DialogType, typeof addDatasetsDialogType>;

interface WorkspaceDropdownMenuItemProps extends PropsWithChildren {
dialogType: DialogTypes;
dialogType: DialogType;
icon: typeof SvgIcon;
}

export function useOpenDialog(dialogType: DialogTypes) {
export function useOpenDialog(dialogType: DialogType) {
const { open, setDialogType } = useEditWorkspaceStore();

const onClick = useCallback(() => {
setDialogType(dialogType);
open();
Expand All @@ -56,7 +55,7 @@ function WorkspaceDropdownMenuItem({ dialogType, children, icon: Icon }: Workspa

const menuItems: {
label: string;
dialogType: DialogTypes;
dialogType: DialogType;
icon: typeof SvgIcon;
}[] = [{ label: 'Add to Existing Workspace', dialogType: addDatasetsDialogType, icon: AddIcon }];

Expand Down
16 changes: 8 additions & 8 deletions context/app/static/js/pages/Dataset/Dataset.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import Box from '@mui/material/Box';
import Paper from '@mui/material/Paper';
import { InternalLink } from 'js/shared-styles/Links';
import Stack from '@mui/material/Stack';

import ProvSection from 'js/components/detailPage/provenance/ProvSection';
import Summary from 'js/components/detailPage/summary/Summary';
import Attribution from 'js/components/detailPage/Attribution';
Expand All @@ -13,11 +14,6 @@ import { DetailPageAlert } from 'js/components/detailPage/style';
import BulkDataTransfer from 'js/components/detailPage/BulkDataTransfer';
import { DetailContextProvider } from 'js/components/detailPage/DetailContext';
import { getCombinedDatasetStatus } from 'js/components/detailPage/utils';

import { useDatasetsCollections } from 'js/hooks/useDatasetsCollections';
import useTrackID from 'js/hooks/useTrackID';
import { useTrackEntityPageEvent } from 'js/components/detailPage/useTrackEntityPageEvent';

import ComponentAlert from 'js/components/detailPage/multi-assay/ComponentAlert';
import MultiAssayRelationship from 'js/components/detailPage/multi-assay/MultiAssayRelationship';
import MetadataSection from 'js/components/detailPage/MetadataSection';
Expand All @@ -26,9 +22,13 @@ import DatasetRelationships from 'js/components/detailPage/DatasetRelationships'
import ProcessedDataSection from 'js/components/detailPage/ProcessedData';
import { SelectedVersionStoreProvider } from 'js/components/detailPage/VersionSelect/SelectedVersionStore';
import SupportAlert from 'js/components/detailPage/SupportAlert';
import OrganIcon from 'js/shared-styles/icons/OrganIcon';
import Stack from '@mui/material/Stack';
import { useTrackEntityPageEvent } from 'js/components/detailPage/useTrackEntityPageEvent';
import { useDatasetRelationships } from 'js/components/detailPage/DatasetRelationships/hooks';
import { useDatasetsCollections } from 'js/hooks/useDatasetsCollections';
import useTrackID from 'js/hooks/useTrackID';
import { InternalLink } from 'js/shared-styles/Links';
import OrganIcon from 'js/shared-styles/icons/OrganIcon';

import { useProcessedDatasets, useProcessedDatasetsSections, useRedirectAlert } from './hooks';

interface SummaryDataChildrenProps {
Expand Down
2 changes: 2 additions & 0 deletions context/app/static/js/stores/useWorkspaceModalStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type DialogType =
| 'UPDATE_NAME'
| 'ADD_DATASETS'
| 'ADD_DATASETS_FROM_SEARCH'
| 'ADD_DATASETS_FROM_HEADER'
| 'ADD_DATASETS_FROM_HELPER_PANEL'
| 'LAUNCH_NEW_WORKSPACE'
| null;

Expand Down
Loading