From caea5d23b0e55c24e2fa24f3f5b867188a08c92d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anne=20L=27H=C3=B4te?= Date: Fri, 13 Dec 2024 12:05:31 +0100 Subject: [PATCH] feat(openalex): Display spinner while computing data --- .../openalex-affiliations/results/index.jsx | 26 ++- .../results/list-view.jsx | 200 +++++++++--------- client/src/utils/works.jsx | 2 + 3 files changed, 112 insertions(+), 116 deletions(-) diff --git a/client/src/pages/openalex-affiliations/results/index.jsx b/client/src/pages/openalex-affiliations/results/index.jsx index 93dca6b..d51a6f9 100644 --- a/client/src/pages/openalex-affiliations/results/index.jsx +++ b/client/src/pages/openalex-affiliations/results/index.jsx @@ -40,7 +40,7 @@ export default function Affiliations() { const [searchParams] = useSearchParams(); const { toast } = useToast(); - const [addList, setAddList] = useState([]); + const [addList, setAddList] = useState([]); // TODO: still used ? const [affiliations, setAffiliations] = useState([]); const [body, setBody] = useState({}); const [cleanRor, setCleanRor] = useState(''); @@ -731,16 +731,20 @@ export default function Affiliations() { /> - + {filteredAffiliations.length === 0 ? ( + // TODO replace spinner by skeleton + ) : ( + + )} diff --git a/client/src/pages/openalex-affiliations/results/list-view.jsx b/client/src/pages/openalex-affiliations/results/list-view.jsx index bb24424..10d76de 100644 --- a/client/src/pages/openalex-affiliations/results/list-view.jsx +++ b/client/src/pages/openalex-affiliations/results/list-view.jsx @@ -5,7 +5,6 @@ import { Col, Modal, ModalContent, ModalFooter, ModalTitle, Row, - Spinner, Text, } from '@dataesr/dsfr-plus'; import { Steps } from 'intro.js-react'; @@ -36,9 +35,9 @@ export default function ListView({ const [selectShowAffiliations, setSelectShowAffiliations] = useState('all'); const [selectRorCountry, setSelectRorCountry] = useState('all'); const [sortsAndFilters, setSortsAndFilters] = useState({ - sortOnNumberOfRors: 'default', - showAffiliations: 'all', rorCountry: 'all', + showAffiliations: 'all', + sortOnNumberOfRors: 'default', }); const [sortedOrFilteredAffiliations, setSortedOrFilteredAffiliations] = useState(filteredAffiliations); @@ -113,17 +112,14 @@ export default function ListView({ } else if (sortsAndFilters.sortOnNumberOfRors === 'empty') { initialAffiliations = initialAffiliations.filter((affiliation) => affiliation.rors.length === 0); } - if (sortsAndFilters.showAffiliations === 'onlyWithCorrections') { initialAffiliations = initialAffiliations.filter((affiliation) => affiliation.addList.length > 0 || affiliation.removeList.length > 0); } else if (sortsAndFilters.showAffiliations === 'onlyWithNoCorrection') { initialAffiliations = initialAffiliations.filter((affiliation) => affiliation.addList.length === 0 && affiliation.removeList.length === 0); } - if (sortsAndFilters.rorCountry !== 'all') { initialAffiliations = initialAffiliations.filter((affiliation) => affiliation.rors.some((ror) => ror.rorCountry === sortsAndFilters.rorCountry)); } - setSortedOrFilteredAffiliations(initialAffiliations); setIsLoading(false); }, [filteredAffiliations, sortsAndFilters]); @@ -145,9 +141,7 @@ export default function ListView({ !affiliation.selected) === undefined} - onChange={() => { - setSelectAffiliations(sortedOrFilteredAffiliations.map((affiliation) => affiliation.id)); - }} + onChange={() => setSelectAffiliations(sortedOrFilteredAffiliations.map((affiliation) => affiliation.id))} /> @@ -221,9 +215,9 @@ export default function ListView({ aria-label="Open colors info modal" className="step-affiliations-colors" color="beige-gris-galet" + icon="palette-fill" onClick={() => setIsColorInfoModalOpen((prev) => !prev)} size="sm" - icon="palette-fill" /> setIsColorInfoModalOpen((prev) => !prev)} size="md"> @@ -283,98 +277,94 @@ export default function ListView({ - {isLoading ? ( - - ) : ( -
-
    - { - sortedOrFilteredAffiliations.map((affiliation, index) => ( -
  • - - -
    -
    - setSelectAffiliations([affiliation.id])} - /> -
    - { - (affiliation.hasCorrection) && ( - - ) - } -
    -
    - setSelectAffiliations([affiliation.id])} - style={{ cursor: 'pointer' }} - > -
    - - -
    +
    +
      + { + sortedOrFilteredAffiliations.map((affiliation, index) => ( +
    • + + +
      +
      + setSelectAffiliations([affiliation.id])} + /> +
      + { + (affiliation.hasCorrection) && ( + + ) + }
      - - - - - {affiliation.rorsToCorrect.map((rorToCorrect) => ( - - - - ))} - {affiliation.addList.map((ror) => ( - - - - ))} - -
      - toggleRemovedRor(affiliation.id, rorToCorrect.rorId)} - ror={rorToCorrect} - rorColor={defineRorColor.find((item) => item.ror === rorToCorrect.rorId)?.color || 'beige-gris-galet'} - setFilteredAffiliationName={setFilteredAffiliationName} - /> -
      - -
      - removeRorFromAddList(affiliation.id, ror.rorId)} - ror={ror} - rorColor={defineRorColor.find((item) => item.ror === ror.rorId)?.color || 'beige-gris-galet'} - setFilteredAffiliationName={setFilteredAffiliationName} - /> -
      - - - Added - -
      - - -
    • - )) - } -
    -
    - )} +
    + setSelectAffiliations([affiliation.id])} + style={{ cursor: 'pointer' }} + > +
    + + +
    +
    + + + + + {affiliation.rorsToCorrect.map((rorToCorrect) => ( + + + + ))} + {affiliation.addList.map((ror) => ( + + + + ))} + +
    + toggleRemovedRor(affiliation.id, rorToCorrect.rorId)} + ror={rorToCorrect} + rorColor={defineRorColor.find((item) => item.ror === rorToCorrect.rorId)?.color || 'beige-gris-galet'} + setFilteredAffiliationName={setFilteredAffiliationName} + /> +
    + +
    + removeRorFromAddList(affiliation.id, ror.rorId)} + ror={ror} + rorColor={defineRorColor.find((item) => item.ror === ror.rorId)?.color || 'beige-gris-galet'} + setFilteredAffiliationName={setFilteredAffiliationName} + /> +
    + + + Added + +
    + + +
  • + )) + } +
+
setIsModalOpen((prev) => !prev)} size="md"> Sorts & filters @@ -447,9 +437,9 @@ export default function ListView({