From c9abb0148e1d5842c45a7b34efc4e9c1cc467a64 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 20 Oct 2021 14:51:44 +0100 Subject: [PATCH] Fix view filters not accounting for invalid column names --- .../DataTable/modals/FilterModal.svelte | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte b/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte index 9c6f4956b0..12e5f23814 100644 --- a/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/FilterModal.svelte @@ -82,34 +82,30 @@ function isMultipleChoice(field) { return ( - (viewTable.schema[field].constraints && - viewTable.schema[field].constraints.inclusion && - viewTable.schema[field].constraints.inclusion.length) || - viewTable.schema[field].type === "boolean" + viewTable.schema[field]?.constraints?.inclusion?.length || + viewTable.schema[field]?.type === "boolean" ) } function fieldOptions(field) { - return viewTable.schema[field].type === "options" - ? viewTable.schema[field].constraints.inclusion + return viewTable.schema[field]?.type === "options" + ? viewTable.schema[field]?.constraints.inclusion : [true, false] } function isDate(field) { - return viewTable.schema[field].type === "datetime" + return viewTable.schema[field]?.type === "datetime" } function isNumber(field) { - return viewTable.schema[field].type === "number" + return viewTable.schema[field]?.type === "number" } const fieldChanged = filter => ev => { - // reset if type changed - if ( - filter.key && - ev.detail && - viewTable.schema[filter.key].type !== viewTable.schema[ev.detail].type - ) { + // Reset if type changed + const oldType = viewTable.schema[filter.key]?.type + const newType = viewTable.schema[ev.detail]?.type + if (filter.key && ev.detail && oldType !== newType) { filter.value = "" } }