From 8fb64881c2cf3893a39618eff59bd875d27012f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Thu, 2 Jan 2025 14:55:03 +0100 Subject: [PATCH] feat(openalex): Display corrections --- .../openalex-affiliations/corrections.jsx | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/client/src/pages/openalex-affiliations/corrections.jsx b/client/src/pages/openalex-affiliations/corrections.jsx index 52695be..4c31d0e 100644 --- a/client/src/pages/openalex-affiliations/corrections.jsx +++ b/client/src/pages/openalex-affiliations/corrections.jsx @@ -12,22 +12,22 @@ const TOP_CONTRIBUTORS_LIMIT = 10; export default function Corrections() { // const [filter, setFilter] = useState([]); - // const [issues, setIssues] = useState([]); - const [chartOptions1, setChartOptions1] = useState(); - const [chartOptions2, setChartOptions2] = useState(); + const [chartOptions1, setChartOptions1] = useState({}); + const [chartOptions2, setChartOptions2] = useState({}); + const [corrections, setCorrections] = useState([]); const getCorrections = async (state, page = 0) => { const offset = page * ODS_BY_PAGE; - let corrections = []; + let _corrections = []; const url = `${ODS_URL}/records?order_by=github_issue_id&limit=${ODS_BY_PAGE}&offset=${offset}&refine=state%3A${state}`; const response = await fetch(url); const { results } = await response.json(); - corrections = corrections.concat(results); + _corrections = _corrections.concat(results); if (results.length === ODS_BY_PAGE) { const c = await getCorrections(state, page + 1); - corrections = corrections.concat(c); + _corrections = _corrections.concat(c); } - return corrections; + return _corrections; }; const getClosedCorrections = () => getCorrections('closed'); @@ -58,7 +58,10 @@ export default function Corrections() { const queries = [getClosedCorrections(), getOpenedCorrections(), getFacets()]; const [closedCorrections, openedCorrections] = await Promise.all(queries); let data = {}; - [...closedCorrections, ...openedCorrections].forEach((correction) => { + const correctionsTmp = [...closedCorrections, ...openedCorrections]; + correctionsTmp.reverse((a, b) => b.date_opened - a.date_opened); + setCorrections(correctionsTmp); + correctionsTmp.forEach((correction) => { const dateOpened = correction?.date_opened?.slice(0, 7); const dateClosed = correction?.date_closed?.slice(0, 7); if (dateOpened) { @@ -130,6 +133,17 @@ export default function Corrections() { )} + {!isFetching && isFetched && corrections && ( +
+ + {corrections.length} + {' '} + corrections + + {' '} + requested until last night +
+ )} {!isFetching && isFetched && chartOptions1 && ( )} - - {/* - {!isFetching && isFetched && ( + {!isFetching && isFetched && (corrections.length > 0) && ( <> - setFilter(e.target.value)} style={{ border: '1px solid #ced4da', @@ -156,36 +168,35 @@ export default function Corrections() { backgroundColor: 'white', }} value={filter} - /> + /> */} )} - */} );