Browse Source

fix: bulk update only pasted columns

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5847/head
mertmit 1 year ago
parent
commit
33bbb383ee
  1. 7
      packages/nc-gui/composables/useMultiSelect/index.ts
  2. 19
      packages/nc-gui/composables/useViewData.ts

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

@ -390,6 +390,7 @@ export function useMultiSelect(
const colsToPaste = unref(fields).slice(activeCell.col, activeCell.col + pasteMatrixCols)
const rowsToPaste = unref(data).slice(activeCell.row, activeCell.row + pasteMatrixRows)
const propsToPaste: string[] = []
for (let i = 0; i < pasteMatrixRows; i++) {
const pasteRow = rowsToPaste[i]
@ -401,10 +402,12 @@ export function useMultiSelect(
}
// skip pasting virtual columns for now
if (isVirtualCol(columnObj)) {
if (isVirtualCol(pasteCol)) {
continue
}
propsToPaste.push(pasteCol.title!)
pasteRow.row[pasteCol.title!] = convertCellData(
{
value: pasteMatrix[i][j],
@ -416,7 +419,7 @@ export function useMultiSelect(
)
}
}
await bulkUpdateRows?.(rowsToPaste)
await bulkUpdateRows?.(rowsToPaste, propsToPaste)
} else {
// handle belongs to column
if (

19
packages/nc-gui/composables/useViewData.ts

@ -450,6 +450,7 @@ export function useViewData(
async function bulkUpdateRows(
rows: Row[],
props: string[],
{ metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {},
undo = false,
) {
@ -472,14 +473,19 @@ export function useViewData(
const pk = rowPkData(row.row, metaValue?.columns as ColumnType[])
updateArray.push({ ...row.row, ...pk })
const updateData = props.reduce((acc: Record<string, any>, prop) => {
acc[prop] = row.row[prop]
return acc
}, {} as Record<string, any>)
updateArray.push({ ...updateData, ...pk })
}
if (!undo) {
addUndo({
redo: {
fn: async function redo(redoRows: Row[], pg: { page: number; pageSize: number }) {
await bulkUpdateRows(redoRows, { metaValue, viewMetaValue }, true)
fn: async function redo(redoRows: Row[], props: string[], pg: { page: number; pageSize: number }) {
await bulkUpdateRows(redoRows, props, { metaValue, viewMetaValue }, true)
if (pg.page === paginationData.value.page && pg.pageSize === paginationData.value.pageSize) {
for (const toUpdate of redoRows) {
const rowIndex = findIndexByPk(rowPkData(toUpdate.row, meta?.value?.columns as ColumnType[]))
@ -496,11 +502,11 @@ export function useViewData(
await changePage(pg.page)
}
},
args: [clone(rows), { page: paginationData.value.page, pageSize: paginationData.value.pageSize }],
args: [clone(rows), clone(props), { page: paginationData.value.page, pageSize: paginationData.value.pageSize }],
},
undo: {
fn: async function undo(undoRows: Row[], pg: { page: number; pageSize: number }) {
await bulkUpdateRows(undoRows, { metaValue, viewMetaValue }, true)
fn: async function undo(undoRows: Row[], props: string[], pg: { page: number; pageSize: number }) {
await bulkUpdateRows(undoRows, props, { metaValue, viewMetaValue }, true)
if (pg.page === paginationData.value.page && pg.pageSize === paginationData.value.pageSize) {
for (const toUpdate of undoRows) {
const rowIndex = findIndexByPk(rowPkData(toUpdate.row, meta?.value?.columns as ColumnType[]))
@ -523,6 +529,7 @@ export function useViewData(
return { row: row.oldRow, oldRow: row.row, rowMeta: row.rowMeta }
}),
),
props,
{ page: paginationData.value.page, pageSize: paginationData.value.pageSize },
],
},

Loading…
Cancel
Save