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. 163
      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) {

163
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,66 +975,121 @@ 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[] },
) => { ) => {
const rowObj = unref(data)[activeCell.row] if (paginationDataRef.value?.pageSize === pg?.pageSize) {
const columnObj = unref(fields)[activeCell.col] if (paginationDataRef.value?.page !== pg?.page) {
await changePage?.(pg?.page!)
await Promise.all([ }
result.link.length && const pasteRowPk = extractPkFromRow(row.row, meta.value?.columns as ColumnType[])
api.dbDataTableRow.nestedLink(tableId, columnId, encodeURIComponent(pasteRowPk), result.link, { const rowObj = unref(data)[activeCell.row]
viewId: activeView?.value?.id, const columnObj = unref(fields)[activeCell.col]
}), if (
result.unlink.length && pasteRowPk === extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]) &&
api.dbDataTableRow.nestedUnlink( columnObj.id === col.id
meta.value?.id as string, ) {
columnObj.id as string, await Promise.all([
encodeURIComponent(pasteRowPk), result.link.length &&
result.unlink, api.dbDataTableRow.nestedLink(
{ viewId: activeView?.value?.id }, meta.value?.id as string,
), columnObj.id as string,
]) encodeURIComponent(pasteRowPk),
result.link,
rowObj.row[columnObj.title!] = value {
viewId: activeView?.value?.id,
await syncCellData?.(activeCell) },
),
result.unlink.length &&
api.dbDataTableRow.nestedUnlink(
meta.value?.id as string,
columnObj.id as string,
encodeURIComponent(pasteRowPk),
result.unlink,
{ viewId: activeView?.value?.id },
),
])
rowObj.row[columnObj.title!] = value
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[] },
) => { ) => {
const rowObj = unref(data)[activeCell.row] if (paginationDataRef.value?.pageSize === pg.pageSize) {
const columnObj = unref(fields)[activeCell.col] if (paginationDataRef.value?.page !== pg.page) {
await changePage?.(pg.page!)
await Promise.all([ }
result.unlink.length &&
api.dbDataTableRow.nestedLink(tableId, columnId, encodeURIComponent(pasteRowPk), result.unlink), const pasteRowPk = extractPkFromRow(row.row, meta.value?.columns as ColumnType[])
result.link.length && const rowObj = unref(data)[activeCell.row]
api.dbDataTableRow.nestedUnlink( const columnObj = unref(fields)[activeCell.col]
meta.value?.id as string,
columnObj.id as string, if (
encodeURIComponent(pasteRowPk), pasteRowPk === extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]) &&
result.link, columnObj.id === col.id
), ) {
]) await Promise.all([
result.unlink.length &&
rowObj.row[columnObj.title!] = value api.dbDataTableRow.nestedLink(
meta.value?.id as string,
await syncCellData?.(activeCell) columnObj.id as string,
encodeURIComponent(pasteRowPk),
result.unlink,
),
result.link.length &&
api.dbDataTableRow.nestedUnlink(
meta.value?.id as string,
columnObj.id as string,
encodeURIComponent(pasteRowPk),
result.link,
),
])
rowObj.row[columnObj.title!] = value
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