Basic frontend work, getting it sending up search fields from tables with links.
This commit is contained in:
parent
69105afffb
commit
e70e923112
|
@ -14,6 +14,7 @@
|
||||||
import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte"
|
import ClientBindingPanel from "components/common/bindings/ClientBindingPanel.svelte"
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
import { getValidOperatorsForType, OperatorOptions } from "constants/lucene"
|
import { getValidOperatorsForType, OperatorOptions } from "constants/lucene"
|
||||||
|
import { tables } from "stores/backend"
|
||||||
|
|
||||||
export let schemaFields
|
export let schemaFields
|
||||||
export let filters = []
|
export let filters = []
|
||||||
|
@ -23,9 +24,34 @@
|
||||||
|
|
||||||
const BannedTypes = ["link", "attachment", "formula", "json", "jsonarray"]
|
const BannedTypes = ["link", "attachment", "formula", "json", "jsonarray"]
|
||||||
|
|
||||||
$: fieldOptions = (schemaFields ?? [])
|
function getTableFields(linkField) {
|
||||||
.filter(field => !BannedTypes.includes(field.type))
|
const table = $tables.list.find(table => table._id === linkField.tableId)
|
||||||
.map(field => field.name)
|
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"]
|
$: valueTypeOptions = allowBindings ? ["Value", "Binding"] : ["Value"]
|
||||||
|
|
||||||
const addFilter = () => {
|
const addFilter = () => {
|
||||||
|
@ -53,7 +79,7 @@
|
||||||
|
|
||||||
const onFieldChange = (expression, field) => {
|
const onFieldChange = (expression, field) => {
|
||||||
// Update the field type
|
// 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
|
// Ensure a valid operator is set
|
||||||
const validOperators = getValidOperatorsForType(expression.type).map(
|
const validOperators = getValidOperatorsForType(expression.type).map(
|
||||||
|
@ -85,7 +111,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const getFieldOptions = field => {
|
const getFieldOptions = field => {
|
||||||
const schema = schemaFields.find(x => x.name === field)
|
const schema = enrichedSchemaFields.find(x => x.name === field)
|
||||||
return schema?.constraints?.inclusion || []
|
return schema?.constraints?.inclusion || []
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue