1
0
Fork 0
mirror of synced 2024-06-17 18:04:42 +12:00

Add settings to dynamic filter to control button text and allowed filter fields

This commit is contained in:
Andrew Kingston 2021-11-18 15:43:51 +00:00
parent 038ec39143
commit b47a25a273
2 changed files with 33 additions and 6 deletions

View file

@ -2631,6 +2631,18 @@
"type": "dataProvider",
"label": "Provider",
"key": "dataProvider"
},
{
"type": "multifield",
"label": "Allowed filter fields",
"key": "allowedFields",
"placeholder": "All fields"
},
{
"type": "text",
"label": "Button text",
"key": "buttonText",
"defaultValue": "Edit filters"
}
]
},

View file

@ -4,17 +4,32 @@
import FilterModal from "./FilterModal.svelte"
export let dataProvider
export let allowedFields
export let buttonText
const component = getContext("component")
const { styleable } = getContext("sdk")
$: schema = dataProvider?.schema
$: schemaFields = Object.values(schema || {})
let modal
let tmpFilters = []
let filters = []
$: schema = dataProvider?.schema
$: schemaFields = getSchemaFields(schema, allowedFields)
$: text = buttonText || "Edit filters"
const getSchemaFields = (schema, allowedFields) => {
let clonedSchema = {}
if (!allowedFields?.length) {
clonedSchema = schema
} else {
allowedFields?.forEach(field => {
clonedSchema[field] = schema[field]
})
}
return Object.values(clonedSchema || {})
}
const openEditor = () => {
tmpFilters = [...filters]
modal.show()
@ -26,11 +41,11 @@
</script>
<div use:styleable={$component.styles}>
<Button on:click={openEditor} secondary icon="FilterEdit">
Edit filters
<Button on:click={openEditor} secondary>
{text}
</Button>
<Modal bind:this={modal}>
<ModalContent title="Edit filters" size="XL" onConfirm={updateQuery}>
<ModalContent title={text} size="XL" onConfirm={updateQuery}>
<FilterModal bind:filters={tmpFilters} {schemaFields} />
</ModalContent>
</Modal>