2020-06-03 00:26:06 +02:00
|
|
|
<script>
|
2020-11-17 13:08:24 +01:00
|
|
|
import { onMount, setContext } from "svelte"
|
|
|
|
import {
|
|
|
|
fetchDatasource,
|
|
|
|
createDataProviderContext,
|
|
|
|
fetchTableDefinition,
|
|
|
|
ContextTypes,
|
|
|
|
} from "@budibase/component-sdk"
|
2020-08-26 18:03:30 +02:00
|
|
|
import { isEmpty } from "lodash/fp"
|
2020-06-03 00:26:06 +02:00
|
|
|
|
2020-08-26 18:03:30 +02:00
|
|
|
export let datasource = []
|
2020-06-03 00:26:06 +02:00
|
|
|
|
|
|
|
let target
|
2020-11-17 13:08:24 +01:00
|
|
|
|
|
|
|
const dataProviderContext = createDataProviderContext()
|
|
|
|
setContext(ContextTypes.DataProvider, dataProviderContext)
|
2020-06-03 00:26:06 +02:00
|
|
|
|
2020-08-26 18:03:30 +02:00
|
|
|
onMount(async () => {
|
|
|
|
if (!isEmpty(datasource)) {
|
2020-11-17 13:08:24 +01:00
|
|
|
const rows = await fetchDatasource(datasource)
|
|
|
|
dataProviderContext.actions.setRows(rows)
|
|
|
|
if (datasource.tableId) {
|
|
|
|
const tableDefinition = await fetchTableDefinition(datasource.tableId)
|
|
|
|
dataProviderContext.actions.setTable(tableDefinition)
|
|
|
|
}
|
2020-06-03 00:26:06 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
2020-07-07 22:29:20 +02:00
|
|
|
<section bind:this={target} />
|