Browse Source

fix: support null filter

pull/6987/head
Pranav C 11 months ago
parent
commit
d181ce78b7
  1. 4
      packages/nc-gui/composables/useViewGroupBy.ts
  2. 3
      packages/nocodb/src/db/BaseModelSqlv2.ts
  3. 15
      packages/nocodb/src/db/conditionV2.ts
  4. 2
      packages/nocodb/src/db/generateLookupSelectQuery.ts
  5. 11
      packages/nocodb/src/utils/globals.ts

4
packages/nc-gui/composables/useViewGroupBy.ts

@ -150,13 +150,13 @@ export const useViewGroupBy = (view: Ref<ViewType | undefined>, 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)

3
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.`);
}

15
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

2
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;

11
packages/nocodb/src/utils/globals.ts

@ -171,7 +171,12 @@ export enum CacheDelDirection {
CHILD_TO_PARENT = 'CHILD_TO_PARENT',
}
export const COMPARISON_OPS = <const>[
export const GROUPBY_COMPARISON_OPS = <const>[
// these are used for groupby
'gb_eq',
'gb_null',
];
export const COMPARISON_OPS = (<const>[
'eq',
'neq',
'not',
@ -201,9 +206,7 @@ export const COMPARISON_OPS = <const>[
'isWithin',
'btw',
'nbtw',
'gb_val'
] as any;
]) as any;
export const IS_WITHIN_COMPARISON_SUB_OPS = <const>[
'pastWeek',

Loading…
Cancel
Save