Skip to content

Commit

Permalink
[FIX] show meta analyses after creation (#691)
Browse files Browse the repository at this point in the history
* show empty list when no ids

* work with and update meta_analyses
  • Loading branch information
jdkent authored Feb 1, 2024
1 parent f32793d commit 4664d31
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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}`);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ProjectStoreMetadata>) => void;
clearProjectStore: () => void;
initCuration: (cols: string[], isPrisma: boolean) => void;
Expand Down Expand Up @@ -198,6 +199,12 @@ const useProjectStore = create<TProjectStore>()((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;
Expand Down Expand Up @@ -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 = () =>
Expand Down

0 comments on commit 4664d31

Please sign in to comment.