Skip to content

Commit 2438ac9

Browse files
authored
fix: added order and added test (#714)
* fix: added order and added test * fix: fix failing test case * feat: added order on put requests
1 parent 8275a55 commit 2438ac9

File tree

11 files changed

+65
-25
lines changed

11 files changed

+65
-25
lines changed

compose/neurosynth-frontend/src/components/Dialogs/ConfirmationDialog/ConfirmationDialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const ConfirmationDialog: React.FC<IConfirmationDialog> = (props) => {
5050
<Button
5151
sx={{ width: '250px', marginRight: '15px' }}
5252
onClick={() => props.onCloseDialog(false, props.data)}
53-
variant="contained"
53+
variant="text"
5454
color="error"
5555
>
5656
{props.rejectText ? props.rejectText : 'Reject'}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { render, screen } from '@testing-library/react';
2+
import FullTextChip from './FullTextChip';
3+
import { useStudyName } from 'pages/Studies/StudyStore';
4+
import { useGetFullText } from 'hooks';
5+
6+
jest.mock('pages/Studies/StudyStore');
7+
jest.mock('hooks');
8+
describe('FullTextChip Component', () => {
9+
it('should render', () => {
10+
render(<FullTextChip />);
11+
});
12+
13+
it('should show the chip with the link', async () => {
14+
(useStudyName as jest.Mock).mockReturnValue(undefined);
15+
useGetFullText().data = 'study-name';
16+
render(<FullTextChip name="study-name" />);
17+
const element = await screen.findByRole('link');
18+
expect(element).toBeInTheDocument();
19+
expect(element.getAttribute('href')).toEqual('study-name');
20+
});
21+
22+
it('should not show the chip with the link', () => {
23+
(useStudyName as jest.Mock).mockReturnValue(undefined);
24+
useGetFullText().data = '';
25+
render(<FullTextChip name="study-name" />);
26+
const element = screen.queryByRole('link');
27+
expect(element).not.toBeInTheDocument();
28+
});
29+
});

compose/neurosynth-frontend/src/components/DisplayStudy/DisplayStudyChipLinks/FullTextChip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
22
import { Chip } from '@mui/material';
3-
import useGetFullText from 'hooks/external/useGetFullText';
3+
import { useGetFullText } from 'hooks';
44
import { useStudyName } from 'pages/Studies/StudyStore';
55
import { useEffect, useState } from 'react';
66
import DisplayStudyChipLinksStyles from './DisplayStudyChipLinks.styles';

compose/neurosynth-frontend/src/components/EditStudyComponents/EditStudySaveButton/EditStudySaveButton.tsx

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { Box } from '@mui/material';
21
import LoadingButton from 'components/Buttons/LoadingButton/LoadingButton';
32
import { AnalysisReturn, StudyRequest } from 'neurostore-typescript-sdk';
43
import { useSnackbar } from 'notistack';
@@ -16,7 +15,7 @@ import {
1615
useUpdateAnnotationById,
1716
useUpdateStudyset,
1817
} from 'hooks';
19-
import EditStudyPageStyles from 'pages/Studies/EditStudyPage/EditStudyPage.styles';
18+
import { STUDYSET_QUERY_STRING } from 'hooks/studysets/useGetStudysets';
2019
import {
2120
useStudy,
2221
useStudyAnalyses,
@@ -38,9 +37,7 @@ import {
3837
import { storeNotesToDBNotes } from 'stores/AnnotationStore.helpers';
3938
import API from 'utils/api';
4039
import { arrayToMetadata } from '../EditStudyMetadata/EditStudyMetadata';
41-
import EditStudySwapVersionButton from '../EditStudySwapVersionButton/EditStudySwapVersionButton';
4240
import { hasDuplicateStudyAnalysisNames, hasEmptyStudyPoints } from './EditStudySaveButton.helpers';
43-
import { STUDYSET_QUERY_STRING } from 'hooks/studysets/useGetStudysets';
4441

4542
const EditStudySaveButton: React.FC = React.memo((props) => {
4643
const { user } = useAuth0();
@@ -273,19 +270,16 @@ const EditStudySaveButton: React.FC = React.memo((props) => {
273270
};
274271

275272
return (
276-
<Box sx={EditStudyPageStyles.loadingButtonContainer}>
277-
<EditStudySwapVersionButton />
278-
<LoadingButton
279-
text="save"
280-
isLoading={updateStudyIsLoading || updateAnnotationIsLoading || isCloning}
281-
variant="contained"
282-
loaderColor="secondary"
283-
disabled={!studyHasBeenEdited && !annotationHasBeenEdited}
284-
disableElevation
285-
sx={{ width: '280px', height: '36px' }}
286-
onClick={handleSave}
287-
/>
288-
</Box>
273+
<LoadingButton
274+
text="save"
275+
isLoading={updateStudyIsLoading || updateAnnotationIsLoading || isCloning}
276+
variant="contained"
277+
loaderColor="secondary"
278+
disabled={!studyHasBeenEdited && !annotationHasBeenEdited}
279+
disableElevation
280+
sx={{ width: '280px', height: '36px' }}
281+
onClick={handleSave}
282+
/>
289283
);
290284
});
291285

compose/neurosynth-frontend/src/components/FullTextLinkComponent/FullTextLinkComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Box, Link, Typography } from '@mui/material';
22
import ProgressLoader from 'components/ProgressLoader/ProgressLoader';
3-
import useGetFullText from 'hooks/external/useGetFullText';
3+
import { useGetFullText } from 'hooks';
44

55
const FullTextLinkComponent: React.FC<{ paperTitle: string; text?: string }> = (props) => {
66
const { paperTitle, text = 'article full text' } = props;

compose/neurosynth-frontend/src/hooks/__mocks__/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ const useGetStudysetById = jest.fn().mockReturnValue({
125125
data: mockStudysetNested(),
126126
});
127127

128+
const useGetFullText = jest.fn().mockReturnValue({
129+
isLoading: false,
130+
isError: false,
131+
data: '',
132+
});
133+
128134
const useIsMounted = () => {
129135
return {
130136
__esModule: true,
@@ -157,4 +163,5 @@ export {
157163
useDeleteProject,
158164
useGetExtractionSummary,
159165
useGetStudysetById,
166+
useGetFullText,
160167
};

compose/neurosynth-frontend/src/hooks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import useGetStudyById from './studies/useGetStudyById';
3434
import useUpdateAnnotationById from './analyses/useUpdateAnnotationById';
3535
import useGetExtractionSummary from './useGetExtractionSummary';
3636
import useGetCurationSummary from './useGetCurationSummary';
37+
import useGetFullText from './external/useGetFullText';
3738

3839
export {
3940
useGetCurationSummary,
@@ -44,6 +45,7 @@ export {
4445
useGuard,
4546
useGetTour,
4647
useGetWindowHeight,
48+
useGetFullText,
4749
// STUDIES
4850
useGetBaseStudies,
4951
useGetStudyById,

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import {
2020
useInitStudyStore,
2121
useStudyId,
2222
} from '../StudyStore';
23+
import EditStudyPageStyles from './EditStudyPage.styles';
24+
import EditStudySwapVersionButton from 'components/EditStudyComponents/EditStudySwapVersionButton/EditStudySwapVersionButton';
2325

2426
const EditStudyPage: React.FC = (props) => {
2527
const { studyId } = useParams<{ studyId: string }>();
@@ -68,7 +70,10 @@ const EditStudyPage: React.FC = (props) => {
6870
<Box sx={{ marginBottom: '5rem' }}>
6971
<EditAnalyses />
7072
</Box>
71-
<EditStudySaveButton />
73+
<Box sx={EditStudyPageStyles.loadingButtonContainer}>
74+
<EditStudySwapVersionButton />
75+
<EditStudySaveButton />
76+
</Box>
7277
</StateHandlerComponent>
7378
);
7479
};

compose/neurosynth-frontend/src/pages/Studies/StudyStore.helpers.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export const studyAnalysesToStoreAnalyses = (analyses?: AnalysisReturn[]): IStor
199199
});
200200

201201
return (studyAnalyses || []).sort((a, b) => {
202-
return (a.name || '').localeCompare(b.name || '');
202+
return (a.order as number) - (b.order as number);
203203

204204
// previously sorted by date: may want this again in the future
205205
// const dateA = Date.parse(a.created_at || '');
@@ -214,7 +214,7 @@ export const storeAnalysesToStudyAnalyses = (analyses?: IStoreAnalysis[]): Analy
214214
// we therefore need to scrub the id from the analysis if it was newly created by us.
215215
// we also need to remove the readonly attributes and any attributes we added
216216
const updatedAnalyses: AnalysisRequest[] = (analyses || []).map(
217-
({ isNew, conditions, points, pointSpace, pointStatistic, ...analysisArgs }) => {
217+
({ isNew, conditions, points, pointSpace, pointStatistic, ...analysisArgs }, index) => {
218218
const scrubbedConditions: ConditionRequest[] = conditions.map(({ isNew, ...args }) => ({
219219
name: args.name,
220220
description: args.description,
@@ -250,6 +250,7 @@ export const storeAnalysesToStudyAnalyses = (analyses?: IStoreAnalysis[]): Analy
250250
conditions: scrubbedConditions,
251251
points: scrubbedPoints,
252252
id: isNew ? undefined : analysisArgs.id,
253+
order: index + 1, // order is not 0 indexed in the BE
253254
};
254255
}
255256
);

0 commit comments

Comments
 (0)