Skip to content

Commit

Permalink
feat(openalex): Can remove a just added ROR
Browse files Browse the repository at this point in the history
  • Loading branch information
jerem1508 committed Nov 29, 2024
1 parent 6968323 commit 862b267
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions client/src/pages/openalex-ror/results/index.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import {
Badge,
Button,
ButtonGroup,
Col,
Container,
Link,
Modal,
ModalContent,
ModalFooter,
ModalTitle,
Row,
Spinner,
Tag,
Text,
TextInput,
Expand Down Expand Up @@ -45,7 +41,7 @@ export default function Affiliations() {

const [addList, setAddList] = useState([]);
const [affiliations, setAffiliations] = useState([]);
const [allOpenalexCorrections, setAllOpenalexCorrections] = useState([]);
const [allOpenalexCorrections, setAllOpenalexCorrections] = useState([]); // TODO: ??
const [body, setBody] = useState({});
const [filteredAffiliationName, setFilteredAffiliationName] = useState('');
const [filteredAffiliations, setFilteredAffiliations] = useState([]);
Expand All @@ -54,16 +50,17 @@ export default function Affiliations() {
status.validated.id,
status.excluded.id,
]);
const [isLoadingRorData, setIsLoadingRorData] = useState(false);
const [isModalOpen, setIsModalOpen] = useState(false);
const [isLoadingRorData, setIsLoadingRorData] = useState(false); // TODO: spinner dans modal
const [isModalOpen, setIsModalOpen] = useState(false); // TODO: ancienne modal - a supp

const [isAddModalOpen, setIsAddModalOpen] = useState(false);
const [isRemoveModalOpen, setIsRemoveModalOpen] = useState(false);
const [removeList, setRemoveList] = useState([]);
const [ror, setRor] = useState('');
const [cleanRor, setCleanRor] = useState('');
const [rorMessage, setRorMessage] = useState('');
const [rorMessageType, setRorMessageType] = useState('');
const [selectedOpenAlex, setSelectedOpenAlex] = useState([]);
const [cleanRor, setCleanRor] = useState('');
const [selectedOpenAlex, setSelectedOpenAlex] = useState([]); // TODO: should be deleted
const [uniqueRors, setUniqueRors] = useState({});
const [rorsToRemove, setRorsToRemove] = useState([]);

Expand All @@ -85,7 +82,7 @@ export default function Affiliations() {
enabled: false,
});

const undo = (id) => {
const undo = (id) => { // TODO: should be deleted
const newAffiliations = affiliations.map((affiliation) => {
if (affiliation.id === id) {
// eslint-disable-next-line no-param-reassign
Expand All @@ -99,7 +96,7 @@ export default function Affiliations() {
setAllOpenalexCorrections([...allOpenalexCorrections, ...getAffiliationsCorrections(newAffiliations)]);
};

const applyCorrections = async () => {
const applyCorrections = async () => { // TODO: should be adapted
let rorsToAdd = await Promise.all(
addList.map((add) => getRorData(add)),
);
Expand All @@ -115,6 +112,7 @@ export default function Affiliations() {
const hasCorrection = rorsToCorrect.filter((rorToCorrect) => rorToCorrect?.action).length > 0;
return { ...item, hasCorrection, rorsToCorrect };
});

setAllOpenalexCorrections([...allOpenalexCorrections, ...getAffiliationsCorrections(selectedOpenAlexTmp)]);
// Duplicate affiliations array
const affiliationsTmp = [...affiliations];
Expand All @@ -136,7 +134,7 @@ export default function Affiliations() {
setRemoveList([]);
};

useEffect(() => {
useEffect(() => { // TODO: should be deleted
const uniqueRorsTmp = {};
selectedOpenAlex.forEach((affiliation) => {
affiliation.rorsToCorrect.forEach((_ror) => {
Expand Down Expand Up @@ -277,6 +275,13 @@ export default function Affiliations() {
}, [ror]);

// -------------------------------------------
// TODO: afficher les ROR supprimer (striked) dans la modal de suppression
// TODO: faire fonctionner les filtres
// TODO: bonton copier ROR
// TODO: lien vers ror.org dans modales
// TODO: faire fonctionner les exports
// TODO: faire fonctionner le feedback

const toggleRemovedRor = (affiliationId, rorId) => {
const updatedAffiliations = affiliations.map((affiliation) => {
if (affiliation.id === affiliationId) {
Expand All @@ -292,26 +297,14 @@ export default function Affiliations() {
setAffiliations(updatedAffiliations);
};

const removeRorFromAddList = (affiliationId, rorId) => {
const updatedAffiliations = affiliations.map((affiliation) => {
if (affiliation.id === affiliationId) {
if (affiliation.addList.find((item) => item.rorId === rorId)) {
return { ...affiliation, addList: affiliation.addList.filter((item) => item.rorId !== rorId) };
}
}
return affiliation;
});

setAffiliations(updatedAffiliations);
};

const removeRorMultiple = () => {
const selectedRorIds = rorsToRemove.filter((_ror) => _ror.removed).map((_ror) => _ror.rorId);

const updatedAffiliations = affiliations.map((affiliation) => {
if (affiliation.selected) {
return {
...affiliation,
addList: affiliation.addList.filter((item) => !selectedRorIds.includes(item.rorId)),
removeList: [...new Set([...affiliation.removeList, ...selectedRorIds])],
selected: false,
};
Expand All @@ -324,6 +317,19 @@ export default function Affiliations() {
setIsRemoveModalOpen(false);
};

const removeRorFromAddList = (affiliationId, rorId) => {
const updatedAffiliations = affiliations.map((affiliation) => {
if (affiliation.id === affiliationId) {
if (affiliation.addList.find((item) => item.rorId === rorId)) {
return { ...affiliation, addList: affiliation.addList.filter((item) => item.rorId !== rorId) };
}
}
return affiliation;
});

setAffiliations(updatedAffiliations);
};

useEffect(() => {
if (rorMessageType !== 'valid') {
setCleanRor({});
Expand Down

0 comments on commit 862b267

Please sign in to comment.