From fffb872b281730b77e2d1a83cb499df3cbd98a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Sun, 22 Oct 2023 16:51:10 -0700 Subject: [PATCH] feat(ui): Filter on datasources --- client/src/pages/home/filters.jsx | 27 ----------- client/src/pages/home/index.jsx | 67 +++++++++++++++++++-------- client/src/pages/home/views/works.jsx | 3 +- client/src/utils/templates.jsx | 19 ++------ 4 files changed, 52 insertions(+), 64 deletions(-) diff --git a/client/src/pages/home/filters.jsx b/client/src/pages/home/filters.jsx index 54448dc8..1e261fbb 100644 --- a/client/src/pages/home/filters.jsx +++ b/client/src/pages/home/filters.jsx @@ -43,15 +43,6 @@ export default function Filters({ sendQuery }) { } }, [searchParams, setSearchParams]); - const onDatasourcesChange = (key) => { - const { datasources } = currentSearchParams; - if (datasources.includes(key)) { - setSearchParams({ ...currentSearchParams, datasources: datasources.filter((datasource) => datasource !== key) }); - } else { - setSearchParams({ ...currentSearchParams, datasources: [...datasources, key] }); - } - }; - const onIdentifiersChange = (label) => { const { dataIdentifiers } = currentSearchParams; if (dataIdentifiers.includes(label)) { @@ -74,8 +65,6 @@ export default function Filters({ sendQuery }) { sendQuery(currentSearchParams); }; - const checkSource = (source) => (currentSearchParams?.datasources ?? []).includes(source); - return ( <> @@ -88,22 +77,6 @@ export default function Filters({ sendQuery }) { onInputHandler={setOnInputAffiliationsHandler} /> - - Datasources - - { - sources.map((source) => ( - onDatasourcesChange(source.key)} - size="sm" - /> - )) - } - - diff --git a/client/src/pages/home/index.jsx b/client/src/pages/home/index.jsx index 0f591628..cc361d0e 100644 --- a/client/src/pages/home/index.jsx +++ b/client/src/pages/home/index.jsx @@ -2,7 +2,7 @@ /* eslint-disable indent */ /* eslint-disable jsx-a11y/control-has-associated-label */ /* eslint-disable no-case-declarations */ -import { Button, Col, Container, Notice, Row, Tab, Tabs } from '@dataesr/react-dsfr'; +import { Button, Checkbox, CheckboxGroup, Col, Container, Notice, Row, Tab, Tabs } from '@dataesr/react-dsfr'; import { useQuery } from '@tanstack/react-query'; import { useEffect, useState } from 'react'; @@ -41,6 +41,7 @@ const TO_BE_DECIDED_STATUS = 'to be decided'; const VALIDATED_STATUS = 'validated'; const EXCLUDED_STATUS = 'excluded'; const REGEXP_ROR = /^(https:\/\/ror\.org\/|ror\.org\/){0,1}0[a-hj-km-np-tv-z|0-9]{6}[0-9]{2}$/; +const DATASOURCES = [{ key: 'bso', label: 'French OSM' }, { key: 'openalex', label: 'OpenAlex' }]; const getRorAffiliations = (affiliations) => { const notRorAffiliations = []; @@ -104,6 +105,7 @@ export default function Home() { const [allAffiliations, setAllAffiliations] = useState([]); const [allDatasets, setAllDatasets] = useState([]); const [allPublications, setAllPublications] = useState([]); + const [filteredDatasources, setFilteredDatasources] = useState(DATASOURCES.map((datasource) => datasource.key)); const [isLoading, setIsLoading] = useState(false); const [options, setOptions] = useState({}); const [regexp, setRegexp] = useState(); @@ -200,16 +202,18 @@ export default function Home() { let allDatasetsTmp = []; let allPublicationsTmp = []; if (data) { - allDatasetsTmp = data.datasets.map((dataset) => ({ - ...dataset, - affiliationsHtml: getAffiliationsHtmlField(dataset, regexp), - affiliationsSearch: getAffiliationsSearchField(dataset), - allIdsHtml: getAllIdsHtmlField(dataset), - authorsHtml: getAuthorsHtmlField(dataset), - authorsTooltip: getAuthorsTooltipField(dataset), - status: TO_BE_DECIDED_STATUS, - })); + allDatasetsTmp = data.datasets + .map((dataset) => ({ + ...dataset, + affiliationsHtml: getAffiliationsHtmlField(dataset, regexp), + affiliationsSearch: getAffiliationsSearchField(dataset), + allIdsHtml: getAllIdsHtmlField(dataset), + authorsHtml: getAuthorsHtmlField(dataset), + authorsTooltip: getAuthorsTooltipField(dataset), + status: TO_BE_DECIDED_STATUS, + })); allPublicationsTmp = data.publications + .filter((publication) => filteredDatasources.includes(publication.datasource)) .map((publication) => ({ ...publication, affiliationsHtml: getAffiliationsHtmlField(publication, regexp), @@ -222,12 +226,12 @@ export default function Home() { } setAllDatasets(allDatasetsTmp); setAllPublications(allPublicationsTmp); - }, [data, regexp]); + }, [data, filteredDatasources, regexp]); useEffect(() => { groupByAffiliations(allPublications, regexp); // eslint-disable-next-line react-hooks/exhaustive-deps - }, [allPublications]); + }, [allPublications, regexp]); const tagPublications = (publications, action) => { const allPublicationsTmp = [...allPublications]; @@ -250,6 +254,7 @@ export default function Home() { setAllAffiliations(allAffiliationsTmp); setSelectedAffiliations([]); }; + const renderAffiliationsButtons = () => ( <>