Display TableSelect the same way we do for DataSourceSelect
This commit is contained in:
parent
655332715d
commit
56f666f15a
|
@ -1,22 +1,30 @@
|
||||||
<script>
|
<script>
|
||||||
import { Select } from "@budibase/bbui"
|
import { Popover, Select } from "@budibase/bbui"
|
||||||
import { createEventDispatcher, onMount } from "svelte"
|
import { createEventDispatcher, onMount } from "svelte"
|
||||||
import { tables as tablesStore, viewsV2 } from "@/stores/builder"
|
import { datasources, tables as tablesStore, viewsV2 } from "@/stores/builder"
|
||||||
import { tableSelect as format } from "@/helpers/data/format"
|
import { tableSelect as format } from "@/helpers/data/format"
|
||||||
|
import DataSourceCategory from "./DataSourceSelect/DataSourceCategory.svelte"
|
||||||
|
|
||||||
export let value
|
export let value
|
||||||
|
|
||||||
|
let anchorRight, dropdownRight
|
||||||
|
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
$: tables = $tablesStore.list.map(format.table)
|
$: tables = $tablesStore.list.map(table =>
|
||||||
|
format.table(table, $datasources.list)
|
||||||
|
)
|
||||||
$: views = $viewsV2.list.map(format.viewV2)
|
$: views = $viewsV2.list.map(format.viewV2)
|
||||||
$: options = [...(tables || []), ...(views || [])]
|
$: options = [...(tables || []), ...(views || [])]
|
||||||
|
|
||||||
|
$: text = value?.label ?? "Choose an option"
|
||||||
|
|
||||||
const onChange = e => {
|
const onChange = e => {
|
||||||
dispatch(
|
dispatch(
|
||||||
"change",
|
"change",
|
||||||
options.find(x => x.resourceId === e.detail)
|
options.find(x => x.resourceId === e.resourceId)
|
||||||
)
|
)
|
||||||
|
dropdownRight.hide()
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
|
@ -29,10 +37,30 @@
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Select
|
<div class="container" bind:this={anchorRight}>
|
||||||
on:change={onChange}
|
<Select
|
||||||
value={value?.resourceId}
|
readonly
|
||||||
{options}
|
value={text}
|
||||||
getOptionValue={x => x.resourceId}
|
options={[text]}
|
||||||
getOptionLabel={x => x.label}
|
on:click={dropdownRight.show}
|
||||||
/>
|
/>
|
||||||
|
</div>
|
||||||
|
<Popover bind:this={dropdownRight} anchor={anchorRight}>
|
||||||
|
<div class="dropdown">
|
||||||
|
<DataSourceCategory
|
||||||
|
heading="Tables"
|
||||||
|
dataSet={tables}
|
||||||
|
{value}
|
||||||
|
onSelect={onChange}
|
||||||
|
/>
|
||||||
|
{#if views?.length}
|
||||||
|
<DataSourceCategory
|
||||||
|
dividerState={true}
|
||||||
|
heading="Views"
|
||||||
|
dataSet={views}
|
||||||
|
{value}
|
||||||
|
onSelect={onChange}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</Popover>
|
||||||
|
|
Loading…
Reference in New Issue