From 304d91875faf217e68702ef48cae0674b14e8bb0 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 17 Aug 2022 22:34:45 +0530 Subject: [PATCH] fix(gui-v2): if json parsing failed set attachments as an empty array Signed-off-by: Pranav C --- packages/nc-gui-v2/components/cell/attachment/index.vue | 6 +++++- packages/nc-gui-v2/composables/useSharedFormViewStore.ts | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui-v2/components/cell/attachment/index.vue b/packages/nc-gui-v2/components/cell/attachment/index.vue index 8f6bfaa887..f2e47339b7 100644 --- a/packages/nc-gui-v2/components/cell/attachment/index.vue +++ b/packages/nc-gui-v2/components/cell/attachment/index.vue @@ -59,7 +59,11 @@ watch( () => modelValue, (nextModel) => { if (nextModel) { - attachments.value = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean) + try { + attachments.value = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean) + } catch { + attachments.value = [] + } } }, { immediate: true }, diff --git a/packages/nc-gui-v2/composables/useSharedFormViewStore.ts b/packages/nc-gui-v2/composables/useSharedFormViewStore.ts index f2f63dfb21..902405b41c 100644 --- a/packages/nc-gui-v2/composables/useSharedFormViewStore.ts +++ b/packages/nc-gui-v2/composables/useSharedFormViewStore.ts @@ -116,7 +116,7 @@ const [useProvideSharedFormStore, useSharedFormStore] = useInjectionState((share const data: Record = { ...(formState?.value ?? {}), ...(additionalState?.value || {}) } const attachment: Record = {} - for (const col of metas?.value?.[sharedFormView?.value?.fk_model_id as string]?.columns ?? []) { + for (const col of metas?.value?.[sharedView?.value?.fk_model_id as string]?.columns ?? []) { if (col.uidt === UITypes.Attachment) { attachment[`_${col.title}`] = data[col.title!] delete data[col.title!]