From c91c0edefe88344746d7638b75cd8a4569e585a6 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 19 Nov 2022 16:46:36 +0800 Subject: [PATCH 1/4] fix(nocodb): remove ignoreFilterSort condition for applyPaginate and rename to ignoreViewFilterAndSort --- .../sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 5c07bb1e2e..6b31c79d9b 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -175,7 +175,7 @@ class BaseModelSqlv2 { sortArr?: Sort[]; sort?: string | string[]; } = {}, - ignoreFilterSort = false + ignoreViewFilterAndSort = false ): Promise { const { where, ...rest } = this._getListArgs(args as any); @@ -189,7 +189,7 @@ class BaseModelSqlv2 { let sorts = extractSortsObject(rest?.sort, aliasColObjMap); const filterObj = extractFilterFromXwhere(where, aliasColObjMap); // todo: replace with view id - if (!ignoreFilterSort && this.viewId) { + if (!ignoreViewFilterAndSort && this.viewId) { await conditionV2( [ new Filter({ @@ -249,7 +249,7 @@ class BaseModelSqlv2 { qb.orderBy('created_at'); } - if (!ignoreFilterSort) applyPaginate(qb, rest); + applyPaginate(qb, rest); const proto = await this.getProto(); const data = await this.extractRawQueryAndExec(qb); @@ -261,7 +261,7 @@ class BaseModelSqlv2 { public async count( args: { where?: string; limit?; filterArr?: Filter[] } = {}, - ignoreFilterSort = false + ignoreViewFilterAndSort = false ): Promise { await this.model.getColumns(); const { where } = this._getListArgs(args); @@ -272,7 +272,7 @@ class BaseModelSqlv2 { const aliasColObjMap = await this.model.getAliasColObjMap(); const filterObj = extractFilterFromXwhere(where, aliasColObjMap); - if (!ignoreFilterSort && this.viewId) { + if (!ignoreViewFilterAndSort && this.viewId) { await conditionV2( [ new Filter({ @@ -2474,7 +2474,7 @@ class BaseModelSqlv2 { public async groupedList( args: { groupColumnId: string; - ignoreFilterSort?: boolean; + ignoreViewFilterAndSort?: boolean; options?: (string | number | null | boolean)[]; } & Partial ): Promise< @@ -2527,7 +2527,7 @@ class BaseModelSqlv2 { let sorts = extractSortsObject(args?.sort, aliasColObjMap); const filterObj = extractFilterFromXwhere(where, aliasColObjMap); // todo: replace with view id - if (!args.ignoreFilterSort && this.viewId) { + if (!args.ignoreViewFilterAndSort && this.viewId) { await conditionV2( [ new Filter({ @@ -2640,7 +2640,10 @@ class BaseModelSqlv2 { } public async groupedListCount( - args: { groupColumnId: string; ignoreFilterSort?: boolean } & XcFilter + args: { + groupColumnId: string; + ignoreViewFilterAndSort?: boolean; + } & XcFilter ) { const column = await this.model .getColumns() @@ -2659,7 +2662,7 @@ class BaseModelSqlv2 { const filterObj = extractFilterFromXwhere(args.where, aliasColObjMap); // todo: replace with view id - if (!args.ignoreFilterSort && this.viewId) { + if (!args.ignoreViewFilterAndSort && this.viewId) { await conditionV2( [ new Filter({ From 501292cead98e472be6eea204edfb19bfcd68eb0 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Sat, 19 Nov 2022 16:47:19 +0800 Subject: [PATCH 2/4] fix(nc-gui): query field returns empty result with non-zero offset --- packages/nc-gui/composables/useViewData.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/nc-gui/composables/useViewData.ts b/packages/nc-gui/composables/useViewData.ts index 706ab27c57..c4e5bedbff 100644 --- a/packages/nc-gui/composables/useViewData.ts +++ b/packages/nc-gui/composables/useViewData.ts @@ -189,6 +189,14 @@ export function useViewData( : await fetchSharedViewData({ sortsArr: sorts.value, filtersArr: nestedFilters.value }) formattedData.value = formatData(response.list) paginationData.value = response.pageInfo + + // to cater the case like when querying with a non-zero offset + // the result page may point to the target page where the actual returned data don't display on + const expectedPage = Math.ceil(paginationData.value.totalRows! / paginationData.value.pageSize!) + if (Math.max(1, expectedPage) < paginationData.value.page!) { + await changePage(expectedPage) + } + if (viewMeta.value?.type === ViewTypes.GRID) { await loadAggCommentsCount() } From 11555d974379f3d04160312a8a90a830437aa6e5 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 21 Nov 2022 12:40:36 +0800 Subject: [PATCH 3/4] fix(nocodb): applyPaginate when ignoreViewFilterAndSort is false --- .../nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts index 6b31c79d9b..9eb5c1cfa2 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts @@ -249,7 +249,7 @@ class BaseModelSqlv2 { qb.orderBy('created_at'); } - applyPaginate(qb, rest); + if (!ignoreViewFilterAndSort) applyPaginate(qb, rest); const proto = await this.getProto(); const data = await this.extractRawQueryAndExec(qb); From 545c5875bbeff009569e7e8bd4cd8c92b19e3b25 Mon Sep 17 00:00:00 2001 From: Wing-Kam Wong Date: Mon, 21 Nov 2022 12:40:53 +0800 Subject: [PATCH 4/4] fix(nc-gui): expectedPage logic --- packages/nc-gui/composables/useViewData.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/composables/useViewData.ts b/packages/nc-gui/composables/useViewData.ts index c4e5bedbff..7b25a42123 100644 --- a/packages/nc-gui/composables/useViewData.ts +++ b/packages/nc-gui/composables/useViewData.ts @@ -192,8 +192,8 @@ export function useViewData( // to cater the case like when querying with a non-zero offset // the result page may point to the target page where the actual returned data don't display on - const expectedPage = Math.ceil(paginationData.value.totalRows! / paginationData.value.pageSize!) - if (Math.max(1, expectedPage) < paginationData.value.page!) { + const expectedPage = Math.max(1, Math.ceil(paginationData.value.totalRows! / paginationData.value.pageSize!)) + if (expectedPage < paginationData.value.page!) { await changePage(expectedPage) }