Basic frontend work, getting it sending up search fields from tables with links.

This commit is contained in:
mike12345567 2022-01-13 15:59:04 +00:00
parent 7e73d4bfd2
commit 90859cfe18
1 changed files with 31 additions and 5 deletions

View File

@ -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 || []
}
</script>