@@ -60,6 +60,13 @@ import Icon from '@/components/Icon/Icon.vue';
60
60
import {useFetch } from ' @/composables/useFetch' ;
61
61
import {useId } from ' @/composables/useId' ;
62
62
63
+ const props = defineProps ({
64
+ currentValue: {
65
+ type: Array ,
66
+ default : () => [],
67
+ },
68
+ });
69
+ const currentValueIds = ref ([]);
63
70
const {generateId } = useId ();
64
71
const autosuggestContainerId = generateId ();
65
72
const currentSelected = ref ([]);
@@ -94,35 +101,49 @@ const autoSuggestProps = computed(() => ({
94
101
isLoading: isLoading .value ,
95
102
}));
96
103
104
+ watch (props .currentValue , (newValue ) => {
105
+ currentValueIds .value = [];
106
+ newValue .forEach ((item ) => {
107
+ if (item[' ror' ]) currentValueIds .value .push (item[' ror' ]);
108
+ });
109
+ });
110
+
97
111
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
+ }
125
145
});
146
+ return newSuggestions;
126
147
});
127
148
128
149
watch (queryParams, () => {
0 commit comments