Skip to content

Commit

Permalink
fix(openalex): Change the logic behind "Remove all affiliations" butt…
Browse files Browse the repository at this point in the history
…on /2
  • Loading branch information
annelhote committed Dec 3, 2024
1 parent b2f840d commit ab4a693
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
16 changes: 9 additions & 7 deletions client/src/components/tag-input/index.jsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import {
Button,
Row, Col,
Col,
DismissibleTag,
Row,
Spinner,
TagGroup, DismissibleTag,
TagGroup,
TextInput,
} from '@dataesr/dsfr-plus';
import PropTypes from 'prop-types';
import { useEffect, useState } from 'react';

import { getTagColor } from '../../utils/tags';

Expand All @@ -17,7 +19,6 @@ const { VITE_APP_TAG_LIMIT } = import.meta.env;
const SEE_MORE_AFTER = 3;

export default function TagInput({
deletedAffiliations,
deletedTags,
getRorChildren,
hint,
Expand All @@ -29,6 +30,7 @@ export default function TagInput({
onInputHandler,
onTagsChange,
placeholder,
removeAllAffiliations,
seeMoreAction,
seeMoreAfter,
switchGetRorChildren,
Expand Down Expand Up @@ -107,7 +109,7 @@ export default function TagInput({
className="fr-ml-1w"
color="yellow-tournesol"
icon="delete-line"
onClick={() => onTagsChange([], deletedAffiliations)}
onClick={() => removeAllAffiliations()}
size="sm"
title="Remove all affiliations"
variant="text"
Expand Down Expand Up @@ -197,7 +199,6 @@ export default function TagInput({
}

TagInput.propTypes = {
deletedAffiliations: PropTypes.arrayOf(PropTypes.string).isRequired,
deletedTags: PropTypes.arrayOf(PropTypes.object),
getRorChildren: PropTypes.bool,
hint: PropTypes.string,
Expand All @@ -209,6 +210,7 @@ TagInput.propTypes = {
onInputHandler: PropTypes.func,
onTagsChange: PropTypes.func.isRequired,
placeholder: PropTypes.string,
removeAllAffiliations: PropTypes.func.isRequired,
seeMoreAction: PropTypes.func,
seeMoreAfter: PropTypes.number,
switchGetRorChildren: PropTypes.func,
Expand Down
12 changes: 10 additions & 2 deletions client/src/pages/datasets/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ export default function DatasetsSearch() {
navigate(`/${pathname.split('/')[1]}/results${queryParams}`);
};

const removeAllAffiliations = () => {
setSearchParams({
...currentSearchParams,
affiliations: [],
});
setSearchedAffiliations([]);
};

const NB_TAGS_STICKY = 2;
const tagsDisplayed = tags.slice(0, NB_TAGS_STICKY);

Expand Down Expand Up @@ -267,7 +275,6 @@ export default function DatasetsSearch() {
</Col>
<Col xs="12">
<TagInput
deletedAffiliations={deletedAffiliations}
getRorChildren={getRorChildren}
hint="Press ENTER to search for several terms / expressions. If several, an OR operator is used."
isLoading={isFetching}
Expand All @@ -277,6 +284,7 @@ export default function DatasetsSearch() {
messageType={messageType}
onInputHandler={setOnInputAffiliationsHandler}
onTagsChange={onTagsChange}
removeAllAffiliations={removeAllAffiliations}
seeMoreAfter={0}
setGetRorChildren={setGetRorChildren}
tags={tags}
Expand Down Expand Up @@ -320,7 +328,6 @@ export default function DatasetsSearch() {
<Row className="fr-pt-2w fr-pr-2w fr-pb-0 fr-pl-2w">
<Col xs="8">
<TagInput
deletedAffiliations={deletedAffiliations}
getRorChildren={getRorChildren}
hint="Press ENTER to search for several terms / expressions. If several, an OR operator is used."
isLoading={isFetching}
Expand All @@ -330,6 +337,7 @@ export default function DatasetsSearch() {
messageType={messageType}
onInputHandler={setOnInputAffiliationsHandler}
onTagsChange={onTagsChange}
removeAllAffiliations={removeAllAffiliations}
seeMoreAction={(e) => {
setIsOpen(true);
e.preventDefault();
Expand Down
1 change: 1 addition & 0 deletions client/src/pages/openalex-affiliations/results/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export default function Affiliations() {
// TODO: afficher les ROR supprimés (striked) dans la modal de suppression - à discuter
// TODO: pastilles de couleur pour les RORs
// TODO: optimisation
// TODO: Rename views-selector component

const toggleRemovedRor = (affiliationId, rorId) => {
const updatedAffiliations = affiliations.map((affiliation) => {
Expand Down
14 changes: 11 additions & 3 deletions client/src/pages/openalex-affiliations/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default function OpenalexAffiliationsSearch() {
const [tags, setTags] = useState([]);

useEffect(() => {
if (searchParams.size < 4) {
if (searchParams.size < 3) {
// Set default params values
setSearchParams({
affiliations: searchParams.getAll('affiliations') ?? [],
Expand Down Expand Up @@ -199,6 +199,14 @@ export default function OpenalexAffiliationsSearch() {

const switchGetRorChildren = () => setSearchParams({ ...currentSearchParams, getRorChildren: currentSearchParams.getRorChildren === '1' ? '0' : '1' });

const removeAllAffiliations = () => {
setSearchParams({
...currentSearchParams,
affiliations: [],
});
setSearchedAffiliations([]);
};

const NB_TAGS_STICKY = 2;
const tagsDisplayed = tags.slice(0, NB_TAGS_STICKY);

Expand Down Expand Up @@ -259,7 +267,6 @@ export default function OpenalexAffiliationsSearch() {
</Col>
<Col xs="12">
<TagInput
deletedAffiliations={deletedAffiliations}
getRorChildren={currentSearchParams.getRorChildren === '1'}
hint="Press ENTER to search for several terms / expressions. If several, an OR operator is used."
isLoading={isLoading}
Expand All @@ -269,6 +276,7 @@ export default function OpenalexAffiliationsSearch() {
messageType={messageType}
onInputHandler={setOnInputAffiliationsHandler}
onTagsChange={onTagsChange}
removeAllAffiliations={removeAllAffiliations}
seeMoreAfter={0}
switchGetRorChildren={switchGetRorChildren}
tags={tags}
Expand Down Expand Up @@ -300,7 +308,6 @@ export default function OpenalexAffiliationsSearch() {
<Row className="fr-pt-2w fr-pr-2w fr-pb-0 fr-pl-2w">
<Col xs="8">
<TagInput
deletedAffiliations={deletedAffiliations}
getRorChildren={currentSearchParams.getRorChildren === '1'}
hint="Press ENTER to search for several terms / expressions. If several, an OR operator is used."
isLoading={isLoading}
Expand All @@ -310,6 +317,7 @@ export default function OpenalexAffiliationsSearch() {
messageType={messageType}
onInputHandler={setOnInputAffiliationsHandler}
onTagsChange={onTagsChange}
removeAllAffiliations={removeAllAffiliations}
seeMoreAction={(e) => {
setIsOpen(true);
e.preventDefault();
Expand Down
12 changes: 10 additions & 2 deletions client/src/pages/publications/search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ export default function PublicationsSearch() {
navigate(`/${pathname.split('/')[1]}/results${search}`);
};

const removeAllAffiliations = () => {
setSearchParams({
...currentSearchParams,
affiliations: [],
});
setSearchedAffiliations([]);
};

const NB_TAGS_STICKY = 2;
const tagsDisplayed = tags.slice(0, NB_TAGS_STICKY);

Expand Down Expand Up @@ -268,7 +276,6 @@ export default function PublicationsSearch() {
</Col>
<Col xs="12">
<TagInput
deletedAffiliations={deletedAffiliations}
getRorChildren={getRorChildren}
hint="Press ENTER to search for several terms / expressions. If several, an OR operator is used."
isLoading={isFetching}
Expand All @@ -278,6 +285,7 @@ export default function PublicationsSearch() {
messageType={messageType}
onInputHandler={setOnInputAffiliationsHandler}
onTagsChange={onTagsChange}
removeAllAffiliations={removeAllAffiliations}
seeMoreAfter={0}
setGetRorChildren={setGetRorChildren}
tags={tags}
Expand Down Expand Up @@ -321,7 +329,6 @@ export default function PublicationsSearch() {
<Row className="fr-pt-2w fr-pr-2w fr-pb-0 fr-pl-2w">
<Col xs="8">
<TagInput
deletedAffiliations={deletedAffiliations}
getRorChildren={getRorChildren}
hint="Press ENTER to search for several terms / expressions. If several, an OR operator is used."
isLoading={isFetching}
Expand All @@ -331,6 +338,7 @@ export default function PublicationsSearch() {
messageType={messageType}
onInputHandler={setOnInputAffiliationsHandler}
onTagsChange={onTagsChange}
removeAllAffiliations={removeAllAffiliations}
seeMoreAction={(e) => {
setIsOpen(true);
e.preventDefault();
Expand Down

0 comments on commit ab4a693

Please sign in to comment.