Skip to content

Commit

Permalink
fix(ui): Restore sources facet
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 9, 2023
1 parent d1cedb6 commit 966b445
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const {
VITE_BSO_PUBLICATIONS_INDEX,
} = import.meta.env;

const DATASOURCES = [{ key: 'bso', label: 'French OSM' }, { key: 'openalex', label: 'OpenAlex' }];

const getData = async (options) => {
const promises1 = [getBsoWorks({ options, index: VITE_BSO_PUBLICATIONS_INDEX }), getOpenAlexPublications(options)];
const publications = await Promise.all(promises1.flat());
Expand Down Expand Up @@ -78,6 +80,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 [filteredPublications, setFilteredPublications] = useState([]);
const [filteredStatus, setFilteredStatus] = useState(Object.keys(status));
const [filteredYears, setFilteredYears] = useState([]);
Expand Down Expand Up @@ -207,9 +210,9 @@ export default function Home() {
}, [data, regexp]);

useEffect(() => {
const filteredPublicationsTmp = allPublications.filter((publication) => filteredStatus.includes(publication.status) && filteredYears.includes(publication.year));
const filteredPublicationsTmp = allPublications.filter((publication) => filteredDatasources.includes(publication.datasource) && filteredStatus.includes(publication.status) && filteredYears.includes(publication.year));
setFilteredPublications(filteredPublicationsTmp);
}, [allPublications, filteredStatus, filteredYears]);
}, [allPublications, filteredDatasources, filteredStatus, filteredYears]);

useEffect(() => {
groupByAffiliations();
Expand Down Expand Up @@ -266,6 +269,14 @@ export default function Home() {
</>
);

const onDatasourcesChange = (datasource) => {
if (filteredDatasources.includes(datasource.key)) {
setFilteredDatasources(filteredDatasources.filter((filteredDatasource) => filteredDatasource !== datasource.key));
} else {
setFilteredDatasources(filteredDatasources.concat([datasource.key]));
}
};

const onStatusChange = (st) => {
if (filteredStatus.includes(st)) {
setFilteredStatus(filteredStatus.filter((filteredSt) => filteredSt !== st));
Expand Down Expand Up @@ -383,6 +394,20 @@ export default function Home() {
/>
))}
</CheckboxGroup>
<CheckboxGroup
hint="Filter results on selected datasources"
legend="Source"
>
{DATASOURCES.map((datasource) => (
<Checkbox
checked={filteredDatasources.includes(datasource.key)}
key={datasource.key}
label={datasource.label}
onChange={() => onDatasourcesChange(datasource)}
size="sm"
/>
))}
</CheckboxGroup>
<CheckboxGroup
hint="Filter results on selected years"
legend="Years"
Expand Down

0 comments on commit 966b445

Please sign in to comment.