From 579010bafc8fcf00772c17e6a24925058bb8a458 Mon Sep 17 00:00:00 2001 From: Nicholas Lee Date: Sun, 29 Oct 2023 18:16:20 -0400 Subject: [PATCH] feat: added swap study button feature --- .../ConfirmationDialog/ConfirmationDialog.tsx | 19 +- .../MoveToExtractionIngest/helpers/utils.ts | 55 +++--- .../EditStudyDetails/EditStudyDetails.tsx | 7 +- .../EditStudySaveButton.tsx | 10 +- .../EditStudySwapVersionButton.tsx | 186 +++++++++++++++--- .../src/hooks/studies/useGetBaseStudyById.tsx | 1 + .../hooks/studysets/useGetStudysetById.tsx | 3 +- .../src/hooks/studysets/useGetStudysets.tsx | 4 +- .../src/neurostore-typescript-sdk | 2 +- .../CurationPage/ProjectIsLoadingText.tsx | 6 +- .../pages/ExtractionPage/ExtractionPage.tsx | 3 +- .../src/pages/Studies/StudyStore.ts | 3 + .../src/pages/helpers/utils.ts | 9 +- compose/neurosynth_compose/openapi | 2 +- store/neurostore/openapi | 2 +- 15 files changed, 233 insertions(+), 79 deletions(-) diff --git a/compose/neurosynth-frontend/src/components/Dialogs/ConfirmationDialog/ConfirmationDialog.tsx b/compose/neurosynth-frontend/src/components/Dialogs/ConfirmationDialog/ConfirmationDialog.tsx index 1d4534e9f..e72ac7c93 100644 --- a/compose/neurosynth-frontend/src/components/Dialogs/ConfirmationDialog/ConfirmationDialog.tsx +++ b/compose/neurosynth-frontend/src/components/Dialogs/ConfirmationDialog/ConfirmationDialog.tsx @@ -9,18 +9,29 @@ import { IconButton, } from '@mui/material'; import CloseIcon from '@mui/icons-material/Close'; +import React, { useMemo } from 'react'; export interface IConfirmationDialog { isOpen: boolean; onCloseDialog: (confirm: boolean | undefined, data?: any) => void; dialogTitle: string; - dialogMessage?: string; + dialogMessage?: JSX.Element | string; confirmText?: string; rejectText?: string; data?: any; } const ConfirmationDialog: React.FC = (props) => { + const dialogContent = useMemo(() => { + if (!props.dialogMessage) return undefined; + + if (typeof props.dialogMessage === 'string') { + return {props.dialogMessage}; + } else { + return props.dialogMessage; + } + }, [props.dialogMessage]); + return ( props.onCloseDialog(undefined, props.data)}> @@ -34,11 +45,7 @@ const ConfirmationDialog: React.FC = (props) => { - {props.dialogMessage && ( - - {props.dialogMessage} - - )} + {props.dialogMessage && dialogContent} + text="Switch study version" + > + + + You are switching from version {studyId} to version + {confirmationDialogState.selectedVersion || ''} + + + Warning: switching versions will remove any annotations you have created + for this study. + + + } + onCloseDialog={handleCloseConfirmationDialog} + isOpen={confirmationDialogState.isOpen} + rejectText="Cancel" + /> { anchorOrigin={{ vertical: 'top', horizontal: 'left' }} transformOrigin={{ vertical: 'bottom', horizontal: 'left' }} > - - - - - - - - - - - - - - - - - - + {baseStudyVersions.map((baseStudyVersion) => ( + + + + + + + ))} ); diff --git a/compose/neurosynth-frontend/src/hooks/studies/useGetBaseStudyById.tsx b/compose/neurosynth-frontend/src/hooks/studies/useGetBaseStudyById.tsx index f32b5ee6a..9cea8d9fd 100644 --- a/compose/neurosynth-frontend/src/hooks/studies/useGetBaseStudyById.tsx +++ b/compose/neurosynth-frontend/src/hooks/studies/useGetBaseStudyById.tsx @@ -9,6 +9,7 @@ const useGetBaseStudyById = (baseStudyId: string) => { select: (res) => { return res.data; }, + enabled: !!baseStudyId, } ); }; diff --git a/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysetById.tsx b/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysetById.tsx index 820dc9c4f..c28a9fc83 100644 --- a/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysetById.tsx +++ b/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysetById.tsx @@ -3,6 +3,7 @@ import { StudysetReturn } from 'neurostore-typescript-sdk'; import { useSnackbar } from 'notistack'; import { useQuery } from 'react-query'; import API from 'utils/api'; +import { STUDYSET_QUERY_STRING } from './useGetStudysets'; const useGetStudysetById = (studysetId?: string, nested?: boolean) => { const { enqueueSnackbar } = useSnackbar(); @@ -12,7 +13,7 @@ const useGetStudysetById = (studysetId?: string, nested?: boolean) => { StudysetReturn, [string, string | undefined, boolean | undefined] >( - ['studysets', studysetId, nested], + [STUDYSET_QUERY_STRING, studysetId, nested], () => API.NeurostoreServices.StudySetsService.studysetsIdGet(studysetId || '', nested), { enabled: !!studysetId, diff --git a/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysets.tsx b/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysets.tsx index a4f5ba75c..fa3b00cfa 100644 --- a/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysets.tsx +++ b/compose/neurosynth-frontend/src/hooks/studysets/useGetStudysets.tsx @@ -2,12 +2,14 @@ import { Source, SearchCriteria } from 'pages/Studies/StudiesPage/models'; import { useQuery } from 'react-query'; import API from 'utils/api'; +export const STUDYSET_QUERY_STRING = 'studysets'; + const useGetStudysets = ( searchCriteria: Partial>, enabled?: boolean ) => { return useQuery( - ['studysets', { ...searchCriteria }], + [STUDYSET_QUERY_STRING, { ...searchCriteria }], () => { return API.NeurostoreServices.StudySetsService.studysetsGet( undefined, diff --git a/compose/neurosynth-frontend/src/neurostore-typescript-sdk b/compose/neurosynth-frontend/src/neurostore-typescript-sdk index 6d0811b64..56f3b4e64 160000 --- a/compose/neurosynth-frontend/src/neurostore-typescript-sdk +++ b/compose/neurosynth-frontend/src/neurostore-typescript-sdk @@ -1 +1 @@ -Subproject commit 6d0811b647bfcb9f4f1a932b37e17adca8c4e99c +Subproject commit 56f3b4e641f4e7f6acea04aa649ac472f1b3f395 diff --git a/compose/neurosynth-frontend/src/pages/CurationPage/ProjectIsLoadingText.tsx b/compose/neurosynth-frontend/src/pages/CurationPage/ProjectIsLoadingText.tsx index e1db0f84a..37438b814 100644 --- a/compose/neurosynth-frontend/src/pages/CurationPage/ProjectIsLoadingText.tsx +++ b/compose/neurosynth-frontend/src/pages/CurationPage/ProjectIsLoadingText.tsx @@ -1,16 +1,18 @@ import { Box, Typography } from '@mui/material'; import { useUpdateProjectIsLoading } from 'pages/Projects/ProjectPage/ProjectStore'; -const ProjectIsLoadingText: React.FC = (props) => { +const ProjectIsLoadingText: React.FC<{ isLoading?: boolean }> = (props) => { const updateProjectIsLoading = useUpdateProjectIsLoading(); + const isLoading = updateProjectIsLoading || props.isLoading; + return ( updating... diff --git a/compose/neurosynth-frontend/src/pages/ExtractionPage/ExtractionPage.tsx b/compose/neurosynth-frontend/src/pages/ExtractionPage/ExtractionPage.tsx index 89dcc051c..13d87922f 100644 --- a/compose/neurosynth-frontend/src/pages/ExtractionPage/ExtractionPage.tsx +++ b/compose/neurosynth-frontend/src/pages/ExtractionPage/ExtractionPage.tsx @@ -63,6 +63,7 @@ const ExtractionPage: React.FC = (props) => { const { data: studyset, isLoading: getStudysetIsLoading, + isRefetching: getStudysetIsRefetching, isError: getStudysetIsError, } = useGetStudysetById(studysetId, true); const { mutate } = useUpdateStudyset(); @@ -200,7 +201,7 @@ const ExtractionPage: React.FC = (props) => { }, ]} /> - +