From 4918350e13f6cea39db9f1f88865bbf52fcb3677 Mon Sep 17 00:00:00 2001 From: GaziYucel <84437883+GaziYucel@users.noreply.github.com> Date: Sat, 8 Feb 2025 17:07:24 +0100 Subject: [PATCH] pkp/pkp-lib#10906 Entering duplicate ROR affiliations are not filtered from search results --- .../Form/fields/FieldAffiliations.vue | 5 +- .../FieldAffiliationsRorAutoSuggest.vue | 75 ++++++++++++------- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/src/components/Form/fields/FieldAffiliations.vue b/src/components/Form/fields/FieldAffiliations.vue index a744c1af5..90333b607 100644 --- a/src/components/Form/fields/FieldAffiliations.vue +++ b/src/components/Form/fields/FieldAffiliations.vue @@ -136,7 +136,10 @@ }) }} - +
diff --git a/src/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue b/src/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue index e6776e0bb..2ad81d8dc 100644 --- a/src/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue +++ b/src/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue @@ -60,6 +60,13 @@ import Icon from '@/components/Icon/Icon.vue'; import {useFetch} from '@/composables/useFetch'; import {useId} from '@/composables/useId'; +const props = defineProps({ + currentValue: { + type: Array, + default: () => [], + }, +}); +const currentValueIds = ref([]); const {generateId} = useId(); const autosuggestContainerId = generateId(); const currentSelected = ref([]); @@ -94,35 +101,49 @@ const autoSuggestProps = computed(() => ({ isLoading: isLoading.value, })); +watch(props.currentValue, (newValue) => { + currentValueIds.value = []; + newValue.forEach((item) => { + if (item['ror']) currentValueIds.value.push(item['ror']); + }); +}); + const mappedSuggestions = computed(() => { - return suggestions.value?.items.map((item) => { - const displayLocale = - item.names?.find((i) => i.types.includes('ror_display'))?.lang !== null - ? item.names?.find((i) => i.types.includes('ror_display'))?.lang - : noLangCode; - - let names = {}; - item.names?.forEach((name) => { - if (name.types.includes('label') || name.types.includes('ror_display')) { - const locale = name.lang !== null ? name.lang : noLangCode; - names[locale] = name.value; - } - }); - - return { - value: { - id: null, - ror: item.id, - displayLocale: displayLocale, - isActive: item.status === 'active' ? 1 : 0, - name: names, - _href: null, - }, - label: names[displayLocale], - hasSlot: true, - href: item.id, - }; + let newSuggestions = []; + suggestions.value?.items.map((item) => { + if (!currentValueIds.value?.includes(item.id)) { + const displayLocale = + item.names?.find((i) => i.types.includes('ror_display'))?.lang !== null + ? item.names?.find((i) => i.types.includes('ror_display'))?.lang + : noLangCode; + + let names = {}; + item.names?.forEach((name) => { + if ( + name.types.includes('label') || + name.types.includes('ror_display') + ) { + const locale = name.lang !== null ? name.lang : noLangCode; + names[locale] = name.value; + } + }); + + newSuggestions.push({ + value: { + id: null, + ror: item.id, + displayLocale: displayLocale, + isActive: item.status === 'active' ? 1 : 0, + name: names, + _href: null, + }, + label: names[displayLocale], + hasSlot: true, + href: item.id, + }); + } }); + return newSuggestions; }); watch(queryParams, () => {