From e4160198cb2f481fc96947fef8932ea9cbc07b1f Mon Sep 17 00:00:00 2001 From: Phil Reese Date: Thu, 21 Nov 2024 11:46:54 -0500 Subject: [PATCH] feat: do not show selected subject in list --- .../components/subjects/SubjectSelector.vue | 101 +++++++++++------- 1 file changed, 61 insertions(+), 40 deletions(-) diff --git a/solution/ui/regulations/eregs-vite/src/components/subjects/SubjectSelector.vue b/solution/ui/regulations/eregs-vite/src/components/subjects/SubjectSelector.vue index 8de7e3d5c..22e01f748 100644 --- a/solution/ui/regulations/eregs-vite/src/components/subjects/SubjectSelector.vue +++ b/solution/ui/regulations/eregs-vite/src/components/subjects/SubjectSelector.vue @@ -7,7 +7,7 @@ import useRemoveList from "composables/removeList"; import _debounce from "lodash/debounce"; import _isArray from "lodash/isArray"; -import { getSubjectName, getSubjectNameParts } from "utilities/filters"; +import { getSubjectName } from "utilities/filters"; import SelectedSubjectChip from "./SelectedSubjectChip.vue"; import SimpleSpinner from "eregsComponentLib/src/components/SimpleSpinner.vue"; @@ -50,7 +50,22 @@ watch( return; } - state.subjects = props.policyDocSubjects.results; + if ($route.query.subjects) { + state.subjects = props.policyDocSubjects.results.filter( + (subject) => $route.query.subjects !== subject.id.toString() + ); + } else { + state.subjects = props.policyDocSubjects.results; + } + } +); + +watch( + () => $route.query.subjects, + () => { + state.subjects = props.policyDocSubjects.results.filter( + (subject) => $route.query.subjects !== subject.id.toString() + ); } ); @@ -60,46 +75,52 @@ const getFilteredSubjects = (filter) => { return; } - state.subjects = props.policyDocSubjects.results.reduce((acc, subject) => { - const shortNameMatch = subject.short_name - ? subject.short_name.toLowerCase().includes(filter.toLowerCase()) - : false; - const abbreviationMatch = subject.abbreviation - ? subject.abbreviation.toLowerCase().includes(filter.toLowerCase()) - : false; - const fullNameMatch = subject.full_name - ? subject.full_name.toLowerCase().includes(filter.toLowerCase()) - : false; - - if (shortNameMatch || abbreviationMatch || fullNameMatch) { - let displayName; - - if (shortNameMatch) { - displayName = subject.short_name; - } else if (abbreviationMatch) { - displayName = subject.abbreviation; - } else if (fullNameMatch) { - displayName = subject.full_name; + state.subjects = props.policyDocSubjects.results + .filter((subject) => $route.query.subjects !== subject.id.toString()) + .reduce((acc, subject) => { + const shortNameMatch = subject.short_name + ? subject.short_name + .toLowerCase() + .includes(filter.toLowerCase()) + : false; + const abbreviationMatch = subject.abbreviation + ? subject.abbreviation + .toLowerCase() + .includes(filter.toLowerCase()) + : false; + const fullNameMatch = subject.full_name + ? subject.full_name.toLowerCase().includes(filter.toLowerCase()) + : false; + + if (shortNameMatch || abbreviationMatch || fullNameMatch) { + let displayName; + + if (shortNameMatch) { + displayName = subject.short_name; + } else if (abbreviationMatch) { + displayName = subject.abbreviation; + } else if (fullNameMatch) { + displayName = subject.full_name; + } + + displayName = + "" + + displayName.replace( + new RegExp(filter, "gi"), + (match) => `${match}` + ) + + ""; + + const newSubject = { + ...subject, + displayName, + }; + + return [...acc, newSubject]; } - displayName = - "" + - displayName.replace( - new RegExp(filter, "gi"), - (match) => `${match}` - ) + - ""; - - const newSubject = { - ...subject, - displayName, - }; - - return [...acc, newSubject]; - } - - return acc; - }, []); + return acc; + }, []); }; const debouncedFilter = _debounce(getFilteredSubjects, 100);