From 941b23fcc03592337ed5cbc7865bdfb7344bb255 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 20 Oct 2021 22:18:15 +0530 Subject: [PATCH] fix: predefined filter in shared grid view Signed-off-by: Pranav C --- .../nocodb/src/lib/noco/meta/NcMetaMgrEE.ts | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts b/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts index 8c7da4b732..33a57d3670 100644 --- a/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts +++ b/packages/nocodb/src/lib/noco/meta/NcMetaMgrEE.ts @@ -170,8 +170,50 @@ export default class NcMetaMgrEE extends NcMetaMgr { where += req.query.where; } - if (queryParams.where) { - where += where ? `~and(${queryParams.where})` : queryParams.where; + // todo: move this logic to a common library + const privateViewWhere = queryParams.filters?.reduce?.( + (condition, filt, i) => { + if (!i && !filt.logicOp) { + return condition; + } + if (!(filt.field && filt.op)) { + return condition; + } + + condition += i ? `~${filt.logicOp}` : ''; + switch (filt.op) { + case 'is equal': + return condition + `(${filt.field},eq,${filt.value})`; + case 'is not equal': + return condition + `~not(${filt.field},eq,${filt.value})`; + case 'is like': + return condition + `(${filt.field},like,%${filt.value}%)`; + case 'is not like': + return condition + `~not(${filt.field},like,%${filt.value}%)`; + case 'is empty': + return condition + `(${filt.field},in,)`; + case 'is not empty': + return condition + `~not(${filt.field},in,)`; + case 'is null': + return condition + `(${filt.field},is,null)`; + case 'is not null': + return condition + `~not(${filt.field},is,null)`; + case '<': + return condition + `(${filt.field},lt,${filt.value})`; + case '<=': + return condition + `(${filt.field},le,${filt.value})`; + case '>': + return condition + `(${filt.field},gt,${filt.value})`; + case '>=': + return condition + `(${filt.field},ge,${filt.value})`; + } + return condition; + }, + '' + ); + + if (privateViewWhere) { + where += where ? `~and(${privateViewWhere})` : privateViewWhere; } if (queryParams.sortList) { sort.push(