Browse Source

fix(nc-gui): use composable instead of redefining

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/4114/head
mertmit 2 years ago
parent
commit
1c2c9d320a
  1. 55
      packages/nc-gui/components/smartsheet/Cell.vue
  2. 5
      packages/nc-gui/composables/useColumn.ts

55
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

5
packages/nc-gui/composables/useColumn.ts

@ -56,11 +56,10 @@ export function useColumn(column: Ref<ColumnType | undefined>) {
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 {

Loading…
Cancel
Save