From 02bfaa4378bcac6462ef1957a74a8276cfeeeb5f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Oct 2023 18:29:35 +0200 Subject: [PATCH 1/4] Clean multiple user checks to simplify --- .../controls/FilterEditor/FilterDrawer.svelte | 14 +------------ packages/shared-core/src/filters.ts | 21 +++---------------- 2 files changed, 4 insertions(+), 31 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 32211212d0..42a9d5773e 100644 --- a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte @@ -195,20 +195,8 @@ return [] } - 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, + filter.type, filter.field, datasource ) diff --git a/packages/shared-core/src/filters.ts b/packages/shared-core/src/filters.ts index 9f883d8f25..6ab8ce623e 100644 --- a/packages/shared-core/src/filters.ts +++ b/packages/shared-core/src/filters.ts @@ -12,22 +12,12 @@ import { deepGet } from "./helpers" const HBS_REGEX = /{{([^{].*?)}}/g -type RequestedFieldType = - | Exclude - | { type: FieldType.BB_REFERENCE; multiple: boolean } - -export function isFieldType( - r: RequestedFieldType -): r is Exclude { - return typeof r === "string" && Object.values(FieldType).includes(r) -} - /** * Returns the valid operator options for a certain data type * @param type the data type */ export const getValidOperatorsForType = ( - type: RequestedFieldType, + type: FieldType, field: string, datasource: Datasource & { tableId: any } // TODO: is this table id ever populated? ) => { @@ -70,13 +60,8 @@ export const getValidOperatorsForType = ( ops = numOps } else if (type === FieldType.FORMULA) { ops = stringOps.concat([Op.MoreThan, Op.LessThan]) - } else if (!isFieldType(type) && type.type === FieldType.BB_REFERENCE) { - if (type.multiple) { - // Temporally disabled - ops = [] - } else { - ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In] - } + } else if (type === FieldType.BB_REFERENCE) { + ops = [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.In] } // Only allow equal/not equal for _id in SQL tables From 2c20d0b7381c522350ce637350228a458c87908c Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 3 Oct 2023 17:33:58 +0100 Subject: [PATCH 2/4] Spelling fix. --- .../controls/FilterEditor/FilterDrawer.svelte | 40 +++++++++---------- 1 file changed, 19 insertions(+), 21 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 42a9d5773e..a31b5be38e 100644 --- a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte @@ -3,24 +3,24 @@ Body, Button, Combobox, - Multiselect, DatePicker, DrawerContent, Icon, Input, - Layout, - Select, Label, + Layout, + Multiselect, + Select, } from "@budibase/bbui" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte" - import { generate } from "shortid" - import { LuceneUtils, Constants } from "@budibase/frontend-core" - import { getFields } from "helpers/searchFields" - import { FieldType } from "@budibase/types" - import { createEventDispatcher, onMount } from "svelte" + import {generate} from "shortid" + import {Constants, LuceneUtils} from "@budibase/frontend-core" + import {getFields} from "helpers/searchFields" + import {FieldType} from "@budibase/types" + import {createEventDispatcher, onMount} from "svelte" import FilterUsers from "./FilterUsers.svelte" - import { RelationshipType } from "constants/backend" + import {RelationshipType} from "constants/backend" export let schemaFields export let filters = [] @@ -122,7 +122,7 @@ return enrichedSchemaFields.find(field => field.name === filter.field) } - const santizeTypes = filter => { + const sanitizeTypes = filter => { // Update type based on field const fieldSchema = enrichedSchemaFields.find(x => x.name === filter.field) filter.type = fieldSchema?.type @@ -131,7 +131,7 @@ filter.externalType = getSchema(filter)?.externalType } - const santizeOperator = filter => { + const sanitizeOperator = filter => { // Ensure a valid operator is selected const operators = getValidOperatorsForType(filter).map(x => x.value) if (!operators.includes(filter.operator)) { @@ -146,7 +146,7 @@ filter.noValue = noValueOptions.includes(filter.operator) } - const santizeValue = (filter, previousType) => { + const sanitizeValue = (filter, previousType) => { // Check if the operator allows a value at all if (filter.noValue) { filter.value = null @@ -171,18 +171,18 @@ const onFieldChange = filter => { const previousType = filter.type - santizeTypes(filter) - santizeOperator(filter) - santizeValue(filter, previousType) + sanitizeTypes(filter) + sanitizeOperator(filter) + sanitizeValue(filter, previousType) } const onOperatorChange = filter => { - santizeOperator(filter) - santizeValue(filter) + sanitizeOperator(filter) + sanitizeValue(filter) } const onValueTypeChange = filter => { - santizeValue(filter) + sanitizeValue(filter) } const getFieldOptions = field => { @@ -195,13 +195,11 @@ return [] } - const operators = LuceneUtils.getValidOperatorsForType( + return LuceneUtils.getValidOperatorsForType( filter.type, filter.field, datasource ) - - return operators } From 5eacc9d93e0f02498ca9b943bb6a4152c5eaab91 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 3 Oct 2023 17:34:20 +0100 Subject: [PATCH 3/4] Lint fix. --- .../controls/FilterEditor/FilterDrawer.svelte | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 a31b5be38e..8f8697d9e9 100644 --- a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte @@ -14,13 +14,13 @@ } from "@budibase/bbui" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte" - import {generate} from "shortid" - import {Constants, LuceneUtils} from "@budibase/frontend-core" - import {getFields} from "helpers/searchFields" - import {FieldType} from "@budibase/types" - import {createEventDispatcher, onMount} from "svelte" + import { generate } from "shortid" + import { Constants, LuceneUtils } from "@budibase/frontend-core" + import { getFields } from "helpers/searchFields" + import { FieldType } from "@budibase/types" + import { createEventDispatcher, onMount } from "svelte" import FilterUsers from "./FilterUsers.svelte" - import {RelationshipType} from "constants/backend" + import { RelationshipType } from "constants/backend" export let schemaFields export let filters = [] From e7b47d08bb98a69f6ccdd76689587f9ab87dc05b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 3 Oct 2023 18:36:58 +0200 Subject: [PATCH 4/4] Do not sanitize on operator change --- .../design/settings/controls/FilterEditor/FilterDrawer.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 8f8697d9e9..822442fcea 100644 --- a/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte +++ b/packages/builder/src/components/design/settings/controls/FilterEditor/FilterDrawer.svelte @@ -178,7 +178,7 @@ const onOperatorChange = filter => { sanitizeOperator(filter) - sanitizeValue(filter) + sanitizeValue(filter, filter.type) } const onValueTypeChange = filter => {