Skip to content

Commit

Permalink
feat(all): Use var env to set default start year and end year on ever…
Browse files Browse the repository at this point in the history
…y screen
  • Loading branch information
annelhote committed Feb 10, 2025
1 parent 25bf174 commit 5e298b7
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 49 deletions.
6 changes: 4 additions & 2 deletions client/.env
Original file line number Diff line number Diff line change
@@ -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<br>chargé<br>de l'enseignement<br>supérieur<br>et de la recherche"
VITE_MINISTER_NAME=Ministère<br>chargé<br>de l'enseignement<br>supérieur<br>et de la recherche
VITE_VERSION=$npm_package_version
VITE_WS_HOST=wss://works-magnet.esr.gouv.fr
4 changes: 3 additions & 1 deletion client/src/pages/datasets/datasetsYearlyDistribution.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions client/src/pages/datasets/results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [];
Expand Down
18 changes: 8 additions & 10 deletions client/src/pages/datasets/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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([]);
Expand All @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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,
}));
Expand Down
6 changes: 3 additions & 3 deletions client/src/pages/openalex-affiliations/results/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [];
Expand Down
18 changes: 8 additions & 10 deletions client/src/pages/openalex-affiliations/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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 {
Expand All @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions client/src/pages/publications/results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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 = [];
Expand Down
18 changes: 8 additions & 10 deletions client/src/pages/publications/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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([]);
Expand All @@ -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),
Expand Down

0 comments on commit 5e298b7

Please sign in to comment.