From 5e298b78a2ba22f3e09090a3608c1bfe23b1af48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Mon, 10 Feb 2025 18:40:35 +0100 Subject: [PATCH] feat(all): Use var env to set default start year and end year on every screen --- client/.env | 6 ++++-- .../datasets/datasetsYearlyDistribution.jsx | 4 +++- client/src/pages/datasets/results.jsx | 8 +++----- client/src/pages/datasets/search.jsx | 18 ++++++++---------- .../components/send-feedback-button.jsx | 6 +++--- .../openalex-affiliations/results/index.jsx | 6 +++--- .../src/pages/openalex-affiliations/search.jsx | 18 ++++++++---------- client/src/pages/publications/results.jsx | 8 +++----- client/src/pages/publications/search.jsx | 18 ++++++++---------- 9 files changed, 43 insertions(+), 49 deletions(-) diff --git a/client/.env b/client/.env index b98bb545..217e5b1d 100644 --- a/client/.env +++ b/client/.env @@ -1,10 +1,12 @@ VITE_API=/api +VITE_APP_DEFAULT_YEAR=2024 VITE_APP_MATOMO_BASE_URL=https://piwik.enseignementsup-recherche.pro -VITE_APP_NAME="Works-magnet 🧲" +VITE_APP_NAME=Works-magnet 🧲 +VITE_APP_START_YEAR=2010 VITE_APP_TAG_LIMIT=3 VITE_GIT_REPOSITORY_URL=https://github.com/dataesr/works-magnet VITE_HEADER_TAG= VITE_HEADER_TAG_COLOR=new -VITE_MINISTER_NAME="Ministère
chargé
de l'enseignement
supérieur
et de la recherche" +VITE_MINISTER_NAME=Ministère
chargé
de l'enseignement
supérieur
et de la recherche VITE_VERSION=$npm_package_version VITE_WS_HOST=wss://works-magnet.esr.gouv.fr diff --git a/client/src/pages/datasets/datasetsYearlyDistribution.jsx b/client/src/pages/datasets/datasetsYearlyDistribution.jsx index 65e79604..df052f01 100644 --- a/client/src/pages/datasets/datasetsYearlyDistribution.jsx +++ b/client/src/pages/datasets/datasetsYearlyDistribution.jsx @@ -9,10 +9,12 @@ import { useSearchParams } from 'react-router-dom'; import { range } from '../../utils/works'; +const { VITE_APP_DEFAULT_YEAR } = import.meta.env; + export default function DatasetsYearlyDistribution({ allDatasets, field, subfield = undefined }) { const [searchParams] = useSearchParams(); - const categories = range(searchParams.get('startYear', 2023), searchParams.get('endYear', 2023)); + const categories = range(searchParams.get('startYear', VITE_APP_DEFAULT_YEAR), searchParams.get('endYear', VITE_APP_DEFAULT_YEAR)); const allFields = {}; allDatasets.filter((dataset) => dataset.status === 'validated').forEach((dataset) => { const publicationYear = dataset?.year; diff --git a/client/src/pages/datasets/results.jsx b/client/src/pages/datasets/results.jsx index 39bdca1e..504cc926 100644 --- a/client/src/pages/datasets/results.jsx +++ b/client/src/pages/datasets/results.jsx @@ -14,9 +14,7 @@ import Datasets from '../views/datasets'; import 'primereact/resources/primereact.min.css'; import 'primereact/resources/themes/lara-light-indigo/theme.css'; -const { VITE_APP_TAG_LIMIT } = import.meta.env; - -const DEFAULT_YEAR = '2024'; +const { VITE_APP_DEFAULT_YEAR, VITE_APP_TAG_LIMIT } = import.meta.env; export default function Affiliations() { const [searchParams] = useSearchParams(); @@ -69,8 +67,8 @@ export default function Affiliations() { useEffect(() => { const getData = async () => { const queryParams = { - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }; queryParams.affiliationStrings = []; queryParams.deletedAffiliations = []; diff --git a/client/src/pages/datasets/search.jsx b/client/src/pages/datasets/search.jsx index db07e174..0915d5f1 100644 --- a/client/src/pages/datasets/search.jsx +++ b/client/src/pages/datasets/search.jsx @@ -17,14 +17,12 @@ import TagInput from '../../components/tag-input'; import Header from '../../layout/header'; import { cleanRor, getRorData, isRor } from '../../utils/ror'; -const { VITE_APP_TAG_LIMIT } = import.meta.env; +const { VITE_APP_DEFAULT_YEAR, VITE_APP_START_YEAR, VITE_APP_TAG_LIMIT } = import.meta.env; -const START_YEAR = 2010; -const DEFAULT_YEAR = '2024'; -// Generate an array of objects with all years from START_YEAR -const years = [...Array(new Date().getFullYear() - START_YEAR + 1).keys()] +// Generate an array of objects with all years from VITE_APP_START_YEAR +const years = [...Array(new Date().getFullYear() - Number(VITE_APP_START_YEAR) + 1).keys()] .sort((a, b) => b - a) - .map((year) => (year + START_YEAR).toString()) + .map((year) => (year + Number(VITE_APP_START_YEAR)).toString()) .map((year) => ({ label: year, value: year })); export default function DatasetsSearch() { @@ -51,9 +49,9 @@ export default function DatasetsSearch() { const searchParamsTmp = { affiliations: searchParams.getAll('affiliations') ?? [], deletedAffiliations: searchParams.getAll('deletedAffiliations') ?? [], - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, getRorChildren: searchParams.get('getRorChildren') ?? '0', - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }; setSearchParams(searchParamsTmp); setTags([]); @@ -64,9 +62,9 @@ export default function DatasetsSearch() { setCurrentSearchParams({ affiliations, deletedAffiliations: deletedAffiliations1, - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, getRorChildren: searchParams.get('getRorChildren') ?? '0', - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }); const newSearchedAffiliations = affiliations.filter( (affiliation) => !searchedAffiliations.includes(affiliation), diff --git a/client/src/pages/openalex-affiliations/components/send-feedback-button.jsx b/client/src/pages/openalex-affiliations/components/send-feedback-button.jsx index 2e7dc894..137d4e8c 100644 --- a/client/src/pages/openalex-affiliations/components/send-feedback-button.jsx +++ b/client/src/pages/openalex-affiliations/components/send-feedback-button.jsx @@ -13,7 +13,7 @@ import useWebSocket from 'react-use-websocket'; import useToast from '../../../hooks/useToast'; -const { VITE_WS_HOST } = import.meta.env; +const { VITE_APP_DEFAULT_YEAR, VITE_WS_HOST } = import.meta.env; export default function SendFeedbackButton({ className, corrections, resetCorrections }) { const [searchParams] = useSearchParams(); @@ -42,11 +42,11 @@ export default function SendFeedbackButton({ className, corrections, resetCorrec const sendFeedback = async () => { try { const data = corrections.map((correction) => ({ - endYear: searchParams.get('endYear') ?? '2023', + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, name: correction.name, rors: [...correction.rors, ...correction.addList].filter((ror) => !correction.removeList.includes(ror.rorId)), rorsToCorrect: correction.rorsToCorrect, - startYear: searchParams.get('startYear') ?? '2023', + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, worksExample: correction.worksExample, worksOpenAlex: correction.worksOpenAlex, })); diff --git a/client/src/pages/openalex-affiliations/results/index.jsx b/client/src/pages/openalex-affiliations/results/index.jsx index 37e921a2..f617115f 100644 --- a/client/src/pages/openalex-affiliations/results/index.jsx +++ b/client/src/pages/openalex-affiliations/results/index.jsx @@ -34,7 +34,7 @@ import 'primereact/resources/primereact.min.css'; import 'primereact/resources/themes/lara-light-indigo/theme.css'; import '../../../styles/index.scss'; -const { VITE_APP_TAG_LIMIT } = import.meta.env; +const { VITE_APP_DEFAULT_YEAR, VITE_APP_TAG_LIMIT } = import.meta.env; export default function Affiliations() { const { pathname, search } = useLocation(); @@ -233,10 +233,10 @@ export default function Affiliations() { useEffect(() => { const getData = async () => { const queryParams = { - endYear: searchParams.get('endYear') ?? '2023', + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, excludedRors: searchParams.get('excludedRors') ?? '', getRorChildren: searchParams.get('getRorChildren') ?? '0', - startYear: searchParams.get('startYear') ?? '2023', + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }; queryParams.deletedAffiliations = []; queryParams.rorExclusions = []; diff --git a/client/src/pages/openalex-affiliations/search.jsx b/client/src/pages/openalex-affiliations/search.jsx index 2f966639..1a6342b7 100644 --- a/client/src/pages/openalex-affiliations/search.jsx +++ b/client/src/pages/openalex-affiliations/search.jsx @@ -21,14 +21,12 @@ import { cleanRor, getRorData, isRor } from '../../utils/ror'; import 'intro.js/introjs.css'; -const { VITE_APP_TAG_LIMIT } = import.meta.env; +const { VITE_APP_DEFAULT_YEAR, VITE_APP_START_YEAR, VITE_APP_TAG_LIMIT } = import.meta.env; -const START_YEAR = 2010; -const DEFAULT_YEAR = '2024'; -// Generate an array of objects with all years from START_YEAR -const years = [...Array(new Date().getFullYear() - START_YEAR + 1).keys()] +// Generate an array of objects with all years from VITE_APP_START_YEAR +const years = [...Array(new Date().getFullYear() - Number(VITE_APP_START_YEAR) + 1).keys()] .sort((a, b) => b - a) - .map((year) => (year + START_YEAR).toString()) + .map((year) => (year + Number(VITE_APP_START_YEAR)).toString()) .map((year) => ({ label: year, value: year })); export default function Search() { @@ -53,10 +51,10 @@ export default function Search() { setSearchParams({ affiliations: searchParams.getAll('affiliations') ?? [], deletedAffiliations: searchParams.getAll('deletedAffiliations') ?? [], - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, excludedRors: searchParams.get('excludedRors') ?? '', getRorChildren: searchParams.get('getRorChildren') ?? '0', - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }); setTags([]); } else { @@ -66,10 +64,10 @@ export default function Search() { setCurrentSearchParams({ affiliations, deletedAffiliations: deletedAffiliations1, - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, excludedRors: searchParams.get('excludedRors') ?? '', getRorChildren: searchParams.get('getRorChildren') ?? '0', - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }); setExcludedRors(searchParams.get('excludedRors') ?? ''); const newSearchedAffiliations = affiliations.filter( diff --git a/client/src/pages/publications/results.jsx b/client/src/pages/publications/results.jsx index e63bfae8..786d69df 100644 --- a/client/src/pages/publications/results.jsx +++ b/client/src/pages/publications/results.jsx @@ -14,9 +14,7 @@ import Publications from '../views/publications'; import 'primereact/resources/primereact.min.css'; import 'primereact/resources/themes/lara-light-indigo/theme.css'; -const { VITE_APP_TAG_LIMIT } = import.meta.env; - -const DEFAULT_YEAR = '2024'; +const { VITE_APP_DEFAULT_YEAR, VITE_APP_TAG_LIMIT } = import.meta.env; export default function Affiliations() { const [searchParams] = useSearchParams(); @@ -66,8 +64,8 @@ export default function Affiliations() { useEffect(() => { const getData = async () => { const queryParams = { - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }; queryParams.affiliationStrings = []; queryParams.deletedAffiliations = []; diff --git a/client/src/pages/publications/search.jsx b/client/src/pages/publications/search.jsx index a4350b20..6705301a 100644 --- a/client/src/pages/publications/search.jsx +++ b/client/src/pages/publications/search.jsx @@ -17,14 +17,12 @@ import TagInput from '../../components/tag-input'; import Header from '../../layout/header'; import { cleanRor, getRorData, isRor } from '../../utils/ror'; -const { VITE_APP_TAG_LIMIT } = import.meta.env; +const { VITE_APP_DEFAULT_YEAR, VITE_APP_START_YEAR, VITE_APP_TAG_LIMIT } = import.meta.env; -const START_YEAR = 2010; -const DEFAULT_YEAR = '2024'; -// Generate an array of objects with all years from START_YEAR -const years = [...Array(new Date().getFullYear() - START_YEAR + 1).keys()] +// Generate an array of objects with all years from VITE_APP_START_YEAR +const years = [...Array(new Date().getFullYear() - Number(VITE_APP_START_YEAR) + 1).keys()] .sort((a, b) => b - a) - .map((year) => (year + START_YEAR).toString()) + .map((year) => (year + Number(VITE_APP_START_YEAR)).toString()) .map((year) => ({ label: year, value: year })); export default function PublicationsSearch() { @@ -51,9 +49,9 @@ export default function PublicationsSearch() { const searchParamsTmp = { affiliations: searchParams.getAll('affiliations') ?? [], deletedAffiliations: searchParams.getAll('deletedAffiliations') ?? [], - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, getRorChildren: searchParams.get('getRorChildren') ?? '0', - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }; setSearchParams(searchParamsTmp); setTags([]); @@ -64,9 +62,9 @@ export default function PublicationsSearch() { setCurrentSearchParams({ affiliations, deletedAffiliations: deletedAffiliations1, - endYear: searchParams.get('endYear') ?? DEFAULT_YEAR, + endYear: searchParams.get('endYear') ?? VITE_APP_DEFAULT_YEAR, getRorChildren: searchParams.get('getRorChildren') ?? '0', - startYear: searchParams.get('startYear') ?? DEFAULT_YEAR, + startYear: searchParams.get('startYear') ?? VITE_APP_DEFAULT_YEAR, }); const newSearchedAffiliations = affiliations.filter( (affiliation) => !searchedAffiliations.includes(affiliation),