Browse Source

fix: duplicate rows

nc-expand-rows
DarkPhoenix2704 1 month ago
parent
commit
ee2bff033a
  1. 39
      packages/nc-gui/components/smartsheet/grid/Table.vue
  2. 49
      packages/nc-gui/composables/useMultiSelect/index.ts

39
packages/nc-gui/components/smartsheet/grid/Table.vue

@ -793,27 +793,12 @@ function scrollToRow(row?: number) {
const isOpen = ref(false) const isOpen = ref(false)
async function expandRows({ async function expandRows(rowCount: number) {
expandedRows, isOpen.value = true
updatedRows,
propsToPaste, const options = {
}: { continue: false,
expandedRows?: Row[] expand: true,
updatedRows: Row[]
propsToPaste: any
}) {
async function closeDialog(expand: boolean) {
close()
if (expand) {
await bulkUpsertRows?.(expandedRows!, updatedRows, propsToPaste)
} else {
await bulkUpdateRows?.(updatedRows, propsToPaste)
}
}
if (expandedRows?.length) {
isOpen.value = true
} else {
await bulkUpsertRows?.(expandedRows!, updatedRows, propsToPaste)
} }
const closeDlg = () => { const closeDlg = () => {
@ -822,12 +807,20 @@ async function expandRows({
const { close } = useDialog(resolveComponent('DlgExpandTable'), { const { close } = useDialog(resolveComponent('DlgExpandTable'), {
'modelValue': isOpen, 'modelValue': isOpen,
'rows': expandedRows!.length, 'rows': rowCount,
'onUpdate:expand': closeDialog, 'onUpdate:expand': closeDialog,
'onUpdate:modelValue': closeDlg, 'onUpdate:modelValue': closeDlg,
}) })
await until(() => isOpen.value).toBeTruthy() async function closeDialog(expand: boolean) {
options.continue = true
options.expand = expand
close(1000)
}
await until(isOpen).toBe(false)
return options
} }
async function saveEmptyRow(rowObj: Row) { async function saveEmptyRow(rowObj: Row) {

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

@ -854,33 +854,43 @@ export function useMultiSelect(
const colsToPaste = unref(fields).slice(activeCell.col, activeCell.col + pasteMatrixCols) const colsToPaste = unref(fields).slice(activeCell.col, activeCell.col + pasteMatrixCols)
const rowsToPaste = unref(data).slice(activeCell.row, activeCell.row + selectionRowCount) const rowsToPaste = unref(data).slice(activeCell.row, activeCell.row + selectionRowCount)
let options = {
continue: false,
expand: true,
}
if (pasteMatrixRows > rowsToPaste.length) { if (pasteMatrixRows > rowsToPaste.length) {
rowsToPaste.push( rowsToPaste.push(
...Array(pasteMatrixRows - rowsToPaste.length).fill({ ...Array(pasteMatrixRows - rowsToPaste.length)
row: {}, .fill({})
oldRow: {}, .map(() => ({
rowMeta: { row: {},
isExpandedData: true, oldRow: {},
}, rowMeta: {
}), isExpandedData: true,
},
})),
) )
options = await expandRows(pasteMatrixRows - rowsToPaste.length)
if (!options.continue) {
return
}
} }
const propsToPaste: string[] = [] const propsToPaste: string[] = []
let pastedRows = 0 let pastedRows = 0
let isInfoShown = false let isInfoShown = false
for (let i = 0; i < pasteMatrixRows; i++) { for (const pasteRow of rowsToPaste) {
const pasteRow = rowsToPaste[i]
// TODO handle insert new row
if (!pasteRow || pasteRow.rowMeta.new) break if (!pasteRow || pasteRow.rowMeta.new) break
pastedRows++ pastedRows++
for (let j = 0; j < pasteMatrixCols; j++) { let colIndex = 0
const pasteCol = colsToPaste[j]
for (const pasteCol of colsToPaste) {
if (!isPasteable(pasteRow, pasteCol)) { if (!isPasteable(pasteRow, pasteCol)) {
if ((isBt(pasteCol) || isOo(pasteCol) || isMm(pasteCol)) && !isInfoShown) { if ((isBt(pasteCol) || isOo(pasteCol) || isMm(pasteCol)) && !isInfoShown) {
message.info(t('msg.info.groupPasteIsNotSupportedOnLinksColumn')) message.info(t('msg.info.groupPasteIsNotSupportedOnLinksColumn'))
@ -894,7 +904,7 @@ export function useMultiSelect(
const pasteValue = convertCellData( const pasteValue = convertCellData(
{ {
// Repeat the clipboard data array if the matrix is smaller than the selection // Repeat the clipboard data array if the matrix is smaller than the selection
value: clipboardMatrix[i % clipboardMatrix.length][j], value: clipboardMatrix[pastedRows % clipboardMatrix.length][colIndex],
to: pasteCol.uidt as UITypes, to: pasteCol.uidt as UITypes,
column: pasteCol, column: pasteCol,
appInfo: unref(appInfo), appInfo: unref(appInfo),
@ -907,6 +917,7 @@ export function useMultiSelect(
if (pasteValue !== undefined) { if (pasteValue !== undefined) {
pasteRow.row[pasteCol.title!] = pasteValue pasteRow.row[pasteCol.title!] = pasteValue
} }
colIndex++
} }
} }
@ -914,11 +925,11 @@ export function useMultiSelect(
const updatedRows = rowsToPaste.filter((row) => !row.rowMeta.isExpandedData) const updatedRows = rowsToPaste.filter((row) => !row.rowMeta.isExpandedData)
await expandRows({ if (options.expand) {
expandedRows, await bulkUpsertRows?.(expandedRows!, updatedRows, propsToPaste)
updatedRows, } else {
propsToPaste, await bulkUpdateRows?.(updatedRows, propsToPaste)
}) }
if (pastedRows > 0) { if (pastedRows > 0) {
// highlight the pasted range // highlight the pasted range

Loading…
Cancel
Save