From 0da029c8969bde4f7392fc2bc9d05a133598ef91 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Oct 2023 17:35:36 +0200 Subject: [PATCH] Sanitise field --- .../controls/FilterEditor/FilterDrawer.svelte | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte index 7c9b603069..ab0c8d124e 100644 --- a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte @@ -146,7 +146,7 @@ filter.noValue = noValueOptions.includes(filter.operator) } - const santizeValue = filter => { + const santizeValue = (filter, previousType) => { // Check if the operator allows a value at all if (filter.noValue) { filter.value = null @@ -160,13 +160,20 @@ } } else if (filter.type === "array" && filter.valueType === "Value") { filter.value = [] + } else if ( + previousType !== filter.type && + previousType === FieldType.BB_REFERENCE && + filter.type === FieldType.BB_REFERENCE + ) { + filter.value = filter.type === "array" ? [] : null } } const onFieldChange = filter => { + const previousType = filter.type santizeTypes(filter) santizeOperator(filter) - santizeValue(filter) + santizeValue(filter, previousType) } const onOperatorChange = filter => { @@ -185,18 +192,21 @@ const getValidOperatorsForType = filter => { const fieldSchema = getSchema(filter) - if (!fieldSchema) { + if (!filter) { return [] } - const type = - fieldSchema.type !== FieldType.BB_REFERENCE - ? field.type - : { - type: fieldSchema.type, - multiple: - fieldSchema.relationshipType === RelationshipType.MANY_TO_MANY, - } + let type = filter.type + if (type === FieldType.BB_REFERENCE) { + const fieldSchema = getSchema(filter) + if (fieldSchema) { + type = { + type: fieldSchema.type, + multiple: + fieldSchema.relationshipType === RelationshipType.MANY_TO_MANY, + } + } + } const operators = LuceneUtils.getValidOperatorsForType( type,