Skip to content

Commit d4d6dbc

Browse files
committed
feat: minor fixes
1 parent 83ef98f commit d4d6dbc

File tree

5 files changed

+24
-92
lines changed

5 files changed

+24
-92
lines changed

compose/neurosynth-frontend/src/components/HotTables/HotTables.utils.tsx

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ export const noteKeyObjToArr = (noteKeys?: object | null): NoteKeyType[] => {
99
.map(([key, descriptor]) => {
1010
if (!descriptor?.type) throw new Error('Invalid note_keys descriptor: missing type');
1111
return {
12-
// rely on new descriptor shape (type + order)
1312
type: descriptor.type,
1413
key,
1514
order: descriptor.order ?? 0,
@@ -23,25 +22,23 @@ export const noteKeyObjToArr = (noteKeys?: object | null): NoteKeyType[] => {
2322
export const noteKeyArrToObj = (
2423
noteKeyArr: NoteKeyType[]
2524
): { [key: string]: { type: EPropertyType; order: number } } => {
26-
const noteKeyObj = noteKeyArr.reduce((acc, curr, index) => {
27-
acc[curr.key] = {
28-
type: curr.type,
29-
order: curr.order ?? index,
30-
};
31-
return acc;
32-
}, {} as { [key: string]: { type: EPropertyType; order: number } });
25+
const noteKeyObj = noteKeyArr.reduce(
26+
(acc, curr, index) => {
27+
acc[curr.key] = {
28+
type: curr.type,
29+
order: curr.order ?? index,
30+
};
31+
return acc;
32+
},
33+
{} as { [key: string]: { type: EPropertyType; order: number } }
34+
);
3335

3436
return noteKeyObj;
3537
};
3638

3739
export const booleanValidator = (value: CellValue, callback: (isValid: boolean) => void) => {
3840
const isValid =
39-
value === true ||
40-
value === false ||
41-
value === 'true' ||
42-
value === 'false' ||
43-
value === null ||
44-
value === '';
41+
value === true || value === false || value === 'true' || value === 'false' || value === null || value === '';
4542
callback(isValid);
4643
};
4744

@@ -54,7 +51,7 @@ export const replaceString = (val: string) => {
5451
export const stripTags = (stringWhichMayHaveHTML: any) => {
5552
if (typeof stringWhichMayHaveHTML !== 'string') return '';
5653

57-
let doc = new DOMParser().parseFromString(stringWhichMayHaveHTML, 'text/html');
54+
const doc = new DOMParser().parseFromString(stringWhichMayHaveHTML, 'text/html');
5855
return doc.body.textContent || '';
5956
};
6057

compose/neurosynth-frontend/src/pages/Annotations/components/EditAnnotationsHotTable.tsx

Lines changed: 4 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -139,52 +139,6 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
139139
}
140140
};
141141

142-
const reorderArray = <T,>(arr: T[], from: number, to: number) => {
143-
if (from === to) return [...arr];
144-
const updated = [...arr];
145-
const [removed] = updated.splice(from, 1);
146-
updated.splice(to, 0, removed);
147-
return updated;
148-
};
149-
150-
const handleColumnMove = (movedColumns: number[], finalIndex: number) => {
151-
if (!canEdit) return;
152-
if (!movedColumns.length) return;
153-
const fromVisualIndex = movedColumns[0];
154-
const toVisualIndex = finalIndex;
155-
156-
if (fromVisualIndex < 2 || toVisualIndex < 2) return; // lock study/analysis columns
157-
158-
const from = fromVisualIndex - 2;
159-
let to = toVisualIndex - 2;
160-
161-
setAnnotationsHotState((prev) => {
162-
if (from >= prev.noteKeys.length) return prev;
163-
if (to >= prev.noteKeys.length) to = prev.noteKeys.length - 1;
164-
165-
const updatedNoteKeys = reorderArray(prev.noteKeys, from, to).map((noteKey, index) => ({
166-
...noteKey,
167-
order: index,
168-
}));
169-
170-
const updatedHotData = prev.hotData.map((row) => {
171-
const metadataCols = row.slice(0, 2);
172-
const noteCols = reorderArray(row.slice(2), from, to);
173-
return [...metadataCols, ...noteCols];
174-
});
175-
176-
return {
177-
...prev,
178-
isEdited: true,
179-
noteKeys: updatedNoteKeys,
180-
hotColumns: createColumns(updatedNoteKeys, !canEdit),
181-
hotData: updatedHotData,
182-
};
183-
});
184-
185-
hotTableRef.current?.hotInstance?.getPlugin('manualColumnMove').clearMoves();
186-
};
187-
188142
/**
189143
* NOTE: there is a bug where fixed, mergedCells (such as the cells showing our studies) get messed up when you scroll to the right. I think that this is
190144
* due to virtualization - as we scroll to the right, the original heights of the cells are no longer in the DOM and so the calculated row heights are lost and
@@ -215,9 +169,10 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
215169
if (noteKeys.find((x) => x.key === trimmedKey)) return false;
216170

217171
setAnnotationsHotState((prev) => {
218-
const updatedNoteKeys = [{ key: trimmedKey, type: getType(row.metadataValue), order: 0 }, ...prev.noteKeys].map(
219-
(noteKey, index) => ({ ...noteKey, order: index })
220-
);
172+
const updatedNoteKeys = [
173+
{ key: trimmedKey, type: getType(row.metadataValue), order: 0 },
174+
...prev.noteKeys,
175+
].map((noteKey, index) => ({ ...noteKey, order: index }));
221176

222177
return {
223178
...prev,
@@ -292,14 +247,12 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
292247
mergeCells={mergeCells}
293248
disableVisualSelection={!canEdit}
294249
colHeaders={hotColumnHeaders}
295-
manualColumnMove={canEdit}
296250
colWidths={colWidths}
297251
rowHeights={rowHeights}
298252
columns={hotColumns}
299253
data={JSON.parse(JSON.stringify(hotData))}
300254
afterOnCellMouseUp={handleCellMouseUp}
301255
beforeOnCellMouseDown={handleCellMouseDown}
302-
afterColumnMove={handleColumnMove}
303256
/>
304257
) : (
305258
<Typography sx={{ color: 'warning.dark' }}>

compose/neurosynth-frontend/src/pages/MetaAnalysis/components/SelectAnalysesComponent.tsx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ import {
1010
IAlgorithmSelection,
1111
IAnalysesSelection,
1212
} from 'pages/MetaAnalysis/components/CreateMetaAnalysisSpecificationDialogBase.types';
13-
import {
14-
isMultiGroupAlgorithm,
15-
selectedReferenceDatasetIsDefaultDataset,
16-
} from './SelectAnalysesComponent.helpers';
13+
import { isMultiGroupAlgorithm, selectedReferenceDatasetIsDefaultDataset } from './SelectAnalysesComponent.helpers';
1714
import { DEFAULT_REFERENCE_DATASETS } from './SelectAnalysesComponent.types';
1815
import SelectAnalysesComponentTable from './SelectAnalysesComponentTable';
1916
import SelectAnalysesStringValue from './SelectAnalysesStringValue';
@@ -50,13 +47,7 @@ const SelectAnalysesComponent: React.FC<{
5047
onSelectValue(initialVal);
5148
selectionOccurred.current = true;
5249
}
53-
}, [
54-
selectedValue.selectionKey,
55-
annotation,
56-
onSelectValue,
57-
selectionOccurred,
58-
algorithm?.estimator,
59-
]);
50+
}, [selectedValue.selectionKey, annotation, onSelectValue, selectionOccurred, algorithm?.estimator]);
6051

6152
const options = useMemo(() => {
6253
return noteKeyObjToArr(annotation?.note_keys)
@@ -77,17 +68,13 @@ const SelectAnalysesComponent: React.FC<{
7768
const handleSelectColumn = (newVal: IAnalysesSelection | undefined) => {
7869
if (newVal?.selectionKey === selectedValue.selectionKey) return; // we selected the same option that is already selected
7970

80-
const referenceDatasetIsNowInvalid = !selectedReferenceDatasetIsDefaultDataset(
81-
selectedValue.referenceDataset
82-
);
71+
const referenceDatasetIsNowInvalid = !selectedReferenceDatasetIsDefaultDataset(selectedValue.referenceDataset);
8372
if (!newVal) {
8473
onSelectValue({
8574
selectionKey: undefined,
8675
type: undefined,
8776
selectionValue: undefined,
88-
referenceDataset: referenceDatasetIsNowInvalid
89-
? undefined
90-
: selectedValue.referenceDataset,
77+
referenceDataset: referenceDatasetIsNowInvalid ? undefined : selectedValue.referenceDataset,
9178
});
9279
return;
9380
}
@@ -96,9 +83,7 @@ const SelectAnalysesComponent: React.FC<{
9683
selectionKey: newVal.selectionKey,
9784
type: newVal.type,
9885
selectionValue: newVal.type === EPropertyType.BOOLEAN ? true : undefined,
99-
referenceDataset: referenceDatasetIsNowInvalid
100-
? undefined
101-
: selectedValue.referenceDataset,
86+
referenceDataset: referenceDatasetIsNowInvalid ? undefined : selectedValue.referenceDataset,
10287
};
10388
onSelectValue(update);
10489
};
@@ -109,9 +94,7 @@ const SelectAnalysesComponent: React.FC<{
10994
sx={CreateMetaAnalysisSpecificationDialogBaseStyles.highlightInput}
11095
label="Inclusion Column"
11196
shouldDisable={false}
112-
isOptionEqualToValue={(option, value) =>
113-
option?.selectionKey === value?.selectionKey
114-
}
97+
isOptionEqualToValue={(option, value) => option?.selectionKey === value?.selectionKey}
11598
value={selectedValue?.selectionKey ? selectedValue : undefined}
11699
size="medium"
117100
inputPropsSx={{

compose/neurosynth-frontend/src/pages/Project/components/MoveToExtractionDialog.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const MoveToExtractionDialog: React.FC<IDialog> = (props) => {
4242

4343
const navigate = useNavigate();
4444

45-
const [isLoadingPhase, setIsLoadingPhase] = useState(false);
4645
const [isError, setIsError] = useState(false);
4746
const [loadingStatus, setLoadingStatus] = useState<{
4847
createdStudyset: boolean;
@@ -55,7 +54,6 @@ const MoveToExtractionDialog: React.FC<IDialog> = (props) => {
5554
});
5655

5756
const handleCloseDialog = () => {
58-
setIsLoadingPhase(false);
5957
setLoadingStatus({
6058
createdAnnotations: false,
6159
createdStudyset: false,

compose/neurosynth-frontend/src/stores/AnnotationStore.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ import {
1717
import { setUnloadHandler } from 'helpers/BeforeUnload.helpers';
1818
import { noteKeyArrToObj } from 'components/HotTables/HotTables.utils';
1919

20-
const normalizeNoteKeyOrder = (noteKeys: NoteKeyType[]) => noteKeys.map((noteKey, index) => ({ ...noteKey, order: index }));
20+
const normalizeNoteKeyOrder = (noteKeys: NoteKeyType[]) =>
21+
noteKeys.map((noteKey, index) => ({ ...noteKey, order: index }));
2122

2223
export const useAnnotationStore = create<
2324
{

0 commit comments

Comments
 (0)