Skip to content

Commit

Permalink
pkp/pkp-lib#10906 Entering duplicate ROR affiliations are not filtere…
Browse files Browse the repository at this point in the history
…d from search results
  • Loading branch information
GaziYucel committed Feb 8, 2025
1 parent 68e6e34 commit 4918350
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
5 changes: 4 additions & 1 deletion src/components/Form/fields/FieldAffiliations.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@
})
}}
</span>
<FieldAffiliationsRorAutoSuggest ref="autoSuggestRef" />
<FieldAffiliationsRorAutoSuggest
ref="autoSuggestRef"
:current-value="currentValue"
/>
</TableCell>
<TableCell>
<div v-if="showNewAffiliationForm">
Expand Down
75 changes: 48 additions & 27 deletions src/components/Form/fields/FieldAffiliationsRorAutoSuggest.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down Expand Up @@ -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, () => {
Expand Down

0 comments on commit 4918350

Please sign in to comment.