From 701cf04083fea7d921d4b8ed5be76e1360a7f817 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 1 Dec 2022 17:42:22 +0530 Subject: [PATCH 1/2] fix(gui): avoid clearing cell data if it's a non-typable column Signed-off-by: Pranav C --- .../composables/useMultiSelect/index.ts | 20 ++---------- packages/nc-gui/utils/columnUtils.ts | 31 ++++++++++++++++++- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index dd4e645609..39273f9036 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -4,6 +4,7 @@ import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk' import type { Cell } from './cellRange' import { CellRange } from './cellRange' import convertCellData from './convertCellData' +import { isTypableInputColumn } from '~/utils' import type { Row } from '~/lib' import { copyTable, @@ -248,22 +249,7 @@ export function useMultiSelect( const columnObj = unref(fields)[selectedCell.col] - if ( - (!unref(editEnabled) || - [ - UITypes.DateTime, - UITypes.Date, - UITypes.Year, - UITypes.Time, - UITypes.Lookup, - UITypes.Rollup, - UITypes.Formula, - UITypes.Attachment, - UITypes.Checkbox, - UITypes.Rating, - ].includes(columnObj.uidt as UITypes)) && - (isMac() ? e.metaKey : e.ctrlKey) - ) { + if ((!unref(editEnabled) || !isTypableInputColumn(columnObj)) && (isMac() ? e.metaKey : e.ctrlKey)) { switch (e.keyCode) { // copy - ctrl/cmd +c case 67: @@ -350,7 +336,7 @@ export function useMultiSelect( // Update not allowed for table which doesn't have primary Key return message.info(t('msg.info.updateNotAllowedWithoutPK')) } - if (makeEditable(rowObj, columnObj) && columnObj.title) { + if (isTypableInputColumn(columnObj) && makeEditable(rowObj, columnObj) && columnObj.title) { rowObj.row[columnObj.title] = '' } // editEnabled = true diff --git a/packages/nc-gui/utils/columnUtils.ts b/packages/nc-gui/utils/columnUtils.ts index 565498e2c6..4f73ff0c63 100644 --- a/packages/nc-gui/utils/columnUtils.ts +++ b/packages/nc-gui/utils/columnUtils.ts @@ -190,4 +190,33 @@ const getUniqueColumnName = (initName: string, columns: ColumnType[]) => { return name } -export { uiTypes, getUIDTIcon, getUniqueColumnName, isColumnRequiredAndNull, isColumnRequired, isVirtualColRequired } +const isTypableInputColumn = (colOrUidt: ColumnType | UITypes) => { + let uidt: UITypes; + if (typeof colOrUidt === 'object') { + uidt = colOrUidt.uidt as UITypes + } else { + uidt = colOrUidt + } + return [ + UITypes.LongText, + UITypes.SingleLineText, + UITypes.Number, + UITypes.PhoneNumber, + UITypes.Email, + UITypes.Decimal, + UITypes.Currency, + UITypes.Percent, + UITypes.Duration, + UITypes.JSON, + ].includes(uidt) +} + +export { + uiTypes, + isTypableInputColumn, + getUIDTIcon, + getUniqueColumnName, + isColumnRequiredAndNull, + isColumnRequired, + isVirtualColRequired, +} From 10be0190a9bc6483725862e5e72b2ff87c0bd8b8 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 1 Dec 2022 20:03:31 +0530 Subject: [PATCH 2/2] chore: lint Signed-off-by: Pranav C --- packages/nc-gui/composables/useMultiSelect/index.ts | 2 +- packages/nc-gui/utils/columnUtils.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 39273f9036..a4c1024df5 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -4,13 +4,13 @@ import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk' import type { Cell } from './cellRange' import { CellRange } from './cellRange' import convertCellData from './convertCellData' -import { isTypableInputColumn } from '~/utils' import type { Row } from '~/lib' import { copyTable, extractPkFromRow, extractSdkResponseErrorMsg, isMac, + isTypableInputColumn, message, reactive, ref, diff --git a/packages/nc-gui/utils/columnUtils.ts b/packages/nc-gui/utils/columnUtils.ts index 4f73ff0c63..54569a8cea 100644 --- a/packages/nc-gui/utils/columnUtils.ts +++ b/packages/nc-gui/utils/columnUtils.ts @@ -191,7 +191,7 @@ const getUniqueColumnName = (initName: string, columns: ColumnType[]) => { } const isTypableInputColumn = (colOrUidt: ColumnType | UITypes) => { - let uidt: UITypes; + let uidt: UITypes if (typeof colOrUidt === 'object') { uidt = colOrUidt.uidt as UITypes } else {