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)
async function expandRows({
expandedRows,
updatedRows,
propsToPaste,
}: {
expandedRows?: Row[]
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)
async function expandRows(rowCount: number) {
isOpen.value = true
const options = {
continue: false,
expand: true,
}
const closeDlg = () => {
@ -822,12 +807,20 @@ async function expandRows({
const { close } = useDialog(resolveComponent('DlgExpandTable'), {
'modelValue': isOpen,
'rows': expandedRows!.length,
'rows': rowCount,
'onUpdate:expand': closeDialog,
'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) {

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

Loading…
Cancel
Save