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 10, 2025
1 parent 68e6e34 commit a68d581
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 27 deletions.
17 changes: 16 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"
:filter-ids="currentValueRorIds"
/>
</TableCell>
<TableCell>
<div v-if="showNewAffiliationForm">
Expand Down Expand Up @@ -248,6 +251,11 @@ const props = defineProps({
type: String,
default: null,
},
/** The ID of the form this field should appear in. This is passed down from the `Form`. */
formId: {
type: String,
default: null,
},
/** Current value of the field */
value: {
type: Array,
Expand Down Expand Up @@ -283,6 +291,13 @@ const currentValue = computed({
get: () => props.value,
set: (newVal) => emit('change', props.name, 'value', newVal),
});
const currentValueRorIds = computed(() => {
return currentValue.value
.filter((item) => item['ror'])
.map((item) => {
return item['ror'];
});
});
const supportedLocales = props.locales.map((language) => language.key);
const autoSuggestRef = ref(null);
const autoSuggestSelected = computed({
Expand Down
65 changes: 39 additions & 26 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({
filterIds: {
type: Array,
default: () => [],
},
});
const filterRorIds = props.filterIds;
const {generateId} = useId();
const autosuggestContainerId = generateId();
const currentSelected = ref([]);
Expand Down Expand Up @@ -95,35 +102,41 @@ const autoSuggestProps = computed(() => ({
}));
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 suggestions.value?.items
.filter((item) => !filterRorIds.value?.includes(item.id))
.map((item) => {
return mapSuggestion(item);
});
});
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,
};
function mapSuggestion(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,
};
}
watch(queryParams, () => {
if (inputValue.value.length > 3) {
Expand Down

0 comments on commit a68d581

Please sign in to comment.