Browse Source

fix(gui): handle invalid data when copying belongs to cell data

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4514/head
Pranav C 2 years ago
parent
commit
e8e503500f
  1. 31
      packages/nc-gui/composables/useMultiSelect/convertCellData.ts
  2. 34
      packages/nc-gui/composables/useMultiSelect/index.ts

31
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
}
}

34
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,

Loading…
Cancel
Save