From 57ec5a2a99775203c31cfca8a59954f0d409b62d Mon Sep 17 00:00:00 2001 From: mertmit Date: Sat, 6 Aug 2022 19:49:59 +0300 Subject: [PATCH] fix(gui-v2): multiselect option update issues Signed-off-by: mertmit --- .../nc-gui-v2/components/cell/MultiSelect.vue | 60 ++++++++++++++----- .../components/cell/SingleSelect.vue | 8 +-- 2 files changed, 46 insertions(+), 22 deletions(-) diff --git a/packages/nc-gui-v2/components/cell/MultiSelect.vue b/packages/nc-gui-v2/components/cell/MultiSelect.vue index 70e88cb94b..43a861b273 100644 --- a/packages/nc-gui-v2/components/cell/MultiSelect.vue +++ b/packages/nc-gui-v2/components/cell/MultiSelect.vue @@ -14,6 +14,9 @@ const emit = defineEmits(['update:modelValue']) const { isMysql } = useProject() const column = inject(ColumnInj) +const isForm = inject('isForm', false) +const editEnabled = inject(EditModeInj, ref(false)) +const selectedIds = ref([]) const options = computed(() => { if (column?.colOptions) { @@ -27,20 +30,41 @@ const options = computed(() => { }) const vModel = computed({ - get: () => - modelValue - ? typeof modelValue === 'string' - ? isMysql - ? modelValue.split(',').sort((a, b) => { - const opa = options.value.find((el: SelectOptionType) => el.title === a) - const opb = options.value.find((el: SelectOptionType) => el.title === b) - return opa.order - opb.order - }) - : modelValue.split(',') - : modelValue - : [], + get: () => selectedIds.value.map((el) => options.value.find((op: SelectOptionType) => op.id === el).title), set: (val) => emit('update:modelValue', val.join(',')), }) + +const selectedTitles = computed(() => + modelValue + ? typeof modelValue === 'string' + ? isMysql + ? modelValue.split(',').sort((a, b) => { + const opa = options.value.find((el: SelectOptionType) => el.title === a) + const opb = options.value.find((el: SelectOptionType) => el.title === b) + if (opa && opb) { + return opa.order - opb.order + } + return 0 + }) + : modelValue.split(',') + : modelValue + : [], +) + +onMounted(() => { + selectedIds.value = selectedTitles.value.map((el) => { + return options.value.find((op: SelectOptionType) => op.title === el).id + }) +}) + +watch( + () => modelValue, + (n, _o) => { + selectedIds.value = selectedTitles.value.map((el) => { + return options.value.find((op: SelectOptionType) => op.title === el).id + }) + }, +)