diff --git a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts new file mode 100644 index 0000000000..47c81656e9 --- /dev/null +++ b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts @@ -0,0 +1,31 @@ +import { UITypes } from 'nocodb-sdk' + +export default +function convertCellData(args: { from: UITypes; to: UITypes; value: any }) { + const { from, to, value } = args + if (from === to) { + return value + } + + switch (to) { + case UITypes.Number: + return Number(value) + case UITypes.Checkbox: + return Boolean(value) + case UITypes.Date: + return new Date(value) + case UITypes.Attachment: + try { + return typeof value === 'string' ? JSON.parse(value) : value + } catch (e) { + return [] + } + case UITypes.LinkToAnotherRecord: + case UITypes.Lookup: + case UITypes.Rollup: + case UITypes.Formula: + throw new Error(`Unsupported conversion from ${from} to ${to}`) + default: + return value + } +} diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 6f223e03fa..58fafe78a6 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -3,40 +3,12 @@ import type { ColumnType, LinkToAnotherRecordType, TableType } from 'nocodb-sdk' import { RelationTypes, UITypes, isVirtualCol } from 'nocodb-sdk' import type { Cell } from './cellRange' import { CellRange } from './cellRange' +import convertCellData from '~/composables/useMultiSelect/convertCellData' import { useMetas } from '~/composables/useMetas' import { extractPkFromRow } from '~/utils' import { copyTable, message, reactive, ref, unref, useCopy, useEventListener, useI18n } from '#imports' import type { Row } from '~/lib' -function convertCellData(args: { from: UITypes; to: UITypes; value: any }) { - const { from, to, value } = args - if (from === to) { - return value - } - - switch (to) { - case UITypes.Number: - return Number(value) - case UITypes.Checkbox: - return Boolean(value) - case UITypes.Date: - return new Date(value) - case UITypes.Attachment: - try { - return typeof value === 'string' ? JSON.parse(value) : value - } catch (e) { - return [] - } - case UITypes.LinkToAnotherRecord: - case UITypes.Lookup: - case UITypes.Rollup: - case UITypes.Formula: - throw new Error(`Unsupported conversion from ${from} to ${to}`) - default: - return value - } -} - /** * Utility to help with multi-selecting rows/cells in the smartsheet */ @@ -278,6 +250,10 @@ export function useMultiSelect( columnObj.uidt === UITypes.LinkToAnotherRecord && (columnObj.colOptions as LinkToAnotherRecordType)?.type === RelationTypes.BELONGS_TO ) { + if (!clipboardContext.value || typeof clipboardContext.value !== 'object') { + return message.info('Invalid data') + } + rowObj.row[columnObj.title!] = convertCellData({ value: clipboardContext.value, from: clipboardContext.uidt,