Skip to content

Commit

Permalink
feat(ui): Exclude ror names from url
Browse files Browse the repository at this point in the history
  • Loading branch information
annelhote committed Feb 16, 2024
1 parent 315ec49 commit 3682cd2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
5 changes: 2 additions & 3 deletions client/src/components/tag-input/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function TagInput({
setInput('');
return;
}
const newValues = [...values, { color: 'brown-cafe-creme', label: input.trim() }];
const newValues = [...values, { label: input.trim(), source: 'user' }];
setValues(newValues);
setInput('');
onTagsChange(newValues);
Expand Down Expand Up @@ -69,8 +69,7 @@ export default function TagInput({
{values.map((tag) => (
<Tag
className="fr-mr-1w"
// brown-cafe-creme, brown-caramel, brown-opera
colorFamily={tag?.color ?? 'brown-cafe-creme'}
colorFamily={(tag?.source ?? 'user') === 'user' ? 'brown-cafe-creme' : 'brown-caramel'}
key={tag.label}
onClick={() => handleDeleteClick(tag)}
>
Expand Down
50 changes: 29 additions & 21 deletions client/src/pages/filters.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,38 @@ export default function Filters({ sendQuery }) {
const [tags, setTags] = useState([]);

useEffect(() => {
if (searchParams.size === 0) {
setSearchParams({
affiliations: [],
datasets: false,
endYear: '2021',
startYear: '2021',
});
} else {
setCurrentSearchParams({
affiliations: searchParams.getAll('affiliations'),
datasets: searchParams.get('datasets') === 'true',
endYear: searchParams.get('endYear'),
startYear: searchParams.get('startYear'),
});
setTags(searchParams.getAll('affiliations').map((affiliation) => ({ color: 'brown-cafe-creme', label: affiliation })));
}
const getData = async () => {
if (searchParams.size === 0) {
setSearchParams({
affiliations: [],
datasets: false,
endYear: '2021',
startYear: '2021',
});
setTags([]);
} else {
setCurrentSearchParams({
affiliations: searchParams.getAll('affiliations'),
datasets: searchParams.get('datasets') === 'true',
endYear: searchParams.get('endYear'),
startYear: searchParams.get('startYear'),
});
const affiliations = searchParams.getAll('affiliations');
const queries = affiliations.map((affiliation) => getRorNames(affiliation));
const rorNames = await Promise.all(queries);
let allTags = [
...affiliations.map((affiliation) => ({ label: affiliation, source: 'user' })),
...rorNames.flat().map((name) => ({ label: name, source: 'ror' })),
];
allTags = [...new Map(allTags.map((v) => [v.label.toLowerCase(), v])).values()];
setTags(allTags);
}
};
getData();
}, [searchParams, setSearchParams]);

const onTagsChange = async (affiliations) => {
const queries = affiliations.map((affiliation) => getRorNames(affiliation.label));
let allNames = await Promise.all(queries);
allNames = [...affiliations.map((affiliation) => affiliation.label), ...allNames.flat()];
allNames = [...new Set(allNames.map((name) => name.toLowerCase()))];
setSearchParams({ ...currentSearchParams, affiliations: allNames });
setSearchParams({ ...currentSearchParams, affiliations: affiliations.filter((affiliation) => affiliation.source === 'user').map((affiliation) => affiliation.label) });
};

const checkAndSendQuery = () => {
Expand Down

0 comments on commit 3682cd2

Please sign in to comment.