Browse Source

fix: update the behaviour

nc-expand-rows
DarkPhoenix2704 1 month ago
parent
commit
9bb052b320
  1. 21
      packages/nc-gui/components/dlg/ExpandTable.vue
  2. 16
      packages/nc-gui/components/smartsheet/grid/Table.vue
  3. 11
      packages/nc-gui/composables/useMultiSelect/index.ts

21
packages/nc-gui/components/dlg/ExpandTable.vue

@ -3,7 +3,9 @@ import { onKeyDown } from '@vueuse/core'
const props = defineProps<{
fields?: number
rows?: number
newRows?: number
currentPage?: number
nextPages?: number
modelValue: boolean
affectedRows?: number
}>()
@ -32,6 +34,7 @@ const close = () => {
<template>
<NcModal
v-if="dialogShow"
v-model:visible="dialogShow"
:show-separator="false"
:header="$t('activity.createTable')"
@ -39,18 +42,22 @@ const close = () => {
@keydown.esc="dialogShow = false"
>
<div class="flex justify-between w-full text-base font-semibold mb-2 text-nc-content-gray-emphasis items-center">
Do you want to expand this table?
{{ (nextPages ?? 0) > 0 ? 'Confirm Record Overwrite ?' : 'Do you want to expand this table ?' }}
</div>
<div data-testid="nc-expand-table-modal" class="flex flex-col">
<div v-if="(rows ?? 0) > 0" class="mb-4 nc-content-gray">
To accommodate your pasted data, we need to insert {{ rows }} additional records
<div v-if="(nextPages ?? 0) > 0" class="mb-2 nc-content-gray">
This action will overwrite {{ currentPage }} records on the current page and {{ nextPages }} records on the subsequent
pages.
<br />
Are you sure you want to proceed with this action?
</div>
<div v-if="(affectedRows ?? 0) < 0" class="mb-2 nc-content-gray">
The data you pasted will update {{ affectedRows }} records in subsequent pages.
<div v-else-if="(newRows ?? 0) > 0" class="mb-2 nc-content-gray">
To accommodate your pasted data, we need to insert {{ newRows }} additional records
</div>
<a-radio-group v-if="(rows ?? 0) > 0" v-model:value="expand">
<a-radio-group v-if="(newRows ?? 0) > 0" v-model:value="expand">
<a-radio
data-testid="nc-table-expand-yes"
:style="{

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

@ -793,7 +793,7 @@ function scrollToRow(row?: number) {
const isOpen = ref(false)
async function expandRows(rowCount: number, rowsAffected: number) {
async function expandRows(rowCount: number, rowsUpdatedinCurrentPage: number, rowsUpdatedInNextPages: number) {
isOpen.value = true
const options = {
@ -801,18 +801,20 @@ async function expandRows(rowCount: number, rowsAffected: number) {
expand: true,
}
const closeDlg = () => {
isOpen.value = false
}
const { close } = useDialog(resolveComponent('DlgExpandTable'), {
'modelValue': isOpen,
'rows': rowCount,
'affectedRows': rowsAffected,
'newRows': rowCount,
'currentPage': rowsUpdatedinCurrentPage,
'nextPages': rowsUpdatedInNextPages,
'onUpdate:expand': closeDialog,
'onUpdate:modelValue': closeDlg,
})
function closeDlg() {
isOpen.value = false
close(1000)
}
async function closeDialog(expand: boolean) {
options.continue = true
options.expand = expand

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

@ -860,15 +860,18 @@ export function useMultiSelect(
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)
const recordsUpdatedInCurrentPage = Math.min(
Math.min(selectionRowCount, rowsInCurrentPage - activeCell.row),
availableRowsToUpdate,
)
const recordsUpdatedInSubsequentPages = Math.max(0, availableRowsToUpdate - recordsUpdatedInCurrentPage)
let options = {
continue: false,
expand: rowsToAdd > 0 || rowsAffectedInOtherPages > 0 || (rowsAffectedInOtherPages > 0 && rowsToAdd > 0),
expand: rowsToAdd > 0 || recordsUpdatedInSubsequentPages > 0,
}
if (options.expand) {
options = await expandRows(rowsToAdd, rowsAffectedInOtherPages)
options = await expandRows(rowsToAdd, recordsUpdatedInCurrentPage, recordsUpdatedInSubsequentPages)
if (!options.continue) return
}

Loading…
Cancel
Save