From 27015ebd1798f3fd3ca3925891dd39eae31b5858 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Thu, 1 Oct 2020 16:55:17 +0100 Subject: [PATCH] fix: view filter handle bool, number & date --- .../database/DataTable/popovers/Filter.svelte | 17 ++++++++++++----- .../src/api/controllers/view/viewBuilder.js | 5 ++++- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/components/database/DataTable/popovers/Filter.svelte b/packages/builder/src/components/database/DataTable/popovers/Filter.svelte index e7ecdcb8b6..ad602768b0 100644 --- a/packages/builder/src/components/database/DataTable/popovers/Filter.svelte +++ b/packages/builder/src/components/database/DataTable/popovers/Filter.svelte @@ -81,11 +81,18 @@ function isMultipleChoice(field) { return ( - viewModel.schema[field].constraints && - viewModel.schema[field].constraints.inclusion && - viewModel.schema[field].constraints.inclusion.length + (viewModel.schema[field].constraints && + viewModel.schema[field].constraints.inclusion && + viewModel.schema[field].constraints.inclusion.length) || + viewModel.schema[field].type === "boolean" ) } + + function fieldOptions(field) { + return viewModel.schema[field].type === "string" + ? viewModel.schema[field].constraints.inclusion + : [true, false] + }
@@ -126,8 +133,8 @@ {#if filter.key && isMultipleChoice(filter.key)} {:else} diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index 6ac3fdb0f2..036f68ecc6 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -61,8 +61,11 @@ function parseFilterExpression(filters) { `doc["${filter.key}"].${TOKEN_MAP[filter.condition]}("${filter.value}")` ) } else { + const value = + typeof filter.value == "string" ? `"${filter.value}"` : filter.value + expression.push( - `doc["${filter.key}"] ${TOKEN_MAP[filter.condition]} "${filter.value}"` + `doc["${filter.key}"] ${TOKEN_MAP[filter.condition]} ${value}` ) } }