Skip to content

Commit

Permalink
Merge branch 'master' of github.com:neurostuff/neurostore into enh/ad…
Browse files Browse the repository at this point in the history
…d_studyset_references_endpoint
  • Loading branch information
jdkent committed Sep 22, 2023
2 parents 6325660 + 76ec881 commit ebba545
Show file tree
Hide file tree
Showing 31 changed files with 647 additions and 337 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

export {};

const PATH = '/studies/mock-study-id/edit';
const PATH = '/projects/abc123/extraction/studies/mock-study-id/edit';
const PAGE_NAME = 'EditStudyPage';

describe(PAGE_NAME, () => {
Expand All @@ -12,11 +12,11 @@ describe(PAGE_NAME, () => {
});

it('should load', () => {
cy.intercept('GET', `**/api/projects*`).as('realProjectsRequest');
cy.intercept('GET', `**/api/projects/*`, { fixture: 'project' }).as('projectFixture');
cy.intercept('GET', `**/api/studies/mock-study-id*`, { fixture: 'study' }).as(
'studyFixture'
);
cy.visit(PATH).wait('@studyFixture');
cy.visit(PATH).wait('@projectFixture').wait('@studyFixture');
// cy.login('mocked').wait('@realProjectsRequest').visit(PATH).wait('@studyFixture');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { mockStudies } from 'testing/mockData';

export {};

const PATH = '/studies';
const PATH = '/base-studies';
const PAGE_NAME = 'StudiesPage';

describe(PAGE_NAME, () => {
Expand Down
10 changes: 2 additions & 8 deletions compose/neurosynth-frontend/cypress/e2e/pages/StudyPage.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@ describe(PAGE_NAME, () => {
cy.intercept('GET', `**/api/studies/**`, {
fixture: 'study',
}).as('studyFixture');
cy.intercept('GET', `**/api/base-studies/**`, {
fixture: 'baseStudy',
}).as('baseStudyFixture');

cy.visit(PATH)
.wait('@semanticScholarFixture')
.wait('@studyFixture')
.wait('@baseStudyFixture');

cy.visit(PATH).wait('@semanticScholarFixture').wait('@studyFixture');
// .get('tr')
// .eq(2)
// .click()
Expand Down
47 changes: 47 additions & 0 deletions compose/neurosynth-frontend/cypress/fixtures/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"created_at": "2023-09-14T18:04:28.079423+00:00",
"description": "",
"id": "4HxF4g4WC5zj",
"meta_analyses": [],
"name": "My project name",
"neurostore_study": {
"created_at": "2023-09-14T18:04:28.090521+00:00",
"exception": null,
"neurostore_id": "4PG9x8gYaoWd",
"status": "PENDING",
"traceback": null,
"updated_at": "2023-09-14T18:04:28.111166+00:00"
},
"neurostore_url": "https://neurostore.org/api/studies/4PG9x8gYaoWd",
"provenance": {
"curationMetadata": {
"columns": [],
"exclusionTags": [],
"identificationSources": [],
"infoTags": [],
"prismaConfig": {
"eligibility": {
"exclusionTags": []
},
"identification": {
"exclusionTags": []
},
"isPrisma": false,
"screening": {
"exclusionTags": []
}
}
},
"extractionMetadata": {
"studyStatusList": []
},
"metaAnalysisMetadata": {
"canEditMetaAnalyses": false
}
},
"public": false,
"updated_at": "2023-09-14T18:04:34.184976+00:00",
"user": "github|12387943",
"username": "Nicholas Lee"
}

71 changes: 37 additions & 34 deletions compose/neurosynth-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion compose/neurosynth-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"@testing-library/user-event": "^12.8.3",
"@types/body-scroll-lock": "^3.1.0",
"@types/node": "^18.6.1",
"cypress": "^10.3.1",
"cypress": "^12.15.0",
"env-cmd": "^10.1.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-cypress": "^2.12.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const NeurostoreSearch: React.FC<IImportArgs> = (props) => {
data-tour={index === 0 ? 'StudiesPage-4' : null}
sx={NeurosynthTableStyles.tableRow}
key={studyrow.id || index}
onClick={() => history.push(`/studies/${studyrow.id}`)}
onClick={() => history.push(`/base-studies/${studyrow.id}`)}
>
<TableCell>
{studyrow?.name || (
Expand All @@ -207,10 +207,7 @@ const NeurostoreSearch: React.FC<IImportArgs> = (props) => {
<Box sx={{ color: 'warning.dark' }}>No Journal</Box>
)}
</TableCell>
<TableCell>
{(studyrow?.user === user?.sub ? 'Me' : studyrow?.user) ||
'Neurosynth-Compose'}
</TableCell>
<TableCell>{studyrow?.username || 'Neurosynth-Compose'}</TableCell>
</TableRow>
))}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@ import { DetailedSettings as MergeCellsSettings } from 'handsontable/plugins/mer
import { ColumnSettings } from 'handsontable/settings';
import { useGetAnnotationById, useUpdateAnnotationById } from 'hooks';
import { NoteCollectionReturn } from 'neurostore-typescript-sdk';
import {
useInitProjectStoreIfRequired,
useProjectExtractionAnnotationId,
} from 'pages/Projects/ProjectPage/ProjectStore';
import { useInitStudyStoreIfRequired } from 'pages/Studies/StudyStore';
import { useCallback, useEffect, useRef, useState } from 'react';
import AnnotationsHotTable from './AnnotationsHotTable/AnnotationsHotTable';
import {
Expand All @@ -21,17 +16,24 @@ import {
noteKeyArrToObj,
noteKeyObjToArr,
} from './helpers/utils';
import { useAuth0 } from '@auth0/auth0-react';
import { useSnackbar } from 'notistack';

const hardCodedColumns = ['Study', 'Analysis'];

const EditAnnotations: React.FC = (props) => {
const annotationId = useProjectExtractionAnnotationId();

useInitProjectStoreIfRequired();
useInitStudyStoreIfRequired();
const EditAnnotations: React.FC<{ annotationId: string }> = (props) => {
const { user } = useAuth0();
const { enqueueSnackbar } = useSnackbar();
const { mutate, isLoading: updateAnnotationIsLoading } = useUpdateAnnotationById(
props.annotationId
);
const {
data,
isLoading: getAnnotationIsLoading,
isError,
} = useGetAnnotationById(props.annotationId);

const { mutate, isLoading: updateAnnotationIsLoading } = useUpdateAnnotationById(annotationId);
const { data, isLoading: getAnnotationIsLoading, isError } = useGetAnnotationById(annotationId);
const theLoggedInUserOwnsThisAnnotation = (user?.sub || null) === (data?.user || undefined);

// tracks the changes made to hot table
const hotTableDataUpdatesRef = useRef<{
Expand Down Expand Up @@ -90,7 +92,13 @@ const EditAnnotations: React.FC = (props) => {
}, [data]);

const handleClickSave = () => {
if (!annotationId) return;
if (!props.annotationId) return;
if (!theLoggedInUserOwnsThisAnnotation) {
enqueueSnackbar('You do not have permission to edit this annotation', {
variant: 'error',
});
return;
}

const { hotData, noteKeys } = hotTableDataUpdatesRef.current;

Expand All @@ -103,7 +111,7 @@ const EditAnnotations: React.FC = (props) => {

mutate(
{
argAnnotationId: annotationId,
argAnnotationId: props.annotationId,
annotation: {
notes: updatedAnnotationNotes.map((annotationNote) => ({
note: annotationNote.note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const NavDrawer: React.FC<INav> = (props) => {
<DrawerToggleMenu labelText="EXPLORE">
<List>
<ListItem>
<ListItemButton onClick={() => history.push('/studies')}>
<ListItemButton onClick={() => history.push('/base-studies')}>
<ListItemIcon />
<ListItemText primary="studies" />
</ListItemButton>
Expand Down
Loading

0 comments on commit ebba545

Please sign in to comment.