From 4664d31b4ba257f503d9cb1dc628d4c9a3368788 Mon Sep 17 00:00:00 2001 From: James Kent Date: Thu, 1 Feb 2024 15:34:05 -0600 Subject: [PATCH] [FIX] show meta analyses after creation (#691) * show empty list when no ids * work with and update meta_analyses --- .../CreateMetaAnalysisSpecificationReview.tsx | 14 ++++++++++++++ .../src/pages/Projects/ProjectPage/ProjectStore.ts | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/compose/neurosynth-frontend/src/components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationReview/CreateMetaAnalysisSpecificationReview.tsx b/compose/neurosynth-frontend/src/components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationReview/CreateMetaAnalysisSpecificationReview.tsx index 63ad1de5e..e610442a3 100644 --- a/compose/neurosynth-frontend/src/components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationReview/CreateMetaAnalysisSpecificationReview.tsx +++ b/compose/neurosynth-frontend/src/components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationReview/CreateMetaAnalysisSpecificationReview.tsx @@ -14,6 +14,8 @@ import { useProjectExtractionAnnotationId, useProjectExtractionStudysetId, useProjectId, + useProjectMetaAnalyses, + useUpdateProjectMetaAnalyses, } from 'pages/Projects/ProjectPage/ProjectStore'; import { useMemo } from 'react'; import { useHistory } from 'react-router-dom'; @@ -43,6 +45,9 @@ const CreateMetaAnalysisSpecificationReview: React.FC<{ const { data: annotations } = useGetAnnotationById(annotationId); const { createMetaAnalysis, isLoading, isError } = useCreateAlgorithmSpecification(); const { enqueueSnackbar } = useSnackbar(); + const projectMetaAnalyses = useProjectMetaAnalyses() || []; + const updateProjectMetaAnalyses = useUpdateProjectMetaAnalyses(); + // TODO: implement studyset snapshot // const [showAdvanced, setShowAdvanced] = useState(false); @@ -74,9 +79,18 @@ const CreateMetaAnalysisSpecificationReview: React.FC<{ if (!metaAnalysis.data.specification || !metaAnalysis.data.id) throw new Error('no specification ID found when creating a meta-analysis'); + // Ensure that metaAnalysis.data.id is a string + if (typeof metaAnalysis.data.id !== 'string') { + throw new Error('metaAnalysis.data.id must be a string'); + } + const updatedMetaAnalyses = [...projectMetaAnalyses, metaAnalysis.data.id] as string[]; + // Update the project meta analyses + updateProjectMetaAnalyses(updatedMetaAnalyses); + enqueueSnackbar('created meta analysis specification successfully', { variant: 'success', }); + history.push(`/projects/${projectId}/meta-analyses/${metaAnalysis.data.id}`); }; diff --git a/compose/neurosynth-frontend/src/pages/Projects/ProjectPage/ProjectStore.ts b/compose/neurosynth-frontend/src/pages/Projects/ProjectPage/ProjectStore.ts index a21f078c5..1241811c8 100644 --- a/compose/neurosynth-frontend/src/pages/Projects/ProjectPage/ProjectStore.ts +++ b/compose/neurosynth-frontend/src/pages/Projects/ProjectPage/ProjectStore.ts @@ -66,6 +66,7 @@ export type ProjectStoreActions = { updateProjectName: (name: string) => void; updateProjectDescription: (description: string) => void; initProjectStore: (project: INeurosynthProjectReturn | undefined) => void; + updateProjectMetaAnalyses: (meta_analyses: string[]) => void; updateProjectMetadata: (metadata: Partial) => void; clearProjectStore: () => void; initCuration: (cols: string[], isPrisma: boolean) => void; @@ -198,6 +199,12 @@ const useProjectStore = create()((set, get) => { created_at: res.data.created_at, })); }, + updateProjectMetaAnalyses: (meta_analyses: string[]) => { + set((state) => ({ + ...state, + meta_analyses: meta_analyses, + })); + }, updateProjectInDBDebounced: () => { const updateProject = get().metadata.updateProject; if (!updateProject) return; @@ -881,6 +888,8 @@ export const useProjectExtractionSetGivenStudyStatusesAsComplete = () => // metaAnalysisAlgorithm updater hooks export const useAllowEditMetaAnalyses = () => useProjectStore((state) => state.allowEditMetaAnalyses); +export const useUpdateProjectMetaAnalyses = () => + useProjectStore((state) => state.updateProjectMetaAnalyses); // metaAnalysisAlgorithm retrieval hooks export const useProjectMetaAnalysisCanEdit = () =>