Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/npm_and_yarn/compose/neurosynth…
Browse files Browse the repository at this point in the history
…-frontend/fast-xml-parser-4.4.1
  • Loading branch information
nicoalee committed Sep 9, 2024
2 parents 1d55069 + 03aeb60 commit f6bd11c
Show file tree
Hide file tree
Showing 20 changed files with 414 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ describe('DoSleuthImport', () => {
beforeEach(() => {
cy.clearLocalStorage().clearSessionStorage();
cy.intercept('GET', 'https://api.appzi.io/**', { fixture: 'appzi' }).as('appziFixture');

cy.intercept('POST', `https://www.google-analytics.com/*/**`, {}).as(
'googleAnalyticsFixture'
);
});

it('should load successfully', () => {
Expand Down Expand Up @@ -429,7 +433,7 @@ describe('DoSleuthImport', () => {
});

describe('edge cases', () => {
it('should apply the pubmed details to the study if a matching pubmed study is found', () => {
it.only('should apply the pubmed details to the study if a matching pubmed study is found', () => {
// this stuff exists just to make sure cypress doesnt send any real requests. They are not under test
// synth API responses
cy.intercept('POST', `${neurostoreAPIBaseURL}/analyses/**`, {
Expand Down Expand Up @@ -486,6 +490,7 @@ describe('DoSleuthImport', () => {
fixture: 'DoSleuthImport/pubmedResponses/efetchSingleResponse.xml',
}).as('pmidsFetch');

// this is not important but is needed to finish the rest of the import
cy.intercept('POST', `${neurostoreAPIBaseURL}/base-studies/**`, {
fixture:
'DoSleuthImport/neurosynthResponses/baseStudiesMultipleSleuthStudyResponse.json',
Expand All @@ -501,12 +506,18 @@ describe('DoSleuthImport', () => {

cy.wait('@baseStudiesIngestFixture').then((baseStudiesResponse) => {
const baseStudy = baseStudiesResponse.request.body[0];

// we should still have all the data from the original base study created from the sleuth import file
expect(baseStudy.authors).equals('Gerardin E,');
expect(baseStudy.doi).equals('some-doi.org');
expect(baseStudy.name).equals('The brains default mode network.');
expect(baseStudy.year).equals(2000);
expect(baseStudy.pmid).equals('25938726');
expect(baseStudy.publication).equals('Annual review of neuroscience');
// additional data should be added from the pubmed query if it did not exist
expect(baseStudy.pmcid).equals('PMCTEST');
expect(baseStudy.description).equals(
`\nThe brains default mode network consists of discrete, bilateral and symmetrical cortical areas, in the medial and lateral parietal, medial prefrontal, and medial and lateral temporal cortices of the human, nonhuman primate, cat, and rodent brains. Its discovery was an unexpected consequence of brain-imaging studies first performed with positron emission tomography in which various novel, attention-demanding, and non-self-referential tasks were compared with quiet repose either with eyes closed or with simple visual fixation. The default mode network consistently decreases its activity when compared with activity during these relaxed nontask states. The discovery of the default mode network reignited a longstanding interest in the significance of the brain's ongoing or intrinsic activity. Presently, studies of the brain's intrinsic activity, popularly referred to as resting-state studies, have come to play a major role in studies of the human brain in health and disease. The brain's default mode network plays a central role in this work.`
);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<PublicationStatus>ppublish</PublicationStatus>
<ArticleIdList>
<ArticleId IdType="pubmed">25938726</ArticleId>
<ArticleId IdType="pmc">PMCTEST</ArticleId>
<ArticleId IdType="doi">some-doi.org</ArticleId>
</ArticleIdList>
</PubmedData>
Expand Down
66 changes: 66 additions & 0 deletions compose/neurosynth-frontend/package-lock.json

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

1 change: 1 addition & 0 deletions compose/neurosynth-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
"@testing-library/dom": "^8.3.0",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^11.2.7",
"@testing-library/react-hooks": "^8.0.1",
"@testing-library/user-event": "^12.8.3",
"@types/node": "^18.6.1",
"cypress": "^13.2.0",
Expand Down
21 changes: 11 additions & 10 deletions compose/neurosynth-frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,25 @@
href="https://fonts.googleapis.com/css2?family=Roboto:wght@300&display=swap"
crossorigin="anonymous"
/>

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-0L9Y0HT9NR"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-0L9Y0HT9NR');
<script type="text/javascript">
if (document.location.hostname === "compose.neurosynth.org") {
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-0L9Y0HT9NR');
}
</script>

<!-- Appzi: Capture Insightful Feedback -->
<script async src="https://w.appzi.io/w.js?token=jFjBf">
window.appziSettings = {
render: { type: 'client' }
}
</script>

<!-- Appzi: Capture Insightful Feedback -->

<script async src="https://w.appzi.io/w.js?token=jFjBf"></script>

<!-- End Appzi -->

<!--
Expand Down
26 changes: 25 additions & 1 deletion compose/neurosynth-frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import Close from '@mui/icons-material/Close';
import { IconButton } from '@mui/material';
import { AxiosError } from 'axios';
import useGoogleAnalytics from 'hooks/useGoogleAnalytics';
import { SnackbarKey, SnackbarProvider } from 'notistack';
import { useRef } from 'react';
import { useEffect, useRef } from 'react';
import { QueryCache, QueryClient, QueryClientProvider } from 'react-query';
import Navbar from './components/Navbar/Navbar';
import useGetToken from './hooks/useGetToken';
import BaseNavigation from './pages/BaseNavigation/BaseNavigation';
import { useLocation } from 'react-router-dom';
import Downbanner from 'components/Downbanner';

const queryClient = new QueryClient({
defaultOptions: {
Expand All @@ -26,9 +29,29 @@ const queryClient = new QueryClient({
}),
});

declare global {
interface Window {
gtag?: (
type: 'event' | 'config' | 'get' | 'set' | 'consent',
action: 'login' | 'page_view',
options?: any
) => void;
}
}

function App() {
const notistackRef = useRef<SnackbarProvider>(null);
useGetToken();
useGoogleAnalytics();

const location = useLocation();
useEffect(() => {
if (window.gtag) {
window.gtag('event', 'page_view', {
page_path: `${location.pathname}${location.search}`,
});
}
}, [location]);

const handleCloseSnackbar = (key: SnackbarKey) => (_event: React.MouseEvent) => {
if (notistackRef?.current?.closeSnackbar) notistackRef.current?.closeSnackbar(key);
Expand All @@ -45,6 +68,7 @@ function App() {
</IconButton>
)}
>
<Downbanner />
<Navbar />
<BaseNavigation />
</SnackbarProvider>
Expand Down
52 changes: 52 additions & 0 deletions compose/neurosynth-frontend/src/components/Downbanner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { Cancel } from '@mui/icons-material';
import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline';
import { Box, IconButton } from '@mui/material';
import BaseNavigationStyles from 'pages/BaseNavigation/BaseNavigation.styles';
import { useState } from 'react';

const Downbanner: React.FC = () => {
const shouldHide = !!localStorage.getItem('hide-dwonbanner');
const [hideBanner, setHideBanner] = useState(shouldHide);

if (hideBanner) return <></>;

return (
<Box
sx={{
backgroundColor: 'secondary.main',
color: 'primary.contrastText',
width: '100%',
paddingY: '0.5rem',
}}
>
<Box
sx={[
BaseNavigationStyles.pagesContainer,
{
marginY: '0',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
},
]}
>
<Box display="flex" alignItems="center">
<ErrorOutlineIcon sx={{ mr: '1rem' }} />
Neurosynth-compose will be undergoing planned maintenance and will be offline on
friday (Sep/06/2024)
</Box>
<IconButton
onClick={() => {
localStorage.setItem('hide-dwonbanner', 'true');
setHideBanner(true);
}}
sx={{ padding: 0, ':hover': { backgroundColor: 'secondary.light' } }}
>
<Cancel />
</IconButton>
</Box>
</Box>
);
};

export default Downbanner;
5 changes: 5 additions & 0 deletions compose/neurosynth-frontend/src/components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const Navbar: React.FC = (_props) => {
audience: AUTH0_AUDIENCE,
scope: 'openid profile email offline_access',
});

if (window.gtag) {
window.gtag('event', 'login');
}

navigate('/');
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { stringToNumber } from 'helpers/utils';
import { ICurationStubStudy } from 'pages/Curation/Curation.types';
import { useMutation } from 'react-query';

/**
* I'll leave this file here for now because it may be useful later and I worked hard on it
*/

const stringAsAuthorArray = (authors: string): IBibtex['author'] => {
const authorsStringToArray = authors.split(', ').map((author) => {
const nameAsArray = author.split(' ');
Expand Down
30 changes: 30 additions & 0 deletions compose/neurosynth-frontend/src/hooks/useGoogleAnalytics.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { routeMapping } from './useGoogleAnalytics';

describe('useGoogleAnalytics', () => {
test.each`
path | expected
${'/projects/g7VRaCLw3iZJ/curation'} | ${'curation page'}
${'/projects/g7VRaCLw3iZJ/curation/import'} | ${'curation import page'}
${'/projects/g7VRaCLw3iZJ/curation/import?pageOfResults=2'} | ${'curation import page'}
${'/projects/g7VRaCLw3iZJ/extraction'} | ${'extraction page'}
${'/projects/g7VRaCLw3iZJ/extraction/annotations'} | ${'annotations page'}
${'/projects'} | ${'projects page'}
${'/projects/g7VRaCLw3iZJ/project'} | ${'project page'}
${'/projects/6zW6TJtzpFjr/meta-analyses'} | ${'project meta-analyses page'}
${'/projects/98ZZj2vbpySw/meta-analyses/8K6KhGEfTy6H'} | ${'project meta-analysis page'}
${'/projects/new/sleuth'} | ${'sleuth import page'}
${'/base-studies'} | ${'base-studies page'}
${'/meta-analyses'} | ${'meta-analyses page'}
${'/meta-analyses/BdCib6uM3QDX'} | ${'meta-analysis page'}
${'/base-studies/FSfE96JVaPuU/5neCyoMwEvrM'} | ${'base-study page'}
${'/base-studies/FSfE96JVaPuU'} | ${'base-study page'}
${'/projects/g7VRaCLw3iZJ/extraction/studies/v7RBrDFEbAC7/edit'} | ${'edit project study page'}
${'/projects/g7VRaCLw3iZJ/extraction/studies/v7RBrDFEbAC7'} | ${'project study page'}
${'/user-profile'} | ${'user profile page'}
${'/forbidden'} | ${'forbidden page'}
${'/termsandconditions'} | ${'terms and conditions page'}
${'/not-found'} | ${'not found page'}
`('transforms $path to $expected', ({ path, expected }) => {
expect(routeMapping(path)).toEqual(expected);
});
});
Loading

0 comments on commit f6bd11c

Please sign in to comment.