Browse Source

feat: fill using multiple select and paste

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5847/head
mertmit 1 year ago
parent
commit
dab3471bed
  1. 66
      packages/nc-gui/composables/useMultiSelect/index.ts

66
packages/nc-gui/composables/useMultiSelect/index.ts

@ -506,9 +506,6 @@ export function useMultiSelect(
const clipboardData = e.clipboardData?.getData('text/plain') || ''
const rowObj = unref(data)[activeCell.row]
const columnObj = unref(fields)[activeCell.col]
try {
if (clipboardData?.includes('\n') || clipboardData?.includes('\t')) {
// if the clipboard data contains new line or tab, then it is a matrix or LongText
@ -531,6 +528,7 @@ export function useMultiSelect(
for (let i = 0; i < pasteMatrixRows; i++) {
const pasteRow = rowsToPaste[i]
// TODO handle insert new row
if (pasteRow.rowMeta.new) break
@ -543,7 +541,7 @@ export function useMultiSelect(
continue
}
// skip pasting virtual columns for now
// skip pasting virtual columns (including LTAR columns for now)
if (isVirtualCol(pasteCol)) {
continue
}
@ -584,6 +582,10 @@ export function useMultiSelect(
selectedRange.endRange({ row: activeCell.row + pastedRows - 1, col: activeCell.col + pasteMatrixCols - 1 })
}
} else {
if (selectedRange.isSingleCell()) {
const rowObj = unref(data)[activeCell.row]
const columnObj = unref(fields)[activeCell.col]
// handle belongs to column
if (
columnObj.uidt === UITypes.LinkToAnotherRecord &&
@ -644,6 +646,62 @@ export function useMultiSelect(
}
await syncCellData?.(activeCell)
} else {
const start = selectedRange.start
const end = selectedRange.end
const startRow = Math.min(start.row, end.row)
const endRow = Math.max(start.row, end.row)
const startCol = Math.min(start.col, end.col)
const endCol = Math.max(start.col, end.col)
const cols = unref(fields).slice(startCol, endCol + 1)
const rows = unref(data).slice(startRow, endRow + 1)
const props = []
for (const row of rows) {
// TODO handle insert new row
if (row.rowMeta.new) continue
for (const col of cols) {
if (!row || !col || !col.title) continue
// skip pasting virtual columns (including LTAR columns for now)
if (isVirtualCol(col)) {
continue
}
// skip pasting auto increment columns
if (col.ai) {
continue
}
// skip pasting primary key columns
if (col.pk && !row.rowMeta.new) {
continue
}
props.push(col.title)
const pasteValue = convertCellData(
{
value: clipboardData,
to: col.uidt as UITypes,
column: col,
appInfo: unref(appInfo),
},
isMysql(meta.value?.base_id),
true,
)
if (pasteValue !== undefined) {
row.row[col.title] = pasteValue
}
}
}
await bulkUpdateRows?.(rows, props)
}
}
} catch (error: any) {
message.error(await extractSdkResponseErrorMsg(error))

Loading…
Cancel
Save