Browse Source

fix(nc-gui): mm cell redo undo issue

pull/7558/head
Ramesh Mane 9 months ago
parent
commit
0483af6b49
  1. 4
      packages/nc-gui/components/smartsheet/grid/Table.vue
  2. 93
      packages/nc-gui/composables/useMultiSelect/index.ts

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

@ -1,7 +1,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import axios from 'axios' import axios from 'axios'
import { nextTick } from '@vue/runtime-core' import { nextTick } from '@vue/runtime-core'
import { type ColumnReqType, type ColumnType, type PaginatedType, type TableType, type ViewType } from 'nocodb-sdk' import type { ColumnReqType, ColumnType, PaginatedType, TableType, ViewType } from 'nocodb-sdk'
import { import {
UITypes, UITypes,
ViewTypes, ViewTypes,
@ -756,6 +756,8 @@ const {
bulkUpdateRows, bulkUpdateRows,
fillHandle, fillHandle,
view, view,
paginationDataRef,
changePage,
) )
function scrollToRow(row?: number) { function scrollToRow(row?: number) {

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

@ -2,7 +2,7 @@ import type { Ref } from 'vue'
import { computed } from 'vue' import { computed } from 'vue'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import type { MaybeRef } from '@vueuse/core' import type { MaybeRef } from '@vueuse/core'
import type { ColumnType, LinkToAnotherRecordType, TableType, UserFieldRecordType, ViewType } from 'nocodb-sdk' import type { ColumnType, LinkToAnotherRecordType, PaginatedType, TableType, UserFieldRecordType, ViewType } from 'nocodb-sdk'
import { UITypes, dateFormats, isDateMonthFormat, isSystemColumn, isVirtualCol, timeFormats } from 'nocodb-sdk' import { UITypes, dateFormats, isDateMonthFormat, isSystemColumn, isVirtualCol, timeFormats } from 'nocodb-sdk'
import { parse } from 'papaparse' import { parse } from 'papaparse'
import type { Cell } from './cellRange' import type { Cell } from './cellRange'
@ -54,6 +54,8 @@ export function useMultiSelect(
bulkUpdateRows?: Function, bulkUpdateRows?: Function,
fillHandle?: MaybeRef<HTMLElement | undefined>, fillHandle?: MaybeRef<HTMLElement | undefined>,
view?: MaybeRef<ViewType | undefined>, view?: MaybeRef<ViewType | undefined>,
paginationData?: MaybeRef<PaginatedType | undefined>,
changePage?: (page: number) => void,
) { ) {
const meta = ref(_meta) const meta = ref(_meta)
@ -81,6 +83,8 @@ export function useMultiSelect(
const activeView = ref(view) const activeView = ref(view)
const paginationDataRef = ref(paginationData)
const selectedRange = reactive(new CellRange()) const selectedRange = reactive(new CellRange())
const fillRange = reactive(new CellRange()) const fillRange = reactive(new CellRange())
@ -971,21 +975,35 @@ export function useMultiSelect(
addUndo({ addUndo({
redo: { redo: {
fn: async ( fn: async (
tableId: string,
columnId: string,
pasteRowPk: string,
result: { link: any[]; unlink: any[] },
value: number,
activeCell: Cell, activeCell: Cell,
col: ColumnType,
row: Row,
pg: PaginatedType,
value: number,
result: { link: any[]; unlink: any[] },
) => { ) => {
if (paginationDataRef.value?.pageSize === pg?.pageSize) {
if (paginationDataRef.value?.page !== pg?.page) {
await changePage?.(pg?.page!)
}
const pasteRowPk = extractPkFromRow(row.row, meta.value?.columns as ColumnType[])
const rowObj = unref(data)[activeCell.row] const rowObj = unref(data)[activeCell.row]
const columnObj = unref(fields)[activeCell.col] const columnObj = unref(fields)[activeCell.col]
if (
pasteRowPk === extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]) &&
columnObj.id === col.id
) {
await Promise.all([ await Promise.all([
result.link.length && result.link.length &&
api.dbDataTableRow.nestedLink(tableId, columnId, encodeURIComponent(pasteRowPk), result.link, { api.dbDataTableRow.nestedLink(
meta.value?.id as string,
columnObj.id as string,
encodeURIComponent(pasteRowPk),
result.link,
{
viewId: activeView?.value?.id, viewId: activeView?.value?.id,
}), },
),
result.unlink.length && result.unlink.length &&
api.dbDataTableRow.nestedUnlink( api.dbDataTableRow.nestedUnlink(
meta.value?.id as string, meta.value?.id as string,
@ -999,24 +1017,52 @@ export function useMultiSelect(
rowObj.row[columnObj.title!] = value rowObj.row[columnObj.title!] = value
await syncCellData?.(activeCell) await syncCellData?.(activeCell)
} else {
throw new Error(t('msg.recordCouldNotBeFound'))
}
} else {
throw new Error(t('msg.pageSizeChanged'))
}
}, },
args: [meta.value?.id as string, columnObj.id as string, pasteRowPk, result, pasteVal.value, clone(activeCell)], args: [
clone(activeCell),
clone(columnObj),
clone(rowObj),
clone(paginationDataRef.value),
clone(pasteVal.value),
result,
],
}, },
undo: { undo: {
fn: async ( fn: async (
tableId: string,
columnId: string,
pasteRowPk: string,
result: { link: any[]; unlink: any[] },
value: number,
activeCell: Cell, activeCell: Cell,
col: ColumnType,
row: Row,
pg: PaginatedType,
value: number,
result: { link: any[]; unlink: any[] },
) => { ) => {
if (paginationDataRef.value?.pageSize === pg.pageSize) {
if (paginationDataRef.value?.page !== pg.page) {
await changePage?.(pg.page!)
}
const pasteRowPk = extractPkFromRow(row.row, meta.value?.columns as ColumnType[])
const rowObj = unref(data)[activeCell.row] const rowObj = unref(data)[activeCell.row]
const columnObj = unref(fields)[activeCell.col] const columnObj = unref(fields)[activeCell.col]
if (
pasteRowPk === extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]) &&
columnObj.id === col.id
) {
await Promise.all([ await Promise.all([
result.unlink.length && result.unlink.length &&
api.dbDataTableRow.nestedLink(tableId, columnId, encodeURIComponent(pasteRowPk), result.unlink), api.dbDataTableRow.nestedLink(
meta.value?.id as string,
columnObj.id as string,
encodeURIComponent(pasteRowPk),
result.unlink,
),
result.link.length && result.link.length &&
api.dbDataTableRow.nestedUnlink( api.dbDataTableRow.nestedUnlink(
meta.value?.id as string, meta.value?.id as string,
@ -1029,8 +1075,21 @@ export function useMultiSelect(
rowObj.row[columnObj.title!] = value rowObj.row[columnObj.title!] = value
await syncCellData?.(activeCell) await syncCellData?.(activeCell)
} else {
throw new Error(t('msg.recordCouldNotBeFound'))
}
} else {
throw new Error(t('msg.pageSizeChanged'))
}
}, },
args: [meta.value?.id as string, columnObj.id as string, pasteRowPk, result, oldCellValue, clone(activeCell)], args: [
clone(activeCell),
clone(columnObj),
clone(rowObj),
clone(paginationDataRef.value),
clone(oldCellValue),
result,
],
}, },
scope: defineViewScope({ view: activeView?.value }), scope: defineViewScope({ view: activeView?.value }),
}) })

Loading…
Cancel
Save