Skip to content

Commit

Permalink
feat(affiliations): Export / import the decided affiliations, close #22
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Nov 8, 2023
1 parent 893641d commit 7ecf6be
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Works finder

Retrieve the scholarly outputs of your institution - Based on French OSM and OpenAlex
Retrieve the scholarly works of your institution - Based on French OSM and OpenAlex

## Build for production

Expand Down
2 changes: 1 addition & 1 deletion client/.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ VITE_BSO_DATASETS_INDEX="bso3-datacite-20230413"
VITE_BSO_PUBLICATIONS_INDEX="bso-publications"
VITE_BSO_SIZE=10000
VITE_BSO_URL="https://cluster.elasticsearch.dataesr.ovh"
VITE_DESCRIPTION="Retrieve the scholarly outputs of your institution"
VITE_DESCRIPTION="Retrieve the scholarly works of your institution"
VITE_GIT_REPOSITORY_URL="https://github.com/dataesr/works-finder/"
VITE_HEADER_TAG="dev"
VITE_HEADER_TAG_COLOR="green-emeraude"
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/gauge/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ export default function Gauge({ data }) {
<div
className={item?.className ? `gauge-bar ${item.className}` : 'gauge-bar'}
data-tooltip-id={`gauge-bar-${item.id}`}
key={item.label}
key={item.id}
style={item?.color ? { width: `${item.valuePercentage}%`, backgroundColor: item.color } : { width: `${item.valuePercentage}%` }}
>
{`${item.label} (${item.value} ie. ${item.valuePercentage} %)`}
</div>
<Tooltip id={`gauge-bar-${item.id}`}>
<Tooltip id={`gauge-bar-${item.id}`} key={`tooltip-${item.id}`}>
{`${item.label} (${item.value} ie. ${item.valuePercentage} %)`}
</Tooltip>
</>
Expand Down
50 changes: 41 additions & 9 deletions client/src/pages/home/actions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,77 @@ export default function Actions({
options,
setAllAffiliations,
setAllPublications,
tagAffiliations,
}) {
const [, setSearchParams] = useSearchParams();
const [displayFileUpload, setDisplayFileUpload] = useState(false);

const decidedAffiliations = allAffiliations.filter((affiliation) => ['excluded', 'validated'].includes(affiliation.status));

return (
<>
<Row className="fr-mb-1w">
<Col className="text-right">
<Button
data-tooltip-id="save-session-button"
disabled={!allAffiliations.length || !allPublications.length}
icon="ri-save-line"
onClick={() => export2json({ allAffiliations, allPublications, options })}
size="sm"
>
Save session
</Button>
<Tooltip id="save-session-button" hidden={!allAffiliations.length || !allPublications.length}>
Save your ongoing work into a file that could be restored later
</Tooltip>
<Button
data-tooltip-id="restore-session-button"
icon="ri-file-upload-line"
onClick={() => setDisplayFileUpload(true)}
secondary
size="sm"
>
Restore session
</Button>
<Tooltip id="restore-session-button" hidden={!allPublications.length}>
<Tooltip id="restore-session-button">
Restore a previous work from saved file
</Tooltip>
<Button
data-tooltip-id="save-session-button"
disabled={!allPublications.length}
data-tooltip-id="save-affiliations-button"
disabled={!decidedAffiliations.length}
icon="ri-save-line"
onClick={() => export2json(allAffiliations, allPublications, options)}
onClick={() => export2json({ decidedAffiliations })}
size="sm"
>
Save decided affiliations
</Button>
<Tooltip id="save-affiliations-button" hidden={!decidedAffiliations.length}>
Save the decided affiliations in order to restore it later
</Tooltip>
<Button
data-tooltip-id="restore-affiliations-button"
icon="ri-file-upload-line"
onClick={() => setDisplayFileUpload(true)}
secondary
size="sm"
>
Save session
Restore affiliations
</Button>
<Tooltip id="save-session-button" hidden={!allPublications.length}>
Save your ongoing work into a file that could be restored later
<Tooltip id="restore-affiliations-button">
Restore affiliations from saved file
</Tooltip>
<Button
data-tooltip-id="export-fosm-button"
disabled={!allPublications.length}
icon="ri-save-line"
onClick={() => export2BsoCsv(allPublications)}
size="sm"
>
Export BSO
Export French OSM
</Button>
<Tooltip id="export-fosm-button" hidden={!allPublications.length}>
Export the selected publications in the format needed to build a local French OSM
</Tooltip>
</Col>
</Row>
{displayFileUpload && (
Expand All @@ -62,7 +93,7 @@ export default function Actions({
accept=".json"
hint="Select JSON file to restore from previous state"
label="JSON file"
onChange={(e) => importJson(e, setAllAffiliations, setSearchParams, setAllPublications)}
onChange={(e) => { importJson(e, options, setAllAffiliations, setAllPublications, setSearchParams, tagAffiliations); setDisplayFileUpload(false); }}
/>
</Col>
</Row>
Expand Down Expand Up @@ -92,4 +123,5 @@ Actions.propTypes = {
options: PropTypes.object.isRequired,
setAllAffiliations: PropTypes.func.isRequired,
setAllPublications: PropTypes.func.isRequired,
tagAffiliations: PropTypes.func.isRequired,
};
3 changes: 2 additions & 1 deletion client/src/pages/home/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useEffect, useState } from 'react';

import Actions from './actions';
import Filters from './filters';
import Metrics from './metrics';
// import Metrics from './metrics';
import AffiliationsView from './views/affiliations';
import WorksView from './views/works';
import Gauge from '../../components/gauge';
Expand Down Expand Up @@ -374,6 +374,7 @@ export default function Home() {
options={options}
setAllAffiliations={setAllAffiliations}
setAllPublications={setAllPublications}
tagAffiliations={tagAffiliations}
/>
<Tabs defaultActiveTab={0}>
<Tab label="Affiliations">
Expand Down
22 changes: 16 additions & 6 deletions client/src/utils/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,33 @@ const export2BsoCsv = (allPublications) => {
document.body.removeChild(link);
};

const export2json = (allAffiliations, allPublications, options) => {
const export2json = (data) => {
const link = document.createElement('a');
link.href = URL.createObjectURL(new Blob([JSON.stringify({ allAffiliations, allPublications, options })], { type: 'application/json' }));
link.href = URL.createObjectURL(new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' }));
link.setAttribute('download', 'works-finder.json');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};

const importJson = (e, setAllAffiliations, setSearchParams, setAllPublications) => {
const importJson = (e, optionsInit, setAllAffiliations, setAllPublications, setSearchParams, tagAffiliations) => {
const fileReader = new FileReader();
fileReader.readAsText(e.target.files[0], 'UTF-8');
fileReader.onload = (f) => {
const { allAffiliations, allPublications, options } = JSON.parse(f.target.result);
const { allAffiliations = [], allPublications = [], decidedAffiliations = [], options = optionsInit } = JSON.parse(f.target.result);
options.restoreFromFile = true;
setAllAffiliations(allAffiliations);
setAllPublications(allPublications);
if (allAffiliations.length) {
setAllAffiliations(allAffiliations);
}
if (allPublications.length) {
setAllPublications(allPublications);
}
if (decidedAffiliations) {
const validatedAffiliations = decidedAffiliations.filter((decidedAffiliation) => decidedAffiliation.status === 'validated');
tagAffiliations(validatedAffiliations, 'validated');
const excludedAffiliations = decidedAffiliations.filter((decidedAffiliation) => decidedAffiliation.status === 'excluded');
tagAffiliations(excludedAffiliations, 'excluded');
}
setSearchParams(options);
};
};
Expand Down

0 comments on commit 7ecf6be

Please sign in to comment.