From d82727a065c833a252798c3518223de56038dc6b Mon Sep 17 00:00:00 2001 From: Mert E Date: Fri, 28 Jun 2024 12:55:53 +0300 Subject: [PATCH] fix: insert user from group by (#8889) --- packages/nc-gui/components/cell/User.vue | 20 ++++++++++++++++---- packages/nocodb/src/db/BaseModelSqlv2.ts | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui/components/cell/User.vue b/packages/nc-gui/components/cell/User.vue index 8ffc58a06a..8a6c1e1bb3 100644 --- a/packages/nc-gui/components/cell/User.vue +++ b/packages/nc-gui/components/cell/User.vue @@ -122,8 +122,20 @@ const editAllowed = computed(() => (hasEditRoles.value || isForm.value) && activ const vModel = computed({ get: () => { let selected: { label: string; value: string }[] = [] - if (typeof modelValue === 'string') { - const idsOrMails = modelValue.split(',').map((idOrMail) => idOrMail.trim()) + + let localModelValue = modelValue + + // if stringified json + if (typeof localModelValue === 'string' && /^\s*[{[]/.test(localModelValue)) { + try { + localModelValue = JSON.parse(localModelValue) + } catch (e) { + // do nothing + } + } + + if (typeof localModelValue === 'string') { + const idsOrMails = localModelValue.split(',').map((idOrMail) => idOrMail.trim()) selected = idsOrMails.reduce((acc, idOrMail) => { const user = options.value.find((u) => u.id === idOrMail || u.email === idOrMail) if (user) { @@ -135,8 +147,8 @@ const vModel = computed({ return acc }, [] as { label: string; value: string }[]) } else { - selected = modelValue - ? (Array.isArray(modelValue) ? modelValue : [modelValue]).reduce((acc, item) => { + selected = localModelValue + ? (Array.isArray(localModelValue) ? localModelValue : [localModelValue]).reduce((acc, item) => { const label = item?.display_name || item?.email if (label) { acc.push({ diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 2f64d33def..9689e3ed0a 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -7202,7 +7202,7 @@ class BaseModelSqlv2 { if ( typeof data[column.column_name] === 'string' && - /^\s*[{[]$/.test(data[column.column_name]) + /^\s*[{[]/.test(data[column.column_name]) ) { try { data[column.column_name] = JSON.parse(data[column.column_name]);