Browse Source

Merge pull request #7779 from nocodb/nc-fix/undo-hidden

fix: keep hidden fields on undo
pull/7795/head
Pranav C 10 months ago committed by GitHub
parent
commit
6a2fb92310
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 40
      packages/nc-gui/composables/useData.ts
  2. 12
      packages/nocodb/src/db/BaseModelSqlv2.ts
  3. 1
      packages/nocodb/src/db/sql-data-mapper/lib/BaseModel.ts
  4. 8
      packages/nocodb/src/schema/swagger-v2.json
  5. 24
      packages/nocodb/src/schema/swagger.json

40
packages/nc-gui/composables/useData.ts

@ -559,6 +559,19 @@ export function useData(args: {
.map((c) => row.row[c.title!])
.join('___')
const fullRecord = await $api.dbTableRow.read(
NOCO,
// todo: base_id missing on view type
base?.value.id as string,
meta.value?.id as string,
encodeURIComponent(id as string),
{
getHiddenColumn: true,
},
)
row.row = fullRecord
const deleted = await deleteRowById(id as string)
if (!deleted) {
return
@ -584,6 +597,7 @@ export function useData(args: {
pg: { page: number; pageSize: number },
) {
const pkData = rowPkData(row.row, meta.value?.columns as ColumnType[])
row.row = { ...pkData, ...row.row }
await insertRow(row, ltarState, {}, true)
recoverLTARRefs(row.row)
@ -642,7 +656,20 @@ export function useData(args: {
if (!removedRowsData.length) return
const { list } = await $api.dbTableRow.list(NOCO, base?.value.id as string, meta.value?.id as string, {
pks: removedRowsData.map((row) => row[compositePrimaryKey]).join(','),
})
try {
for (const removedRow of removedRowsData) {
const rowObj = removedRow.row
const rowPk = rowPkData(rowObj.row, meta?.value?.columns as ColumnType[])
const fullRecord = list.find((r: Record<string, any>) => {
return Object.keys(rowPk).every((key) => rowPk[key] === r[key])
})
rowObj.row = clone(fullRecord)
}
const removedRowIds: Record<string, any>[] = await bulkDeleteRows(
removedRowsData.map((row) => ({ [compositePrimaryKey]: row[compositePrimaryKey] as string })),
)
@ -767,7 +794,20 @@ export function useData(args: {
if (!removedRowsData.length) return
const { list } = await $api.dbTableRow.list(NOCO, base?.value.id as string, meta.value?.id as string, {
pks: removedRowsData.map((row) => row[compositePrimaryKey]).join(','),
})
try {
for (const removedRow of removedRowsData) {
const rowObj = removedRow.row
const rowPk = rowPkData(rowObj.row, meta?.value?.columns as ColumnType[])
const fullRecord = list.find((r: Record<string, any>) => {
return Object.keys(rowPk).every((key) => rowPk[key] === r[key])
})
rowObj.row = clone(fullRecord)
}
const removedRowIds: Record<string, any>[] = await bulkDeleteRows(
removedRowsData.map((row) => ({ [compositePrimaryKey]: row[compositePrimaryKey] as string })),
)

12
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -429,6 +429,16 @@ class BaseModelSqlv2 {
if (createdCol) qb.orderBy(createdCol.column_name);
}
if (rest.pks) {
const pks = rest.pks.split(',');
qb.where((qb) => {
pks.forEach((pk) => {
qb.orWhere(_wherePk(this.model.primaryKeys, pk));
});
return qb;
});
}
// For calendar View, if calendarLimitOverride is provided, use it as limit for the query
if (!ignorePagination) {
if (!calendarLimitOverride) {
@ -2124,6 +2134,7 @@ class BaseModelSqlv2 {
obj.offset = Math.max(+(args.offset || args.o) || 0, 0);
obj.fields = args.fields || args.f;
obj.sort = args.sort || args.s;
obj.pks = args.pks;
return obj;
}
@ -6392,6 +6403,7 @@ export function getListArgs(
obj.fields =
args?.fields || args?.f || (ignoreAssigningWildcardSelect ? null : '*');
obj.sort = args?.sort || args?.s || model.primaryKey?.[0]?.column_name;
obj.pks = args?.pks;
return obj;
}

1
packages/nocodb/src/db/sql-data-mapper/lib/BaseModel.ts

@ -1514,6 +1514,7 @@ export interface XcFilter {
fields?: string;
filterArr?: Filter[];
sortArr?: Sort[];
pks?: string;
}
export interface XcFilterWithAlias extends XcFilter {

8
packages/nocodb/src/schema/swagger-v2.json

@ -7688,6 +7688,14 @@
"in": "query",
"name": "filterArrJson",
"description": "Used for multiple filter queries"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "pks",
"description": "Comma separated list of pks"
}
],
"description": "List all shared view rows"

24
packages/nocodb/src/schema/swagger.json

@ -9051,6 +9051,14 @@
"name": "filterArrJson",
"description": "Used for multiple filter queries"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "pks",
"description": "Comma separated list of pks"
},
{
"$ref": "#/components/parameters/xc-auth"
}
@ -12772,6 +12780,14 @@
"in": "query",
"name": "filterArrJson",
"description": "Used for multiple filter queries"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "pks",
"description": "Comma separated list of pks"
}
],
"description": "List all shared view rows"
@ -16338,6 +16354,14 @@
"name": "filterArrJson",
"description": "Used for multiple filter queries"
},
{
"schema": {
"type": "string"
},
"in": "query",
"name": "pks",
"description": "Comma separated list of pks"
},
{
"$ref": "#/components/parameters/xc-auth"
}

Loading…
Cancel
Save