Browse Source

Merge pull request #6941 from nocodb/fix/avoid-applying-default-view-filter

fix: Avoid applying default view filter and sort if viewId is not passed
pull/6962/head
աӄա 1 year ago committed by GitHub
parent
commit
78cae5c2e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      packages/nocodb/src/db/BaseModelSqlv2.ts
  2. 3
      packages/nocodb/src/models/Model.ts
  3. 2
      packages/nocodb/src/services/datas.service.ts
  4. 6
      packages/nocodb/tests/unit/rest/tests/groupby.test.ts

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

@ -655,14 +655,17 @@ class BaseModelSqlv2 {
qb, qb,
); );
if (!sorts) if (!sorts) {
sorts = args.sortArr?.length if (args.sortArr?.length) {
? args.sortArr sorts = args.sortArr;
: await Sort.list({ viewId: this.viewId }); } else if (this.viewId) {
sorts = await Sort.list({ viewId: this.viewId });
}
}
// if sort is provided filter out the group by columns sort and apply // if sort is provided filter out the group by columns sort and apply
// since we are grouping by the column and applying sort on any other column is not required // since we are grouping by the column and applying sort on any other column is not required
for (const sort of sorts) { for (const sort of sorts || []) {
if (!groupByColumns[sort.fk_column_id]) { if (!groupByColumns[sort.fk_column_id]) {
continue; continue;
} }

3
packages/nocodb/src/models/Model.ts

@ -381,12 +381,13 @@ export default class Model implements TableType {
viewId?: string; viewId?: string;
dbDriver: XKnex; dbDriver: XKnex;
model?: Model; model?: Model;
extractDefaultView?: boolean;
}, },
ncMeta = Noco.ncMeta, ncMeta = Noco.ncMeta,
): Promise<BaseModelSqlv2> { ): Promise<BaseModelSqlv2> {
const model = args?.model || (await this.get(args.id, ncMeta)); const model = args?.model || (await this.get(args.id, ncMeta));
if (!args?.viewId) { if (!args?.viewId && args.extractDefaultView) {
const view = await View.getDefaultView(model.id, ncMeta); const view = await View.getDefaultView(model.id, ncMeta);
args.viewId = view.id; args.viewId = view.id;
} }

2
packages/nocodb/src/services/datas.service.ts

@ -163,7 +163,7 @@ export class DatasService {
} catch (e) {} } catch (e) {}
const [count, data] = await Promise.all([ const [count, data] = await Promise.all([
baseModel.count(listArgs), baseModel.count(listArgs, false, param.throwErrorIfInvalidParams),
(async () => { (async () => {
let data = []; let data = [];
try { try {

6
packages/nocodb/tests/unit/rest/tests/groupby.test.ts

@ -7,7 +7,7 @@ import { listRow } from '../../factory/row';
import { getTable } from '../../factory/table'; import { getTable } from '../../factory/table';
import { getView, updateView } from '../../factory/view'; import { getView, updateView } from '../../factory/view';
import init from '../../init'; import init from '../../init';
import type { Column, Model, Base, View } from '../../../../src/models'; import type { Base, Column, Model, View } from '../../../../src/models';
import 'mocha'; import 'mocha';
function groupByTests() { function groupByTests() {
@ -226,7 +226,9 @@ function groupByTests() {
], ],
}); });
const response = await request(context.app) const response = await request(context.app)
.get(`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/groupby`) .get(
`/api/v1/db/data/noco/${sakilaProject.id}/${filmTable.id}/views/${filmView.id}/groupby`,
)
.set('xc-auth', context.token) .set('xc-auth', context.token)
.query({ .query({
column_name: _lengthColumn.column_name, column_name: _lengthColumn.column_name,

Loading…
Cancel
Save