Browse Source

fix: keep hidden fields on undo

pull/7779/head
mertmit 9 months ago
parent
commit
9e74b682b5
  1. 40
      packages/nc-gui/composables/useData.ts
  2. 21
      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 })),
)

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

@ -426,7 +426,24 @@ class BaseModelSqlv2 {
if (createdCol) qb.orderBy(createdCol.column_name);
}
if (!ignorePagination) applyPaginate(qb, rest);
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) {
applyPaginate(qb, rest);
} else {
applyPaginate(qb, { ...rest, limit: calendarLimitOverride });
}
}
const proto = await this.getProto();
let data;
@ -2114,6 +2131,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;
}
@ -6382,6 +6400,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

@ -7503,6 +7503,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

@ -9040,6 +9040,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"
}
@ -12348,6 +12356,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"
@ -15914,6 +15930,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