Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ui): load initial value for Multiselect input - WF-66 #571

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/ui/src/components/core/base/BaseSelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ const emit = defineEmits(["change"]);

const props = defineProps({
baseId: { type: String, required: true },
activeValue: { required: true, validator: () => true },
activeValue: {
type: [Array, String] as PropType<string[] | string>,
required: true,
},
options: {
type: Object as PropType<Record<string, string | number | undefined>>,
required: true,
Expand All @@ -109,8 +112,13 @@ const props = defineProps({
placeholder: { type: String, required: false, default: undefined },
});

const { baseId, activeValue, options, maximumCount, mode, placeholder } =
toRefs(props);
const { baseId, options, maximumCount, mode, placeholder } = toRefs(props);

const activeValue = computed<string[]>(() =>
typeof props.activeValue === "string"
? [props.activeValue]
: props.activeValue,
);

const LIST_MAX_HEIGHT_PX = 200;
const rootEl: Ref<HTMLElement | null> = ref(null);
Expand Down Expand Up @@ -152,12 +160,9 @@ const isMaximumCountReached = computed(() => {
watch(
activeValue,
() => {
selectedOptions.value = [];

activeValue.value.forEach?.((av: string) => {
if (typeof options.value[av] === "undefined") return;
selectedOptions.value.push(av);
});
selectedOptions.value = activeValue.value.filter(
(v) => options.value[v] !== undefined,
);
},
{ immediate: true },
);
Expand Down
Loading