From 92ad577d7b400e582ba795921638c31b01673e53 Mon Sep 17 00:00:00 2001 From: mertmit Date: Mon, 13 Nov 2023 13:48:44 +0300 Subject: [PATCH] fix: trailing space handling for select options Signed-off-by: mertmit --- packages/nc-gui/components/cell/MultiSelect.vue | 8 ++++---- packages/nc-gui/components/cell/SingleSelect.vue | 4 ++-- packages/nocodb/src/services/columns.service.ts | 10 ++++------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/packages/nc-gui/components/cell/MultiSelect.vue b/packages/nc-gui/components/cell/MultiSelect.vue index 7a64c35a1a..d8fe577a99 100644 --- a/packages/nc-gui/components/cell/MultiSelect.vue +++ b/packages/nc-gui/components/cell/MultiSelect.vue @@ -144,14 +144,14 @@ const selectedTitles = computed(() => } return 0 }) - : modelValue.split(',').map((el) => el.trim()) - : modelValue.map((el) => el.trim()) + : modelValue.split(',') + : modelValue : [], ) onMounted(() => { selectedIds.value = selectedTitles.value.flatMap((el) => { - const item = options.value.find((op) => op.title === el) + const item = options.value.find((op) => op.title === el || op.title === el?.trim()) const itemIdOrTitle = item?.id || item?.title if (itemIdOrTitle) { return [itemIdOrTitle] @@ -165,7 +165,7 @@ watch( () => modelValue, () => { selectedIds.value = selectedTitles.value.flatMap((el) => { - const item = options.value.find((op) => op.title === el) + const item = options.value.find((op) => op.title === el || op.title === el?.trim()) if (item && (item.id || item.title)) { return [(item.id || item.title)!] } diff --git a/packages/nc-gui/components/cell/SingleSelect.vue b/packages/nc-gui/components/cell/SingleSelect.vue index 6d132cf0b0..0afc0e4c4b 100644 --- a/packages/nc-gui/components/cell/SingleSelect.vue +++ b/packages/nc-gui/components/cell/SingleSelect.vue @@ -104,7 +104,7 @@ const hasEditRoles = computed(() => isUIAllowed('dataEdit')) const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && active.value) const vModel = computed({ - get: () => tempSelectedOptState.value ?? modelValue?.trim(), + get: () => tempSelectedOptState.value ?? modelValue, set: (val) => { if (val && isNewOptionCreateEnabled.value && (options.value ?? []).every((op) => op.title !== val)) { tempSelectedOptState.value = val @@ -259,7 +259,7 @@ const handleClose = (e: MouseEvent) => { useEventListener(document, 'click', handleClose, true) const selectedOpt = computed(() => { - return options.value.find((o) => o.value === vModel.value) + return options.value.find((o) => o.value === vModel.value || o.value === vModel.value?.trim()) }) diff --git a/packages/nocodb/src/services/columns.service.ts b/packages/nocodb/src/services/columns.service.ts index e485023849..f93638bf6a 100644 --- a/packages/nocodb/src/services/columns.service.ts +++ b/packages/nocodb/src/services/columns.service.ts @@ -356,12 +356,10 @@ export class ColumnsService { }), ); - const data = await baseModel.execAndParse( - sqlClient.raw('SELECT DISTINCT ?? FROM ??', [ - column.column_name, - baseModel.getTnPath(table.table_name), - ]), - ); + const data = await sqlClient.raw('SELECT DISTINCT ?? FROM ??', [ + column.column_name, + baseModel.getTnPath(table.table_name), + ]); if (data.length) { const existingOptions = colBody.colOptions.options.map(