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
աӄա 12 months 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,
);
if (!sorts)
sorts = args.sortArr?.length
? args.sortArr
: await Sort.list({ viewId: this.viewId });
if (!sorts) {
if (args.sortArr?.length) {
sorts = args.sortArr;
} else if (this.viewId) {
sorts = await Sort.list({ viewId: this.viewId });
}
}
// 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
for (const sort of sorts) {
for (const sort of sorts || []) {
if (!groupByColumns[sort.fk_column_id]) {
continue;
}

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

@ -381,12 +381,13 @@ export default class Model implements TableType {
viewId?: string;
dbDriver: XKnex;
model?: Model;
extractDefaultView?: boolean;
},
ncMeta = Noco.ncMeta,
): Promise<BaseModelSqlv2> {
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);
args.viewId = view.id;
}

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

@ -163,7 +163,7 @@ export class DatasService {
} catch (e) {}
const [count, data] = await Promise.all([
baseModel.count(listArgs),
baseModel.count(listArgs, false, param.throwErrorIfInvalidParams),
(async () => {
let data = [];
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 { getView, updateView } from '../../factory/view';
import init from '../../init';
import type { Column, Model, Base, View } from '../../../../src/models';
import type { Base, Column, Model, View } from '../../../../src/models';
import 'mocha';
function groupByTests() {
@ -226,7 +226,9 @@ function groupByTests() {
],
});
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)
.query({
column_name: _lengthColumn.column_name,

Loading…
Cancel
Save