Skip to content

Commit

Permalink
feat: added handling for string selection in specification and mkdachi2
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoalee committed Nov 10, 2023
1 parent 11c9eeb commit ea9e87a
Show file tree
Hide file tree
Showing 18 changed files with 638 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const CreateMetaAnalysisSpecificationDetailsStep: React.FC<{
sx={{ marginBottom: '1rem' }}
fullWidth
value={details.name}
label="name"
label="meta-analysis name"
name="name"
onChange={handleUpdateDetails}
/>
Expand All @@ -75,7 +75,7 @@ const CreateMetaAnalysisSpecificationDetailsStep: React.FC<{
sx={{ marginBottom: '1rem' }}
fullWidth
onChange={handleUpdateDetails}
label="description"
label="meta-analysis description"
name="description"
/>
<NavigationButtons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import CreateMetaAnalysisSpecificationReview from './CreateMetaAnalysisSpecifica
import { IAutocompleteObject } from 'components/NeurosynthAutocomplete/NeurosynthAutocomplete';
import CreateMetaAnalysisSpecificationDetailsStep from './CreateMetaAnalysisSpecificationDetailsStep/CreateMetaAnalysisSpecificationDetailsStep';
import { useProjectName } from 'pages/Projects/ProjectPage/ProjectStore';
import {
IAlgorithmSelection,
IAnalysesSelection,
} from './CreateMetaAnalysisSpecificationDialogBase.types';
import { AnnotationNoteValue } from 'components/HotTables/HotTables.types';

const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) => {
const projectName = useProjectName();
Expand All @@ -19,16 +24,8 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
name: `${projectName} Meta Analysis`,
description: `this is a meta-analysis for ${projectName}`,
});
const [selection, setSelection] = useState<{
selectionKey: string | undefined;
type: EPropertyType;
}>();
const [algorithm, setAlgorithm] = useState<{
estimator: IAutocompleteObject | null;
estimatorArgs: IDynamicValueType;
corrector: IAutocompleteObject | null;
correctorArgs: IDynamicValueType;
}>({
const [selection, setSelection] = useState<IAnalysesSelection>();
const [algorithm, setAlgorithm] = useState<IAlgorithmSelection>({
estimator: null,
estimatorArgs: {},
corrector: null,
Expand Down Expand Up @@ -72,10 +69,15 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
});
};

const handleChooseSelection = (selectionKey: string, type: EPropertyType) => {
const handleChooseSelection = (
selectionKey: string,
type: EPropertyType,
selectionValue?: AnnotationNoteValue
) => {
setSelection({
selectionKey,
type,
selectionValue: selectionValue ? selectionValue : undefined,
});
};

Expand All @@ -98,16 +100,17 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
dialogTitle="Create Meta-Analysis Specification"
isOpen={props.isOpen}
fullWidth
maxWidth="md"
dialogTitleSx={{ padding: '1rem 0rem 0rem 4rem' }}
maxWidth="lg"
onCloseDialog={handleCloseDialog}
>
<Box>
<Box sx={{ padding: '2rem' }}>
<Stepper activeStep={activeStep}>
<Step>
<StepLabel>Select Analyses</StepLabel>
<StepLabel>Enter Specification</StepLabel>
</Step>
<Step>
<StepLabel>Enter Specification</StepLabel>
<StepLabel>Select Analyses</StepLabel>
</Step>
<Step>
<StepLabel>Enter Details</StepLabel>
Expand All @@ -118,16 +121,17 @@ const CreateMetaAnalysisSpecificationDialogBase: React.FC<IDialog> = (props) =>
</Stepper>
<Box sx={{ marginTop: '1rem' }}>
{activeStep === 0 && (
<CreateMetaAnalysisSpecificationSelectionStep
onChooseSelection={handleChooseSelection}
selection={selection}
<CreateMetaAnalysisSpecificationAlgorithmStep
onChooseAlgorithm={handleChooseAlgorithm}
algorithm={algorithm}
onNavigate={handleNavigate}
/>
)}
{activeStep === 1 && (
<CreateMetaAnalysisSpecificationAlgorithmStep
onChooseAlgorithm={handleChooseAlgorithm}
<CreateMetaAnalysisSpecificationSelectionStep
onChooseSelection={handleChooseSelection}
algorithm={algorithm}
selection={selection}
onNavigate={handleNavigate}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { EPropertyType } from 'components/EditMetadata';
import { AnnotationNoteValue } from 'components/HotTables/HotTables.types';
import { IDynamicValueType } from 'components/MetaAnalysisConfigComponents';
import { IAutocompleteObject } from 'components/NeurosynthAutocomplete/NeurosynthAutocomplete';

export interface IAnalysesSelection {
selectionKey: string;
type: EPropertyType;
selectionValue?: AnnotationNoteValue;
}

export interface IAlgorithmSelection {
estimator: IAutocompleteObject | null;
estimatorArgs: IDynamicValueType;
corrector: IAutocompleteObject | null;
correctorArgs: IDynamicValueType;
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
import {
Box,
Button,
Divider,
FormControl,
InputLabel,
MenuItem,
Select,
Typography,
} from '@mui/material';
import { Box, Button } from '@mui/material';
import LoadingButton from 'components/Buttons/LoadingButton/LoadingButton';
import { ENavigationButton } from 'components/Buttons/NavigationButtons/NavigationButtons';
import { getFilteredAnnotationNotes } from 'components/Dialogs/CreateMetaAnalysisSpecificationDialog/CreateMetaAnalysisSpecificationSelectionStep/SelectAnalysesComponent/SelectAnalysesComponent';
import { EPropertyType } from 'components/EditMetadata';
import { IDynamicValueType } from 'components/MetaAnalysisConfigComponents';
import DynamicInputDisplay from 'components/MetaAnalysisConfigComponents/DynamicInputDisplay/DynamicInputDisplay';
import MetaAnalysisSummaryRow from 'components/MetaAnalysisConfigComponents/MetaAnalysisSummaryRow/MetaAnalysisSummaryRow';
Expand All @@ -26,18 +15,15 @@ import {
useProjectExtractionStudysetId,
useProjectId,
} from 'pages/Projects/ProjectPage/ProjectStore';
import { useState } from 'react';
import { useMemo } from 'react';
import { useHistory } from 'react-router-dom';
import { IAnalysesSelection } from '../CreateMetaAnalysisSpecificationDialogBase.types';
import { getFilteredAnnotationNotes } from '../CreateMetaAnalysisSpecificationSelectionStep/SelectAnalysesComponent/SelectAnalysesComponent.helpers';

const CreateMetaAnalysisSpecificationReview: React.FC<{
onNavigate: (button: ENavigationButton) => void;
onClose: () => void;
selection:
| {
selectionKey: string | undefined;
type: EPropertyType;
}
| undefined;
selection: IAnalysesSelection | undefined;
algorithm: {
estimator: IAutocompleteObject | null;
estimatorArgs: IDynamicValueType;
Expand All @@ -56,37 +42,57 @@ const CreateMetaAnalysisSpecificationReview: React.FC<{
const { data: annotations } = useGetAnnotationById(annotationId);
const { createMetaAnalysis, isLoading, isError } = useCreateAlgorithmSpecification();
const { enqueueSnackbar } = useSnackbar();
const [showAdvanced, setShowAdvanced] = useState(false);
// TODO: implement studyset snapshot
// const [showAdvanced, setShowAdvanced] = useState(false);

const handleCreateSpecification = async () => {
if (props.algorithm?.estimator?.label && props.selection?.selectionKey) {
const metaAnalysis = await createMetaAnalysis(
projectId,
EAnalysisType.CBMA,
props.algorithm.estimator,
props.algorithm.corrector,
studysetId,
annotationId,
props.selection?.selectionKey,
props.details.name,
props.details.description,
props.algorithm.estimatorArgs,
props.algorithm.correctorArgs
);
if (!metaAnalysis.data.specification || !metaAnalysis.data.id)
throw new Error('no specification ID found when creating a meta-analysis');
if (!props.algorithm?.estimator?.label || !props.selection?.selectionKey) return;
if (!props.selection || !props.selection.selectionValue) return;

const conditions = [props.selection.selectionValue] as string[] | boolean[];
const weights = [1];

const metaAnalysis = await createMetaAnalysis(
projectId,
EAnalysisType.CBMA,
props.algorithm.estimator,
props.algorithm.corrector,
studysetId,
annotationId,
props.selection?.selectionKey,
props.details.name,
props.details.description,
props.algorithm.estimatorArgs,
props.algorithm.correctorArgs,
conditions,
weights
);
if (!metaAnalysis.data.specification || !metaAnalysis.data.id)
throw new Error('no specification ID found when creating a meta-analysis');

enqueueSnackbar('created meta analysis specification successfully', {
variant: 'success',
});
history.push(`/projects/${projectId}/meta-analyses/${metaAnalysis.data.id}`);
}
enqueueSnackbar('created meta analysis specification successfully', {
variant: 'success',
});
history.push(`/projects/${projectId}/meta-analyses/${metaAnalysis.data.id}`);
};

const selectedAnnotations = getFilteredAnnotationNotes(
(annotations?.notes || []) as NoteCollectionReturn[],
props.selection?.selectionKey
);
const numSelectedAnnotationsText = useMemo(() => {
const selectedAnnotations = getFilteredAnnotationNotes(
(annotations?.notes || []) as NoteCollectionReturn[],
props.selection
);
const totalNumAnnotations = (annotations?.notes || []).length;
return `${selectedAnnotations.length} / ${totalNumAnnotations} analyses selected`;
}, [annotations?.notes, props.selection]);

const selectionText = useMemo(() => {
if (!props.selection) return '';
const selectionKey = props.selection.selectionKey;
const selectionValue = props.selection.selectionValue
? `: ${props.selection.selectionValue}`
: '';
return `${selectionKey} ${selectionValue}`;
}, [props.selection]);

return (
<StateHandlerComponent
Expand All @@ -102,10 +108,8 @@ const CreateMetaAnalysisSpecificationReview: React.FC<{
/>
<MetaAnalysisSummaryRow
title="Selection"
value={props.selection?.selectionKey || ''}
caption={`${selectedAnnotations.length} / ${
(annotations?.notes || []).length
} analyses selected`}
value={selectionText}
caption={numSelectedAnnotationsText}
></MetaAnalysisSummaryRow>
<MetaAnalysisSummaryRow
title="Estimator"
Expand All @@ -131,7 +135,7 @@ const CreateMetaAnalysisSpecificationReview: React.FC<{
)}
</MetaAnalysisSummaryRow>
)}
<Box>
{/* <Box>
<Button color="info" onClick={() => setShowAdvanced((prev) => !prev)}>
{showAdvanced ? 'hide' : 'show'} advanced
</Button>
Expand Down Expand Up @@ -163,7 +167,7 @@ const CreateMetaAnalysisSpecificationReview: React.FC<{
</FormControl>
</Box>
)}
</Box>
</Box> */}
</Box>
<Box sx={{ marginTop: '1rem', display: 'flex', justifyContent: 'space-between' }}>
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,36 @@ import {
} from 'pages/Projects/ProjectPage/ProjectStore';
import { useState } from 'react';
import SelectAnalysesComponent from './SelectAnalysesComponent/SelectAnalysesComponent';
import SelectAnalysesSummaryComponent from './SelectAnalysesSummaryComponent/SelectAnalysesSummaryComponent';
import SelectAnalysesSummaryComponent from './SelectAnalysesComponent/SelectAnalysesSummaryComponent';
import {
IAlgorithmSelection,
IAnalysesSelection,
} from '../CreateMetaAnalysisSpecificationDialogBase.types';
import { AnnotationNoteValue } from 'components/HotTables/HotTables.types';

const CreateMetaAnalysisSpecificationSelectionStep: React.FC<{
onChooseSelection: (selectionKey: string, type: EPropertyType) => void;
onChooseSelection: (
selectionKey: string,
type: EPropertyType,
selectionValue?: AnnotationNoteValue
) => void;
onNavigate: (button: ENavigationButton) => void;
selection: { selectionKey: string | undefined; type: EPropertyType } | undefined;
selection: IAnalysesSelection | undefined;
algorithm: IAlgorithmSelection;
}> = (props) => {
const annotationId = useProjectExtractionAnnotationId();
const studysetId = useProjectExtractionStudysetId();
const [selectedValue, setSelectedValue] = useState<
| {
selectionKey: string | undefined;
type: EPropertyType;
}
| undefined
>(props.selection);
const [selectedValue, setSelectedValue] = useState<IAnalysesSelection | undefined>(
props.selection
);

const handleNavigate = (button: ENavigationButton) => {
if (selectedValue?.selectionKey && selectedValue?.type !== EPropertyType.NONE)
props.onChooseSelection(selectedValue.selectionKey, selectedValue.type);
props.onChooseSelection(
selectedValue.selectionKey,
selectedValue.type,
selectedValue.selectionValue
);
props.onNavigate(button);
};

Expand All @@ -39,19 +49,16 @@ const CreateMetaAnalysisSpecificationSelectionStep: React.FC<{
</Typography>
</Box>
<Box>
<Typography gutterBottom>
<Typography gutterBottom sx={{ marginBottom: '1rem' }}>
Select the <b>annotation inclusion column</b> that you would like to use to
select the analyses for your meta-analysis.
</Typography>
<Typography sx={{ color: 'warning.dark', marginBottom: '1rem' }}>
At the moment, only boolean columns will be supported. We will be adding support
for the other types in the near future.
</Typography>

<SelectAnalysesComponent
selectedValue={selectedValue}
onSelectValue={(val) => setSelectedValue(val)}
annotationdId={annotationId || ''}
algorithm={props.algorithm}
/>

<Box
Expand All @@ -69,7 +76,11 @@ const CreateMetaAnalysisSpecificationSelectionStep: React.FC<{
/>
<Button
variant="contained"
disabled={!selectedValue?.selectionKey}
sx={{ width: '200px' }}
disabled={
!selectedValue?.selectionKey ||
selectedValue?.selectionValue === undefined
}
onClick={() => handleNavigate(ENavigationButton.NEXT)}
>
next
Expand Down
Loading

0 comments on commit ea9e87a

Please sign in to comment.