Remove duplication

This commit is contained in:
Mel O'Hagan 2022-11-21 14:48:26 +00:00
parent 2a9266e22e
commit 9a3209cc56
4 changed files with 17 additions and 82 deletions

View File

@ -43,7 +43,7 @@ const componentMap = {
filter: FilterEditor, filter: FilterEditor,
url: URLSelect, url: URLSelect,
columns: ColumnEditor, columns: ColumnEditor,
allowedFields: BasicColumnEditor, "columns/basic": BasicColumnEditor,
"field/sortable": SortableFieldSelect, "field/sortable": SortableFieldSelect,
"field/string": FormFieldSelect, "field/string": FormFieldSelect,
"field/number": FormFieldSelect, "field/number": FormFieldSelect,

View File

@ -1,83 +1,12 @@
<script> <script>
import { Button, ActionButton, Drawer } from "@budibase/bbui" import ColumnEditor from "./ColumnEditor.svelte"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import ColumnDrawer from "./ColumnDrawer.svelte"
import { cloneDeep } from "lodash/fp"
import {
getDatasourceForProvider,
getSchemaForDatasource,
} from "builderStore/dataBinding"
import { currentAsset } from "builderStore"
export let componentInstance
export let value = []
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
let drawer
let boundValue
$: datasource = getDatasourceForProvider($currentAsset, componentInstance)
$: schema = getSchema($currentAsset, datasource)
$: options = Object.keys(schema || {})
$: sanitisedValue = getValidColumns(value, options)
$: updateBoundValue(sanitisedValue)
const getSchema = (asset, datasource) => {
const schema = getSchemaForDatasource(asset, datasource).schema
// Don't show ID and rev in tables
if (schema) {
delete schema._id
delete schema._rev
}
return schema
}
const updateBoundValue = value => {
boundValue = cloneDeep(value)
}
const getValidColumns = (columns, options) => {
if (!Array.isArray(columns) || !columns.length) {
return []
}
// We need to account for legacy configs which would just be an array
// of strings
if (typeof columns[0] === "string") {
columns = columns.map(col => ({
name: col,
displayName: col,
}))
}
return columns.filter(column => {
return options.includes(column.name)
})
}
const open = () => {
updateBoundValue(sanitisedValue)
drawer.show()
}
const save = () => {
dispatch("change", getValidColumns(boundValue, options))
drawer.hide()
}
</script> </script>
<ActionButton on:click={open}>Configure columns</ActionButton> <ColumnEditor
<Drawer bind:this={drawer} title="Dynamic Filter Columns"> {...$$props}
<svelte:fragment slot="description"> on:change={e => dispatch("change", e.detail)}
Configure the columns in your dynamic filter. allowCellEditing={false}
</svelte:fragment> />
<Button cta slot="buttons" on:click={save}>Save</Button>
<ColumnDrawer
slot="body"
bind:columns={boundValue}
{options}
{schema}
allowCellEditing={false}
/>
</Drawer>

View File

@ -11,6 +11,7 @@
export let componentInstance export let componentInstance
export let value = [] export let value = []
export let allowCellEditing = true
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -73,5 +74,11 @@
Configure the columns in your table. Configure the columns in your table.
</svelte:fragment> </svelte:fragment>
<Button cta slot="buttons" on:click={save}>Save</Button> <Button cta slot="buttons" on:click={save}>Save</Button>
<ColumnDrawer slot="body" bind:columns={boundValue} {options} {schema} /> <ColumnDrawer
slot="body"
bind:columns={boundValue}
{options}
{schema}
{allowCellEditing}
/>
</Drawer> </Drawer>

View File

@ -3940,11 +3940,10 @@
"required": true "required": true
}, },
{ {
"type": "allowedFields", "type": "columns/basic",
"label": "Allowed filter columns", "label": "Allowed filter columns",
"key": "allowedFields", "key": "allowedFields",
"dependsOn": "dataProvider", "dependsOn": "dataProvider"
"nested": true
}, },
{ {
"type": "select", "type": "select",