diff --git a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts index de2384972c..082e2dde82 100644 --- a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts +++ b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts @@ -7,6 +7,7 @@ import { parseProp } from '#imports' export default function convertCellData( args: { to: UITypes; value: string; column: ColumnType; appInfo: AppInfo }, isMysql = false, + isMultiple = false, ) { const { to, value, column } = args @@ -16,14 +17,22 @@ export default function convertCellData( case UITypes.Number: { const parsedNumber = Number(value) if (isNaN(parsedNumber)) { - throw new TypeError(`Cannot convert '${value}' to number`) + if (isMultiple) { + return null + } else { + throw new TypeError(`Cannot convert '${value}' to number`) + } } return parsedNumber } case UITypes.Rating: { const parsedNumber = Number(value ?? 0) if (isNaN(parsedNumber)) { - throw new TypeError(`Cannot convert '${value}' to rating`) + if (isMultiple) { + return null + } else { + throw new TypeError(`Cannot convert '${value}' to rating`) + } } return parsedNumber } @@ -37,13 +46,23 @@ export default function convertCellData( return Boolean(value) case UITypes.Date: { const parsedDate = dayjs(value) - if (!parsedDate.isValid()) throw new Error('Not a valid date') + if (!parsedDate.isValid()) { + if (isMultiple) { + return null + } else { + throw new Error('Not a valid date') + } + } return parsedDate.format('YYYY-MM-DD') } case UITypes.DateTime: { const parsedDateTime = dayjs(value) if (!parsedDateTime.isValid()) { - throw new Error('Not a valid datetime value') + if (isMultiple) { + return null + } else { + throw new Error('Not a valid datetime value') + } } return parsedDateTime.utc().format('YYYY-MM-DD HH:mm:ssZ') } @@ -57,7 +76,11 @@ export default function convertCellData( parsedTime = dayjs(`1999-01-01 ${value}`) } if (!parsedTime.isValid()) { - throw new Error('Not a valid time value') + if (isMultiple) { + return null + } else { + throw new Error('Not a valid time value') + } } return parsedTime.format(dateFormat) } @@ -72,7 +95,11 @@ export default function convertCellData( return parsedDate.format('YYYY') } - throw new Error('Not a valid year value') + if (isMultiple) { + return null + } else { + throw new Error('Not a valid year value') + } } case UITypes.Attachment: { let parsedVal @@ -80,12 +107,17 @@ export default function convertCellData( parsedVal = parseProp(value) parsedVal = Array.isArray(parsedVal) ? parsedVal : [parsedVal] } catch (e) { - console.error('Invalid attachment value', e) - return null + if (isMultiple) { + return null + } else { + throw new Error('Invalid attachment data') + } } + if (parsedVal.some((v: any) => v && !(v.url || v.data || v.path))) { return null } + // TODO(refactor): duplicate logic in attachment/utils.ts const defaultAttachmentMeta = { ...(args.appInfo.ee && { @@ -156,8 +188,13 @@ export default function convertCellData( case UITypes.Lookup: case UITypes.Rollup: case UITypes.Formula: - case UITypes.QrCode: - throw new Error(`Unsupported conversion for ${to}`) + case UITypes.QrCode: { + if (isMultiple) { + return undefined + } else { + throw new Error(`Unsupported conversion for ${to}`) + } + } default: return value } diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index d7d41a00ec..04de637650 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -536,7 +536,7 @@ export function useMultiSelect( propsToPaste.push(pasteCol.title!) - pasteRow.row[pasteCol.title!] = convertCellData( + const pasteValue = convertCellData( { value: clipboardMatrix[i][j], to: pasteCol.uidt as UITypes, @@ -544,7 +544,12 @@ export function useMultiSelect( appInfo: unref(appInfo), }, isMysql(meta.value?.base_id), + true, ) + + if (pasteValue !== undefined) { + pasteRow.row[pasteCol.title!] = pasteValue + } } } await bulkUpdateRows?.(rowsToPaste, propsToPaste) @@ -588,7 +593,7 @@ export function useMultiSelect( return message.info(t('msg.info.pasteNotSupported')) } - rowObj.row[columnObj.title!] = convertCellData( + const pasteValue = convertCellData( { value: clipboardData, to: columnObj.uidt as UITypes, @@ -598,6 +603,10 @@ export function useMultiSelect( isMysql(meta.value?.base_id), ) + if (pasteValue !== undefined) { + rowObj.row[columnObj.title!] = pasteValue + } + await syncCellData?.(activeCell) } } catch (error: any) {