From ad59db19f83529cfeff3518914068e1b876d2efd Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Fri, 11 Oct 2024 16:17:47 +0000 Subject: [PATCH] fix: handle paste and specific row --- packages/nc-gui/composables/useData.ts | 5 ++--- packages/nc-gui/composables/useMultiSelect/index.ts | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/nc-gui/composables/useData.ts b/packages/nc-gui/composables/useData.ts index 1260e6ca38..f23c6c1663 100644 --- a/packages/nc-gui/composables/useData.ts +++ b/packages/nc-gui/composables/useData.ts @@ -167,7 +167,6 @@ export function useData(args: { try { // Identify the rows that need to be fetched from the server - const rowsToFetch = updateRows.filter((row) => row.rowMeta?.isExistingRow) const pagesToFetch = Array.from(new Set(rowsToFetch.map((row) => row.rowMeta.page))).filter( (page): page is number => page !== undefined && page !== paginationData.value.page, @@ -187,8 +186,8 @@ export function useData(args: { const getPk = (row: Row) => extractPkFromRow(row.row, metaValue?.columns as ColumnType[]) const ogUpdateRows = updateRows.map((row) => { - if (row.rowMeta?.page && row.rowMeta.page !== paginationData.value.page) { - const fetchedRow = fetchedData[row.rowMeta.page]?.[row.rowMeta.rowInPage!] + if (row.rowMeta?.isExistingRow) { + const fetchedRow = fetchedData[row.rowMeta.page!]?.[row.rowMeta.rowInPage!] return fetchedRow ? clone(fetchedRow) : row } const currentPageRow = formattedData.value.find((formattedRow) => getPk(formattedRow) === getPk(row)) diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 13b26b74dc..a908b0c743 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -857,6 +857,8 @@ export function useMultiSelect( const availableRowsToUpdate = Math.max(0, totalRows - totalRowsBeforeActiveCell) const rowsToAdd = Math.max(0, selectionRowCount - availableRowsToUpdate) + const unreffedData = unref(data).slice(activeCell.row, activeCell.row + selectionRowCount) + const rowsInCurrentPage = unref(data).length const rowsAffectedInCurrentPage = Math.min(selectionRowCount, rowsInCurrentPage - activeCell.row) const rowsAffectedInOtherPages = Math.max(0, selectionRowCount - rowsAffectedInCurrentPage) @@ -882,8 +884,8 @@ export function useMultiSelect( if (i < availableRowsToUpdate) { const absoluteRowIndex = totalRowsBeforeActiveCell + i targetRow = - i < unref(data).length - ? unref(data)[i] + i < unreffedData.length + ? unreffedData[i] : { row: {}, oldRow: {},