Skip to content

Commit e08f343

Browse files
committed
feat: added responsiveness to extraction page
1 parent 27741d6 commit e08f343

16 files changed

+207
-160
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { useEffect, useState } from 'react';
2+
3+
const useGetWindowWidth = (debounceMs: number = 150) => {
4+
const [windowWidth, setWindowWidth] = useState(0);
5+
6+
useEffect(() => {
7+
let timeoutId: NodeJS.Timeout;
8+
9+
const handleResize = () => {
10+
clearTimeout(timeoutId);
11+
timeoutId = setTimeout(() => {
12+
const currentWindowSize = window.innerWidth;
13+
if (currentWindowSize) {
14+
setWindowWidth(currentWindowSize);
15+
}
16+
}, debounceMs);
17+
};
18+
19+
window.addEventListener('resize', handleResize);
20+
handleResize();
21+
22+
return () => {
23+
clearTimeout(timeoutId);
24+
window.removeEventListener('resize', handleResize);
25+
};
26+
}, [debounceMs]);
27+
return windowWidth;
28+
};
29+
30+
export default useGetWindowWidth;

compose/neurosynth-frontend/src/pages/Annotations/components/EditAnnotationsHotTable.styles.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

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

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@ import { Box, Typography } from '@mui/material';
33
import LoadingButton from 'components/Buttons/LoadingButton';
44
import { IMetadataRowModel, getType } from 'components/EditMetadata/EditMetadata.types';
55
import AddMetadataRow from 'components/EditMetadata/AddMetadataRow';
6-
import {
7-
createColumns,
8-
hotDataToAnnotationNotes,
9-
hotSettings,
10-
} from 'pages/Annotations/components/EditAnnotationsHotTable.helpers';
11-
import AnnotationsHotTableStyles from 'pages/Annotations/components/EditAnnotationsHotTable.styles';
126
import useEditAnnotationsHotTable from 'pages/Annotations/hooks/useEditAnnotationsHotTable';
137
import { noteKeyArrToObj } from 'components/HotTables/HotTables.utils';
148
import { CellCoords } from 'handsontable';
@@ -20,14 +14,13 @@ import useUserCanEdit from 'hooks/useUserCanEdit';
2014
import { useSnackbar } from 'notistack';
2115
import { useProjectUser } from 'pages/Project/store/ProjectStore';
2216
import React, { useEffect, useRef } from 'react';
17+
import { createColumns, hotDataToAnnotationNotes, hotSettings } from './EditAnnotationsHotTable.helpers';
2318

2419
registerAllModules();
2520

2621
const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((props) => {
2722
const { enqueueSnackbar } = useSnackbar();
28-
const { mutate, isLoading: updateAnnotationIsLoading } = useUpdateAnnotationById(
29-
props.annotationId
30-
);
23+
const { mutate, isLoading: updateAnnotationIsLoading } = useUpdateAnnotationById(props.annotationId);
3124
const projectUser = useProjectUser();
3225
const canEdit = useUserCanEdit(projectUser || undefined);
3326
const hotTableRef = useRef<HotTable>(null);
@@ -47,7 +40,7 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
4740
} = useEditAnnotationsHotTable(props.annotationId, !canEdit);
4841

4942
useEffect(() => {
50-
let timeout: any = setTimeout(() => {
43+
const timeout: any = setTimeout(() => {
5144
if (!hotTableRef.current?.hotInstance) return;
5245
const sizes = [
5346
'64px', // NAV_HEIGHT
@@ -88,11 +81,7 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
8881
return;
8982
}
9083

91-
const updatedAnnotationNotes = hotDataToAnnotationNotes(
92-
hotData,
93-
hotDataToStudyMapping,
94-
noteKeys
95-
);
84+
const updatedAnnotationNotes = hotDataToAnnotationNotes(hotData, hotDataToStudyMapping, noteKeys);
9685
const updatedNoteKeyObj = noteKeyArrToObj(noteKeys);
9786

9887
mutate(
@@ -138,11 +127,7 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
138127
});
139128
};
140129

141-
const handleCellMouseUp = (
142-
event: MouseEvent,
143-
coords: CellCoords,
144-
TD: HTMLTableCellElement
145-
): void => {
130+
const handleCellMouseUp = (event: MouseEvent, coords: CellCoords, TD: HTMLTableCellElement): void => {
146131
const target = event.target as HTMLButtonElement;
147132
if (coords.row < 0 && (target.tagName === 'svg' || target.tagName === 'path')) {
148133
handleRemoveHotColumn(TD.innerText);
@@ -179,10 +164,7 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
179164
if (noteKeys.find((x) => x.key === trimmedKey)) return false;
180165

181166
setAnnotationsHotState((prev) => {
182-
const updatedNoteKeys = [
183-
{ key: trimmedKey, type: getType(row.metadataValue) },
184-
...prev.noteKeys,
185-
];
167+
const updatedNoteKeys = [{ key: trimmedKey, type: getType(row.metadataValue) }, ...prev.noteKeys];
186168

187169
return {
188170
...prev,
@@ -227,8 +209,17 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
227209
<Box>
228210
{theUserOwnsThisAnnotation && canEdit && (
229211
<Box
230-
className="neurosynth-annotation-component"
231-
sx={[AnnotationsHotTableStyles.addMetadataRow]}
212+
sx={{
213+
mb: 1,
214+
width: {
215+
xs: '100%',
216+
md: '60%',
217+
lg: '50%',
218+
},
219+
display: 'grid',
220+
gridTemplateColumns: 'auto 1fr auto',
221+
gap: 4,
222+
}}
232223
>
233224
<AddMetadataRow
234225
keyPlaceholderText="New Annotation Key"
@@ -258,8 +249,7 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
258249
/>
259250
) : (
260251
<Typography sx={{ color: 'warning.dark' }}>
261-
There are no analyses to annotate. Get started by adding analyses to your
262-
studies.
252+
There are no analyses to annotate. Get started by adding analyses to your studies.
263253
</Typography>
264254
)}
265255
</Box>
@@ -275,7 +265,7 @@ const AnnotationsHotTable: React.FC<{ annotationId?: string }> = React.memo((pro
275265
xs: '90%',
276266
md: '80%',
277267
},
278-
zIndex: 1000,
268+
zIndex: 999,
279269
}}
280270
>
281271
<LoadingButton

compose/neurosynth-frontend/src/pages/Study/EditStudyPage.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,14 @@ const EditStudyPage: React.FC = () => {
8282
xs: 'column-reverse',
8383
md: 'row',
8484
},
85-
boxSizing: 'border-box',
8685
}}
8786
>
8887
<Box
8988
sx={{
90-
flexGrow: 1,
89+
width: {
90+
xs: '100%',
91+
md: 'calc(100% - 62px - 1rem)',
92+
},
9193
mr: {
9294
xs: 0,
9395
md: 2,
@@ -137,11 +139,9 @@ const EditStudyPage: React.FC = () => {
137139
</Box>
138140
<Box
139141
sx={{
140-
position: 'sticky', // this is needed when the toolbar is on top of the eidt study content
142+
position: 'sticky', // this is needed when the toolbar is on top of the edit study content
141143
top: '0',
142-
pt: 1,
143-
backgroundColor: 'white',
144-
zIndex: 1000,
144+
zIndex: 999,
145145
mb: 1,
146146
}}
147147
>

compose/neurosynth-frontend/src/pages/Study/components/EditStudyAnalyses.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Add } from '@mui/icons-material';
22
import { Box, Button, Divider, Typography } from '@mui/material';
3-
import EditStudyComponentsStyles from 'pages/Study/components/EditStudyComponents.styles';
43
import NeurosynthAccordion from 'components/NeurosynthAccordion/NeurosynthAccordion';
4+
import EditStudyComponentsStyles from 'pages/Study/components/EditStudyComponents.styles';
55
import { useAddOrUpdateAnalysis, useStudyAnalyses, useStudyId } from 'pages/Study/store/StudyStore';
66
import React, { useCallback, useEffect, useState } from 'react';
77
import { useCreateAnnotationNote } from 'stores/AnnotationStore.actions';
@@ -68,7 +68,7 @@ const EditStudyAnalyses: React.FC = React.memo(() => {
6868
accordionSummarySx={EditStudyComponentsStyles.accordionSummary}
6969
TitleElement={<Typography sx={EditStudyComponentsStyles.accordionTitle}>Analyses</Typography>}
7070
>
71-
<Box sx={{ width: '100%', margin: '0.5rem 0' }}>
71+
<Box sx={{ padding: '0.5rem 0' }}>
7272
<Box sx={{ marginBottom: '1rem' }}>
7373
{analyses.length === 0 && (
7474
<Typography sx={{ color: 'warning.dark' }} gutterBottom>
@@ -89,15 +89,21 @@ const EditStudyAnalyses: React.FC = React.memo(() => {
8989
<>
9090
<Divider />
9191
<Box sx={{ display: 'flex' }}>
92-
<EditStudyAnalysesList
93-
analyses={analyses}
94-
selectedAnalysisId={selectedAnalysisId}
95-
onSelectAnalysis={handleSelectAnalysis}
96-
/>
92+
<Box>
93+
<EditStudyAnalysesList
94+
analyses={analyses}
95+
selectedAnalysisId={selectedAnalysisId}
96+
onSelectAnalysis={handleSelectAnalysis}
97+
/>
98+
</Box>
9799
<Box
98100
sx={{
101+
boxSizing: 'border-box',
99102
padding: '1rem 0 1rem 1rem',
100-
// width: 'calc(100% - 250px - 1rem)',
103+
width: {
104+
xs: 'calc(100% - 150px)',
105+
md: 'calc(100% - 250px)',
106+
},
101107
}}
102108
>
103109
<EditStudyAnalysis

compose/neurosynth-frontend/src/pages/Study/components/EditStudyAnalysesList.tsx

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Box, List } from '@mui/material';
1+
import { List } from '@mui/material';
22
import { IStoreAnalysis } from 'pages/Study/store/StudyStore.helpers';
33
import { useCallback } from 'react';
44
import StudyAnalysesListItem from './StudyAnalysesListItem';
@@ -18,37 +18,28 @@ const EditStudyAnalysesList: React.FC<{
1818
);
1919

2020
return (
21-
<Box
21+
<List
2222
sx={{
2323
borderLeft: '1px solid lightgray',
2424
borderRight: '1px solid lightgray',
2525
width: {
2626
xs: '150px',
2727
md: '250px',
2828
},
29+
maxHeight: '946px',
30+
overflow: 'auto',
2931
}}
32+
disablePadding
3033
>
31-
<List
32-
sx={{
33-
width: {
34-
xs: '150px',
35-
md: '250px',
36-
},
37-
maxHeight: '946px',
38-
overflow: 'auto',
39-
}}
40-
disablePadding
41-
>
42-
{analyses.map((analysis) => (
43-
<StudyAnalysesListItem
44-
key={analysis.id}
45-
analysis={analysis}
46-
onSelectAnalysis={handleSelectAnalysis}
47-
selected={(analysis.id || null) === (selectedAnalysisId || undefined)}
48-
/>
49-
))}
50-
</List>
51-
</Box>
34+
{analyses.map((analysis) => (
35+
<StudyAnalysesListItem
36+
key={analysis.id}
37+
analysis={analysis}
38+
onSelectAnalysis={handleSelectAnalysis}
39+
selected={(analysis.id || null) === (selectedAnalysisId || undefined)}
40+
/>
41+
))}
42+
</List>
5243
);
5344
};
5445

compose/neurosynth-frontend/src/pages/Study/components/EditStudyAnalysis.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const EditStudyAnalysis: React.FC<{
3030
};
3131

3232
return (
33-
<Box sx={{ marginBottom: '2rem', width: '100%' }}>
33+
<Box sx={{ marginBottom: '2rem' }}>
3434
<StudyAnalysisWarnings analysisId={props.analysisId} />
3535
<EditStudyAnalysisDetails analysisId={props.analysisId} />
3636
<EditStudyAnalysisPoints analysisId={props.analysisId} />

compose/neurosynth-frontend/src/pages/Study/components/EditStudyAnalysisPoints.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@ import EditStudyAnalysisPointSpaceAndStatistic from 'pages/Study/components/Edit
55

66
const EditStudyAnalysisPoints: React.FC<{ analysisId?: string }> = (props) => {
77
return (
8-
<Box sx={{ marginTop: '2rem', width: '100%' }}>
8+
<Box sx={{ marginTop: '2rem' }}>
99
<Box sx={{ display: 'flex', alignItems: 'center', margin: '0.5rem 0' }}>
10-
<Typography sx={{ fontWeight: 'bold', marginRight: '1rem' }}>
11-
Analysis Coordinates
12-
</Typography>
10+
<Typography sx={{ fontWeight: 'bold', marginRight: '1rem' }}>Analysis Coordinates</Typography>
1311
<Tooltip
1412
title="To add or remove rows, right click on a cell to open the context menu. You must enter all coordinates in order to save the overall study. Please note that the ordering of points is not guaranteed."
1513
placement="right"
1614
>
1715
<HelpIcon color="primary" />
1816
</Tooltip>
1917
</Box>
20-
<EditStudyAnalysisPointSpaceAndStatistic analysisId={props.analysisId} />
18+
{/* <EditStudyAnalysisPointSpaceAndStatistic analysisId={props.analysisId} /> */}
2119
<EditStudyAnalysisPointsHotTable analysisId={props.analysisId} />
2220
</Box>
2321
);

compose/neurosynth-frontend/src/pages/Study/components/EditStudyAnalysisPointsHotTable.helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export const EditStudyAnalysisPointsDefaultConfig: HotTableProps = {
7676
undo: false,
7777
manualColumnResize: false,
7878
allowInsertColumn: false,
79-
colWidths: [50, 50, 50, 150, 150, 100],
79+
colWidths: [50, 50, 50, 100, 140, 100],
8080
};
8181

8282
export const getHotTableInsertionIndices = (selectedCoords: [number, number, number, number][]) => {

0 commit comments

Comments
 (0)