Skip to content

Commit 4918350

Browse files
committed
pkp/pkp-lib#10906 Entering duplicate ROR affiliations are not filtered from search results
1 parent 68e6e34 commit 4918350

File tree

2 files changed

+52
-28
lines changed

2 files changed

+52
-28
lines changed

src/components/Form/fields/FieldAffiliations.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,10 @@
136136
})
137137
}}
138138
</span>
139-
<FieldAffiliationsRorAutoSuggest ref="autoSuggestRef" />
139+
<FieldAffiliationsRorAutoSuggest
140+
ref="autoSuggestRef"
141+
:current-value="currentValue"
142+
/>
140143
</TableCell>
141144
<TableCell>
142145
<div v-if="showNewAffiliationForm">

src/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ import Icon from '@/components/Icon/Icon.vue';
6060
import {useFetch} from '@/composables/useFetch';
6161
import {useId} from '@/composables/useId';
6262
63+
const props = defineProps({
64+
currentValue: {
65+
type: Array,
66+
default: () => [],
67+
},
68+
});
69+
const currentValueIds = ref([]);
6370
const {generateId} = useId();
6471
const autosuggestContainerId = generateId();
6572
const currentSelected = ref([]);
@@ -94,35 +101,49 @@ const autoSuggestProps = computed(() => ({
94101
isLoading: isLoading.value,
95102
}));
96103
104+
watch(props.currentValue, (newValue) => {
105+
currentValueIds.value = [];
106+
newValue.forEach((item) => {
107+
if (item['ror']) currentValueIds.value.push(item['ror']);
108+
});
109+
});
110+
97111
const mappedSuggestions = computed(() => {
98-
return suggestions.value?.items.map((item) => {
99-
const displayLocale =
100-
item.names?.find((i) => i.types.includes('ror_display'))?.lang !== null
101-
? item.names?.find((i) => i.types.includes('ror_display'))?.lang
102-
: noLangCode;
103-
104-
let names = {};
105-
item.names?.forEach((name) => {
106-
if (name.types.includes('label') || name.types.includes('ror_display')) {
107-
const locale = name.lang !== null ? name.lang : noLangCode;
108-
names[locale] = name.value;
109-
}
110-
});
111-
112-
return {
113-
value: {
114-
id: null,
115-
ror: item.id,
116-
displayLocale: displayLocale,
117-
isActive: item.status === 'active' ? 1 : 0,
118-
name: names,
119-
_href: null,
120-
},
121-
label: names[displayLocale],
122-
hasSlot: true,
123-
href: item.id,
124-
};
112+
let newSuggestions = [];
113+
suggestions.value?.items.map((item) => {
114+
if (!currentValueIds.value?.includes(item.id)) {
115+
const displayLocale =
116+
item.names?.find((i) => i.types.includes('ror_display'))?.lang !== null
117+
? item.names?.find((i) => i.types.includes('ror_display'))?.lang
118+
: noLangCode;
119+
120+
let names = {};
121+
item.names?.forEach((name) => {
122+
if (
123+
name.types.includes('label') ||
124+
name.types.includes('ror_display')
125+
) {
126+
const locale = name.lang !== null ? name.lang : noLangCode;
127+
names[locale] = name.value;
128+
}
129+
});
130+
131+
newSuggestions.push({
132+
value: {
133+
id: null,
134+
ror: item.id,
135+
displayLocale: displayLocale,
136+
isActive: item.status === 'active' ? 1 : 0,
137+
name: names,
138+
_href: null,
139+
},
140+
label: names[displayLocale],
141+
hasSlot: true,
142+
href: item.id,
143+
});
144+
}
125145
});
146+
return newSuggestions;
126147
});
127148
128149
watch(queryParams, () => {

0 commit comments

Comments
 (0)