From 102f4bf1d47883aaf12fed1db7ea4dc9ff0527eb Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 28 Apr 2021 14:57:52 +0100 Subject: [PATCH] Stripping out conjunction in view filter if its the first one. --- .../server/src/api/controllers/view/viewBuilder.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index e9fa29856d..ed1199fa5b 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -62,8 +62,11 @@ const SCHEMA_MAP = { function parseFilterExpression(filters) { const expression = [] + let first = true for (let filter of filters) { - if (filter.conjunction) expression.push(TOKEN_MAP[filter.conjunction]) + if (!first && filter.conjunction) { + expression.push(TOKEN_MAP[filter.conjunction]) + } if (filter.condition === "CONTAINS") { expression.push( @@ -77,6 +80,7 @@ function parseFilterExpression(filters) { `doc["${filter.key}"] ${TOKEN_MAP[filter.condition]} ${value}` ) } + first = false } return expression.join(" ") @@ -104,6 +108,10 @@ function parseEmitExpression(field, groupBy) { * calculation: an optional calculation to be performed over the view data. */ function viewTemplate({ field, tableId, groupBy, filters = [], calculation }) { + // first filter can't have a conjuction + if (filters && filters.length > 0 && filters[0].conjunction) { + delete filters[0].conjunction + } const parsedFilters = parseFilterExpression(filters) const filterExpression = parsedFilters ? `&& ${parsedFilters}` : ""