From 1c2c9d320a10cfd38d9ae4933b8b8a0b1cc0ec64 Mon Sep 17 00:00:00 2001 From: mertmit Date: Sun, 16 Oct 2022 16:43:49 +0300 Subject: [PATCH] fix(nc-gui): use composable instead of redefining Signed-off-by: mertmit --- .../nc-gui/components/smartsheet/Cell.vue | 55 ++++++------------- packages/nc-gui/composables/useColumn.ts | 5 +- 2 files changed, 20 insertions(+), 40 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/Cell.vue b/packages/nc-gui/components/smartsheet/Cell.vue index 3b53294172..2ed187af22 100644 --- a/packages/nc-gui/components/smartsheet/Cell.vue +++ b/packages/nc-gui/components/smartsheet/Cell.vue @@ -66,43 +66,6 @@ const syncValue = useDebounceFn( 500, { maxWait: 2000 }, ) - -const isAutoSaved = $computed(() => { - return [ - UITypes.SingleLineText, - UITypes.LongText, - UITypes.PhoneNumber, - UITypes.Email, - UITypes.URL, - UITypes.Number, - UITypes.Decimal, - UITypes.Percent, - UITypes.Count, - UITypes.AutoNumber, - UITypes.SpecificDBType, - UITypes.Geometry, - UITypes.Duration, - ].includes(column?.value?.uidt as UITypes) -}) - -const isManualSaved = $computed(() => [UITypes.Currency].includes(column?.value?.uidt as UITypes)) - -const vModel = computed({ - get: () => props.modelValue, - set: (val) => { - if (val !== props.modelValue) { - currentRow.value.rowMeta.changed = true - emit('update:modelValue', val) - if (isAutoSaved) { - syncValue() - } else if (!isManualSaved) { - emit('save') - currentRow.value.rowMeta.changed = true - } - } - }, -}) - const { isPrimary, isURL, @@ -126,8 +89,26 @@ const { isMultiSelect, isPercent, isPhoneNumber, + isAutoSaved, + isManualSaved, } = useColumn(column) +const vModel = computed({ + get: () => props.modelValue, + set: (val) => { + if (val !== props.modelValue) { + currentRow.value.rowMeta.changed = true + emit('update:modelValue', val) + if (isAutoSaved.value) { + syncValue() + } else if (!isManualSaved.value) { + emit('save') + currentRow.value.rowMeta.changed = true + } + } + }, +}) + const syncAndNavigate = (dir: NavigateDir, e: KeyboardEvent) => { if (isJSON.value) return diff --git a/packages/nc-gui/composables/useColumn.ts b/packages/nc-gui/composables/useColumn.ts index 93710c3f77..a481e227a0 100644 --- a/packages/nc-gui/composables/useColumn.ts +++ b/packages/nc-gui/composables/useColumn.ts @@ -56,11 +56,10 @@ export function useColumn(column: Ref) { UITypes.AutoNumber, UITypes.SpecificDBType, UITypes.Geometry, + UITypes.Duration, ].includes(uiDatatype.value), ) - const isManualSaved = computed(() => - [UITypes.Currency, UITypes.Year, UITypes.Time, UITypes.Duration].includes(uiDatatype.value), - ) + const isManualSaved = computed(() => [UITypes.Currency].includes(uiDatatype.value)) const isPrimary = computed(() => column.value?.pv) return {