Skip to content

Commit

Permalink
fix(publications): Restore tag affiliations /2
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Dec 13, 2024
1 parent 82b8c29 commit b992b85
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 33 deletions.
21 changes: 11 additions & 10 deletions client/src/pages/datasets/results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Affiliations() {
const { toast } = useToast();

const { data, error, isFetched, isFetching, refetch } = useQuery({
queryKey: ['datasets', JSON.stringify(options)],
queryKey: ['works', JSON.stringify(options)],
queryFn: () => getWorks(options, toast),
enabled: false,
});
Expand All @@ -44,21 +44,22 @@ export default function Affiliations() {
const worksIds = _affiliations
.map((affiliation) => affiliation.works)
.flat();
data?.publications?.results
?.filter((publication) => worksIds.includes(publication.id))
.map((publication) => (publication.status = action));
data?.datasets?.results
?.filter((dataset) => worksIds.includes(dataset.id))
.map((dataset) => (dataset.status = action));
}
const affiliationIds = _affiliations.map((affiliation) => affiliation.id);
setAffiliations(
_affiliations
?.filter((affiliation) => affiliationIds.includes(affiliation.id))
.map((affiliation) => ({
...affiliation,
status: action,
})),
affiliations
.map((affiliation) => {
if (affiliationIds.includes(affiliation.id)) {
return ({
...affiliation,
status: action,
});
}
return affiliation;
}),
);
setSelectedAffiliations([]);
};
Expand Down
26 changes: 13 additions & 13 deletions client/src/pages/openalex-affiliations/results/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ export default function Affiliations() {

const [addList, setAddList] = useState([]); // TODO: still used ?
const [affiliations, setAffiliations] = useState([]);
const [body, setBody] = useState({});
const [cleanRor, setCleanRor] = useState('');
const [filteredAffiliationName, setFilteredAffiliationName] = useState('');
const [filteredAffiliations, setFilteredAffiliations] = useState([]);
const [isLoading, setIsLoading] = useState(false);
const [isLoadingRor, setIsLoadingRor] = useState(false);
const [isAddModalOpen, setIsAddModalOpen] = useState(false);
const [isRemoveModalOpen, setIsRemoveModalOpen] = useState(false);
const [options, setOptions] = useState({});
const [ror, setRor] = useState('');
const [rorMessage, setRorMessage] = useState('');
const [rorMessageType, setRorMessageType] = useState('');
Expand Down Expand Up @@ -82,15 +82,15 @@ export default function Affiliations() {
];

const { data, error, isFetched, isFetching, refetch } = useQuery({
queryKey: ['openalex-affiliations', JSON.stringify(body)],
queryKey: ['works', JSON.stringify(options)],
// Search for works from affiliations for each affiliation strictly longer than 2 letters
queryFn: () => getWorks(
{
...body,
affiliationStrings: body.affiliations
...options,
affiliationStrings: options.affiliations
.filter((affiliation) => !affiliation.isDisabled)
.map((affiliation) => affiliation.label),
rors: body.affiliations
rors: options.affiliations
.filter((affiliation) => affiliation.isRor)
.map((affiliation) => affiliation.label),
},
Expand Down Expand Up @@ -174,14 +174,14 @@ export default function Affiliations() {
queryParams.deletedAffiliations.push(normalize(item));
}
});
setBody(queryParams);
setOptions(queryParams);
};
getData();
}, [searchParams]);

useEffect(() => {
if (Object.keys(body).length > 0) refetch();
}, [body, refetch]);
if (Object.keys(options).length > 0) refetch();
}, [options, refetch]);

useEffect(() => {
setAffiliations(data?.affiliations?.filter(
Expand Down Expand Up @@ -449,10 +449,10 @@ export default function Affiliations() {
color="blue-cumulus"
key="openalex-affiliations-tag-year-start"
>
{`Start: ${body.startYear}`}
{`Start: ${options.startYear}`}
</Tag>
<Tag color="blue-cumulus" key="openalex-affiliations-tag-year-end">
{`End: ${body.endYear}`}
{`End: ${options.endYear}`}
</Tag>
</div>
</Col>
Expand All @@ -465,7 +465,7 @@ export default function Affiliations() {
Searched affiliations
</div>
<div className="wm-content">
{body.affiliations.map((affiliation) => (
{options.affiliations.map((affiliation) => (
<Row key={`openalex-affiliations-search-${affiliation.label}`}>
<Tag
className={`fr-mr-1w ${affiliation.isDisabled ? 'scratched' : ''
Expand All @@ -490,7 +490,7 @@ export default function Affiliations() {
</div>
</Col>
</Row>
{(body.excludedRors.length > 0) && (
{(options.excludedRors.length > 0) && (
<Row>
<Col>
<div className="wm-title">
Expand All @@ -500,7 +500,7 @@ export default function Affiliations() {
</span>
</div>
<div className="wm-content">
{body.excludedRors.split(' ').map((excludedRor) => (
{options.excludedRors.split(' ').map((excludedRor) => (
<Tag
className="fr-mr-1w"
color="green-archipel"
Expand Down
21 changes: 11 additions & 10 deletions client/src/pages/publications/results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function Affiliations() {
const { toast } = useToast();

const { data, error, isFetched, isFetching, refetch } = useQuery({
queryKey: ['publications', JSON.stringify(options)],
queryKey: ['works', JSON.stringify(options)],
queryFn: () => getWorks(options, toast),
enabled: false,
});
Expand All @@ -39,18 +39,19 @@ export default function Affiliations() {
data?.publications?.results
?.filter((publication) => worksIds.includes(publication.id))
.map((publication) => (publication.status = action));
data?.datasets?.results
?.filter((dataset) => worksIds.includes(dataset.id))
.map((dataset) => (dataset.status = action));
}
const affiliationIds = _affiliations.map((affiliation) => affiliation.id);
setAffiliations(
_affiliations
?.filter((affiliation) => affiliationIds.includes(affiliation.id))
.map((affiliation) => ({
...affiliation,
status: action,
})),
affiliations
.map((affiliation) => {
if (affiliationIds.includes(affiliation.id)) {
return ({
...affiliation,
status: action,
});
}
return affiliation;
}),
);
setSelectedAffiliations([]);
};
Expand Down

0 comments on commit b992b85

Please sign in to comment.