Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FD-1680 -- Preferred Terminology Filtering by Name and System #140

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/components/Projects/Tables/EditDataTypeSubForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ function EditDataTypeSubForm({ type, form, editRow, tableData }) {
}}
placeholder="Search to Select"
optionFilterProp="children"
filterOption={(input, option) =>
(option?.label ?? '').includes(input)
}
// Searches by terminology name, accounting for spaces in the name
filterOption={(input, option) => {
const trimmedInput = input.toLowerCase().trim();
const optionLabel = (option?.label).toLowerCase().trim();
return optionLabel.includes(trimmedInput);
}}
filterSort={(optionA, optionB) =>
(optionA?.label ?? '')
(optionA?.label)
.toLowerCase()
.localeCompare((optionB?.label ?? '').toLowerCase())
.localeCompare((optionB?.label).toLowerCase())
}
options={terminologies.map(term => {
return {
Expand Down
13 changes: 8 additions & 5 deletions src/components/Projects/Terminologies/PreferredTerminology.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,17 @@ export const PreferredTerminology = ({ terminology, setTerminology }) => {
setPreferredData([]);
};

// Filters the terminologies that have already been selected out of the main terminology array to avoid duplicates
// Filters terminologies that have already been selected (by combination of name and url) out of the main terminology array to avoid duplicates
const filterTerminologies = () => {
const terminologiesToExclude = new Set([
...prefTerminologies?.map(pt => pt?.id),
...displaySelectedTerminologies?.map(dst => dst?.id),
...preferredData?.map(ep => ep?.id),
...prefTerminologies?.map(pt => `${pt?.name}|${pt?.url}`),
...displaySelectedTerminologies?.map(dst => `${dst?.name}|${dst?.url}`),
...preferredData?.map(ep => `${ep?.name}|${ep?.url}`),
]);
return terminologies.filter(t => !terminologiesToExclude?.has(t.id));

return terminologies.filter(
t => !terminologiesToExclude.has(`${t?.name}|${t?.url}`)
);
};

const filteredTerminologyArray = filterTerminologies();
Expand Down