Add settings to dynamic filter to control button text and allowed filter fields
This commit is contained in:
parent
038ec39143
commit
b47a25a273
|
@ -2631,6 +2631,18 @@
|
||||||
"type": "dataProvider",
|
"type": "dataProvider",
|
||||||
"label": "Provider",
|
"label": "Provider",
|
||||||
"key": "dataProvider"
|
"key": "dataProvider"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "multifield",
|
||||||
|
"label": "Allowed filter fields",
|
||||||
|
"key": "allowedFields",
|
||||||
|
"placeholder": "All fields"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"label": "Button text",
|
||||||
|
"key": "buttonText",
|
||||||
|
"defaultValue": "Edit filters"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
@ -4,17 +4,32 @@
|
||||||
import FilterModal from "./FilterModal.svelte"
|
import FilterModal from "./FilterModal.svelte"
|
||||||
|
|
||||||
export let dataProvider
|
export let dataProvider
|
||||||
|
export let allowedFields
|
||||||
|
export let buttonText
|
||||||
|
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
const { styleable } = getContext("sdk")
|
const { styleable } = getContext("sdk")
|
||||||
|
|
||||||
$: schema = dataProvider?.schema
|
|
||||||
$: schemaFields = Object.values(schema || {})
|
|
||||||
|
|
||||||
let modal
|
let modal
|
||||||
let tmpFilters = []
|
let tmpFilters = []
|
||||||
let filters = []
|
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 = () => {
|
const openEditor = () => {
|
||||||
tmpFilters = [...filters]
|
tmpFilters = [...filters]
|
||||||
modal.show()
|
modal.show()
|
||||||
|
@ -26,11 +41,11 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div use:styleable={$component.styles}>
|
<div use:styleable={$component.styles}>
|
||||||
<Button on:click={openEditor} secondary icon="FilterEdit">
|
<Button on:click={openEditor} secondary>
|
||||||
Edit filters
|
{text}
|
||||||
</Button>
|
</Button>
|
||||||
<Modal bind:this={modal}>
|
<Modal bind:this={modal}>
|
||||||
<ModalContent title="Edit filters" size="XL" onConfirm={updateQuery}>
|
<ModalContent title={text} size="XL" onConfirm={updateQuery}>
|
||||||
<FilterModal bind:filters={tmpFilters} {schemaFields} />
|
<FilterModal bind:filters={tmpFilters} {schemaFields} />
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
Loading…
Reference in New Issue