From ad7358ccdfaf8e46484e187d935feeda78951d92 Mon Sep 17 00:00:00 2001 From: Muhammed Mustafa Date: Fri, 5 Aug 2022 10:42:59 +0530 Subject: [PATCH] chore/removed enter to save for json cells and added formatting after save --- packages/nc-gui-v2/components/cell/Json.vue | 11 ++++++++++- packages/nc-gui-v2/components/smartsheet/Cell.vue | 2 ++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/nc-gui-v2/components/cell/Json.vue b/packages/nc-gui-v2/components/cell/Json.vue index 523c88b03c..3168185ce6 100644 --- a/packages/nc-gui-v2/components/cell/Json.vue +++ b/packages/nc-gui-v2/components/cell/Json.vue @@ -27,7 +27,7 @@ let localValue = $( computed({ get: () => localValueState, set: (val: undefined | string | Record) => { - localValueState = typeof val === 'object' ? JSON.stringify(val) : val + localValueState = typeof val === 'object' ? JSON.stringify(val, null, 2) : val }, }), ) @@ -43,9 +43,18 @@ const clear = () => { localValue = vModel } +const formatJson = (json: string) => { + try { + return JSON.stringify(JSON.parse(json), null, 2) + } catch (e) { + return json + } +} + const onSave = () => { isExpanded = false editEnabled.value = false + localValue = localValue ? formatJson(localValue) : localValue vModel = localValue } diff --git a/packages/nc-gui-v2/components/smartsheet/Cell.vue b/packages/nc-gui-v2/components/smartsheet/Cell.vue index 9f7793761a..76fd005ab4 100644 --- a/packages/nc-gui-v2/components/smartsheet/Cell.vue +++ b/packages/nc-gui-v2/components/smartsheet/Cell.vue @@ -92,6 +92,8 @@ const { } = useColumn(column) const syncAndNavigate = (dir: NavigateDir) => { + if (isJSON) return + if (changed) { emit('save') changed = false