Skip to content

Commit b83b64c

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

File tree

2 files changed

+56
-28
lines changed

2 files changed

+56
-28
lines changed

src/components/Form/fields/FieldAffiliations.vue

+9-1
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">
@@ -248,6 +251,11 @@ const props = defineProps({
248251
type: String,
249252
default: null,
250253
},
254+
/** The ID of the form this field should appear in. This is passed down from the `Form`. */
255+
formId: {
256+
type: String,
257+
default: null,
258+
},
251259
/** Current value of the field */
252260
value: {
253261
type: Array,

src/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue

+47-27
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@ 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 = computed(() => {
70+
let ids = [];
71+
props.currentValue.forEach((item) => {
72+
if (item['ror']) ids.push(item['ror']);
73+
});
74+
return ids;
75+
});
6376
const {generateId} = useId();
6477
const autosuggestContainerId = generateId();
6578
const currentSelected = ref([]);
@@ -95,34 +108,41 @@ const autoSuggestProps = computed(() => ({
95108
}));
96109
97110
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-
};
111+
let newSuggestions = [];
112+
suggestions.value?.items.map((item) => {
113+
if (!currentValueIds.value?.includes(item.id)) {
114+
const displayLocale =
115+
item.names?.find((i) => i.types.includes('ror_display'))?.lang !== null
116+
? item.names?.find((i) => i.types.includes('ror_display'))?.lang
117+
: noLangCode;
118+
119+
let names = {};
120+
item.names?.forEach((name) => {
121+
if (
122+
name.types.includes('label') ||
123+
name.types.includes('ror_display')
124+
) {
125+
const locale = name.lang !== null ? name.lang : noLangCode;
126+
names[locale] = name.value;
127+
}
128+
});
129+
130+
newSuggestions.push({
131+
value: {
132+
id: null,
133+
ror: item.id,
134+
displayLocale: displayLocale,
135+
isActive: item.status === 'active' ? 1 : 0,
136+
name: names,
137+
_href: null,
138+
},
139+
label: names[displayLocale],
140+
hasSlot: true,
141+
href: item.id,
142+
});
143+
}
125144
});
145+
return newSuggestions;
126146
});
127147
128148
watch(queryParams, () => {

0 commit comments

Comments
 (0)