diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte index d9425c961d..31a7307911 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/FilterEditor/FilterDrawer.svelte @@ -14,6 +14,7 @@ import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte" import { generate } from "shortid" import { getValidOperatorsForType, OperatorOptions } from "constants/lucene" + import { tables } from "stores/backend" export let schemaFields export let filters = [] @@ -23,9 +24,34 @@ const BannedTypes = ["link", "attachment", "formula", "json", "jsonarray"] - $: fieldOptions = (schemaFields ?? []) - .filter(field => !BannedTypes.includes(field.type)) - .map(field => field.name) + function getTableFields(linkField) { + const table = $tables.list.find(table => table._id === linkField.tableId) + if (!table) { + return [] + } + const linkFields = getFields(Object.values(table.schema), { + allowLinks: false, + }) + return linkFields.map(field => ({ + ...field, + name: `${linkField.name}.${field.name}`, + })) + } + + function getFields(fields, { allowLinks } = { allowLinks: true }) { + let fieldNames = fields.filter(field => !BannedTypes.includes(field.type)) + if (allowLinks) { + const linkFields = fields.filter(field => field.type === "link") + for (let linkField of linkFields) { + // only allow one depth of SQL relationship filtering + fieldNames = fieldNames.concat(getTableFields(linkField)) + } + } + return fieldNames + } + + $: enrichedSchemaFields = getFields(schemaFields || []) + $: fieldOptions = enrichedSchemaFields.map(field => field.name) || [] $: valueTypeOptions = allowBindings ? ["Value", "Binding"] : ["Value"] const addFilter = () => { @@ -53,7 +79,7 @@ const onFieldChange = (expression, field) => { // Update the field type - expression.type = schemaFields.find(x => x.name === field)?.type + expression.type = enrichedSchemaFields.find(x => x.name === field)?.type // Ensure a valid operator is set const validOperators = getValidOperatorsForType(expression.type).map( @@ -85,7 +111,7 @@ } const getFieldOptions = field => { - const schema = schemaFields.find(x => x.name === field) + const schema = enrichedSchemaFields.find(x => x.name === field) return schema?.constraints?.inclusion || [] }