Simplify extracting schemas from datasources

This commit is contained in:
Andrew Kingston 2021-01-21 10:39:53 +00:00
parent d76621d5f8
commit 99c1360be1
1 changed files with 7 additions and 19 deletions

View File

@ -1,31 +1,19 @@
<script> <script>
import OptionSelect from "./OptionSelect.svelte" import OptionSelect from "./OptionSelect.svelte"
import { backendUiStore } from "builderStore"
import MultiOptionSelect from "./MultiOptionSelect.svelte" import MultiOptionSelect from "./MultiOptionSelect.svelte"
import {
getDatasourceForProvider,
getSchemaForDatasource,
} from "builderStore/dataBinding"
export let componentInstance = {} export let componentInstance = {}
export let value = "" export let value = ""
export let onChange = () => {} export let onChange = () => {}
export let multiselect = false export let multiselect = false
const tables = $backendUiStore.tables $: datasource = getDatasourceForProvider(componentInstance)
const queries = $backendUiStore.queries $: schema = getSchemaForDatasource(datasource)
$: options = Object.keys(schema || {})
let options = []
$: table =
componentInstance.datasource?.type === "table"
? tables.find(m => m._id === componentInstance.datasource.tableId)
: queries.find(query => query._id === componentInstance.datasource._id)
$: type = componentInstance.datasource.type
$: if (table) {
options =
type === "table" || type === "link" || type === "query"
? Object.keys(table.schema)
: Object.keys(table.views[componentInstance.datasource.name].schema)
}
</script> </script>
{#if multiselect} {#if multiselect}