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<{ const props = defineProps<{
fields?: number fields?: number
rows?: number newRows?: number
currentPage?: number
nextPages?: number
modelValue: boolean modelValue: boolean
affectedRows?: number affectedRows?: number
}>() }>()
@ -32,6 +34,7 @@ const close = () => {
<template> <template>
<NcModal <NcModal
v-if="dialogShow"
v-model:visible="dialogShow" v-model:visible="dialogShow"
:show-separator="false" :show-separator="false"
:header="$t('activity.createTable')" :header="$t('activity.createTable')"
@ -39,18 +42,22 @@ const close = () => {
@keydown.esc="dialogShow = false" @keydown.esc="dialogShow = false"
> >
<div class="flex justify-between w-full text-base font-semibold mb-2 text-nc-content-gray-emphasis items-center"> <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>
<div data-testid="nc-expand-table-modal" class="flex flex-col"> <div data-testid="nc-expand-table-modal" class="flex flex-col">
<div v-if="(rows ?? 0) > 0" class="mb-4 nc-content-gray"> <div v-if="(nextPages ?? 0) > 0" class="mb-2 nc-content-gray">
To accommodate your pasted data, we need to insert {{ rows }} additional records 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>
<div v-if="(affectedRows ?? 0) < 0" class="mb-2 nc-content-gray"> <div v-else-if="(newRows ?? 0) > 0" class="mb-2 nc-content-gray">
The data you pasted will update {{ affectedRows }} records in subsequent pages. To accommodate your pasted data, we need to insert {{ newRows }} additional records
</div> </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 <a-radio
data-testid="nc-table-expand-yes" data-testid="nc-table-expand-yes"
:style="{ :style="{

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

@ -793,7 +793,7 @@ function scrollToRow(row?: number) {
const isOpen = ref(false) const isOpen = ref(false)
async function expandRows(rowCount: number, rowsAffected: number) { async function expandRows(rowCount: number, rowsUpdatedinCurrentPage: number, rowsUpdatedInNextPages: number) {
isOpen.value = true isOpen.value = true
const options = { const options = {
@ -801,18 +801,20 @@ async function expandRows(rowCount: number, rowsAffected: number) {
expand: true, expand: true,
} }
const closeDlg = () => {
isOpen.value = false
}
const { close } = useDialog(resolveComponent('DlgExpandTable'), { const { close } = useDialog(resolveComponent('DlgExpandTable'), {
'modelValue': isOpen, 'modelValue': isOpen,
'rows': rowCount, 'newRows': rowCount,
'affectedRows': rowsAffected, 'currentPage': rowsUpdatedinCurrentPage,
'nextPages': rowsUpdatedInNextPages,
'onUpdate:expand': closeDialog, 'onUpdate:expand': closeDialog,
'onUpdate:modelValue': closeDlg, 'onUpdate:modelValue': closeDlg,
}) })
function closeDlg() {
isOpen.value = false
close(1000)
}
async function closeDialog(expand: boolean) { async function closeDialog(expand: boolean) {
options.continue = true options.continue = true
options.expand = expand 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 unreffedData = unref(data).slice(activeCell.row, activeCell.row + selectionRowCount)
const rowsInCurrentPage = unref(data).length const rowsInCurrentPage = unref(data).length
const rowsAffectedInCurrentPage = Math.min(selectionRowCount, rowsInCurrentPage - activeCell.row) const recordsUpdatedInCurrentPage = Math.min(
const rowsAffectedInOtherPages = Math.max(0, selectionRowCount - rowsAffectedInCurrentPage) Math.min(selectionRowCount, rowsInCurrentPage - activeCell.row),
availableRowsToUpdate,
)
const recordsUpdatedInSubsequentPages = Math.max(0, availableRowsToUpdate - recordsUpdatedInCurrentPage)
let options = { let options = {
continue: false, continue: false,
expand: rowsToAdd > 0 || rowsAffectedInOtherPages > 0 || (rowsAffectedInOtherPages > 0 && rowsToAdd > 0), expand: rowsToAdd > 0 || recordsUpdatedInSubsequentPages > 0,
} }
if (options.expand) { if (options.expand) {
options = await expandRows(rowsToAdd, rowsAffectedInOtherPages) options = await expandRows(rowsToAdd, recordsUpdatedInCurrentPage, recordsUpdatedInSubsequentPages)
if (!options.continue) return if (!options.continue) return
} }

Loading…
Cancel
Save