diff --git a/packages/nc-gui/composables/useViewGroupBy.ts b/packages/nc-gui/composables/useViewGroupBy.ts index caa4d6642f..1c6ea8fddb 100644 --- a/packages/nc-gui/composables/useViewGroupBy.ts +++ b/packages/nc-gui/composables/useViewGroupBy.ts @@ -150,13 +150,13 @@ export const useViewGroupBy = (view: Ref, where?: Computed const calculateNestedWhere = (nestedIn: GroupNestedIn[], existing = '') => { return nestedIn.reduce((acc, curr) => { if (curr.key === GROUP_BY_VARS.NULL) { - acc += `${acc.length ? '~and' : ''}(${curr.title},blank)` + acc += `${acc.length ? '~and' : ''}(${curr.title},gb_null)` } else if (curr.column_uidt === UITypes.Checkbox) { acc += `${acc.length ? '~and' : ''}(${curr.title},${curr.key === GROUP_BY_VARS.TRUE ? 'checked' : 'notchecked'})` } else if ([UITypes.Date, UITypes.DateTime].includes(curr.column_uidt as UITypes)) { acc += `${acc.length ? '~and' : ''}(${curr.title},eq,exactDate,${curr.key})` } else { - acc += `${acc.length ? '~and' : ''}(${curr.title},gb_val,${curr.key})` + acc += `${acc.length ? '~and' : ''}(${curr.title},gb_eq,${curr.key})` } return acc }, existing) diff --git a/packages/nocodb/src/db/BaseModelSqlv2.ts b/packages/nocodb/src/db/BaseModelSqlv2.ts index 780056ced5..35571e1cfa 100644 --- a/packages/nocodb/src/db/BaseModelSqlv2.ts +++ b/packages/nocodb/src/db/BaseModelSqlv2.ts @@ -59,6 +59,7 @@ import { HANDLE_WEBHOOK } from '~/services/hook-handler.service'; import { COMPARISON_OPS, COMPARISON_SUB_OPS, + GROUPBY_COMPARISON_OPS, IS_WITHIN_COMPARISON_SUB_OPS, } from '~/utils/globals'; import { extractProps } from '~/helpers/extractProps'; @@ -5284,7 +5285,7 @@ export function extractFilterFromXwhere( // mark `op` and `sub_op` any for being assignable to parameter of type function validateFilterComparison(uidt: UITypes, op: any, sub_op?: any) { - if (!COMPARISON_OPS.includes(op)) { + if (!COMPARISON_OPS.includes(op) && !GROUPBY_COMPARISON_OPS.includes(op)) { NcError.badRequest(`${op} is not supported.`); } diff --git a/packages/nocodb/src/db/conditionV2.ts b/packages/nocodb/src/db/conditionV2.ts index e2cda40f82..2f236429d8 100644 --- a/packages/nocodb/src/db/conditionV2.ts +++ b/packages/nocodb/src/db/conditionV2.ts @@ -116,9 +116,13 @@ const parseConditionV2 = async ( }; } else { // handle group by filter separately, - // `gb_val` is equivalent to `eq` but for lookup it compares on aggregated value returns in group by api + // `gb_eq` is equivalent to `eq` but for lookup it compares on aggregated value returns in group by api // aggregated value will be either json array or `___` separated string - if (filter.comparison_op === 'gb_val') { + // `gb_null` is equivalent to `blank` but for lookup it compares on aggregated value is null + if ( + filter.comparison_op === 'gb_eq' || + filter.comparison_op === 'gb_null' + ) { const column = await filter.getColumn(); if ( column.uidt === UITypes.Lookup || @@ -133,10 +137,13 @@ const parseConditionV2 = async ( getAlias: getAliasGenerator('__gb_filter_lk'), }); return (qb) => { - qb.where(knex.raw('?', [filter.value]), lkQb.builder); + if (filter.comparison_op === 'gb_eq') + qb.where(knex.raw('?', [filter.value]), lkQb.builder); + else qb.whereNull(knex.raw(lkQb.builder).wrap('(', ')')); }; } else { - filter.comparison_op = 'eq'; + filter.comparison_op = + filter.comparison_op === 'gb_eq' ? 'eq' : 'blank'; // if qrCode or Barcode replace it with value column if ([UITypes.QrCode, UITypes.Barcode].includes(column.uidt)) filter.fk_column_id = await column diff --git a/packages/nocodb/src/db/generateLookupSelectQuery.ts b/packages/nocodb/src/db/generateLookupSelectQuery.ts index aa7fba5679..09187d1fdc 100644 --- a/packages/nocodb/src/db/generateLookupSelectQuery.ts +++ b/packages/nocodb/src/db/generateLookupSelectQuery.ts @@ -32,7 +32,7 @@ export default async function generateLookupSelectQuery({ column, baseModelSqlv2, alias, - model, + model: _model, getAlias = getAliasGenerator('__lk_slt_'), }: { column: Column; diff --git a/packages/nocodb/src/utils/globals.ts b/packages/nocodb/src/utils/globals.ts index 2602637916..f3bce47faf 100644 --- a/packages/nocodb/src/utils/globals.ts +++ b/packages/nocodb/src/utils/globals.ts @@ -171,7 +171,12 @@ export enum CacheDelDirection { CHILD_TO_PARENT = 'CHILD_TO_PARENT', } -export const COMPARISON_OPS = [ +export const GROUPBY_COMPARISON_OPS = [ + // these are used for groupby + 'gb_eq', + 'gb_null', +]; +export const COMPARISON_OPS = ([ 'eq', 'neq', 'not', @@ -201,9 +206,7 @@ export const COMPARISON_OPS = [ 'isWithin', 'btw', 'nbtw', - - 'gb_val' -] as any; +]) as any; export const IS_WITHIN_COMPARISON_SUB_OPS = [ 'pastWeek',