Allow selecting viewV2s for grid blocks and form blocks
This commit is contained in:
parent
06810d43d9
commit
08b348c1d4
|
@ -7,22 +7,50 @@
|
|||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
$: tables = $tablesStore.list.map(m => ({
|
||||
label: m.name,
|
||||
tableId: m._id,
|
||||
$: tables = $tablesStore.list.map(table => ({
|
||||
...table,
|
||||
type: "table",
|
||||
label: table.name,
|
||||
key: table._id,
|
||||
}))
|
||||
$: views = $tablesStore.list.reduce(
|
||||
(acc, table) => [
|
||||
...acc,
|
||||
...Object.values(table.views || {})
|
||||
.filter(view => view.version === 2)
|
||||
.map(view => ({
|
||||
...view,
|
||||
type: "viewV2",
|
||||
label: view.name,
|
||||
key: view.id,
|
||||
})),
|
||||
],
|
||||
[]
|
||||
)
|
||||
$: options = [...(tables || []), ...(views || [])]
|
||||
$: {
|
||||
// Migrate old table values before "key" existed
|
||||
if (value && !value.key) {
|
||||
console.log("migrate")
|
||||
dispatch(
|
||||
"change",
|
||||
tables.find(x => x.tableId === value.tableId)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
const onChange = e => {
|
||||
const dataSource = tables?.find(x => x.tableId === e.detail)
|
||||
dispatch("change", dataSource)
|
||||
dispatch(
|
||||
"change",
|
||||
options.find(x => x.key === e.detail)
|
||||
)
|
||||
}
|
||||
</script>
|
||||
|
||||
<Select
|
||||
on:change={onChange}
|
||||
value={value?.tableId}
|
||||
options={tables}
|
||||
getOptionValue={x => x.tableId}
|
||||
value={value?.key}
|
||||
{options}
|
||||
getOptionValue={x => x.key}
|
||||
getOptionLabel={x => x.label}
|
||||
/>
|
||||
|
|
|
@ -5272,7 +5272,7 @@
|
|||
},
|
||||
{
|
||||
"type": "table",
|
||||
"label": "Table",
|
||||
"label": "Data",
|
||||
"key": "dataSource"
|
||||
},
|
||||
{
|
||||
|
@ -5547,7 +5547,7 @@
|
|||
"settings": [
|
||||
{
|
||||
"type": "table",
|
||||
"label": "Table",
|
||||
"label": "Data",
|
||||
"key": "table",
|
||||
"required": true
|
||||
},
|
||||
|
|
|
@ -38,10 +38,7 @@
|
|||
class:in-builder={$builderStore.inBuilder}
|
||||
>
|
||||
<Grid
|
||||
datasource={{
|
||||
type: "table",
|
||||
tableId: table?.tableId,
|
||||
}}
|
||||
datasource={table}
|
||||
{API}
|
||||
{stripeRows}
|
||||
{initialFilter}
|
||||
|
|
Loading…
Reference in New Issue