2020-06-03 00:26:06 +02:00
|
|
|
<script>
|
2021-01-21 11:42:14 +01:00
|
|
|
import { getContext } from "svelte"
|
2020-08-26 18:03:30 +02:00
|
|
|
import { isEmpty } from "lodash/fp"
|
2020-11-18 20:18:18 +01:00
|
|
|
|
2021-02-10 19:34:45 +01:00
|
|
|
export let datasource
|
|
|
|
export let noRowsMessage
|
2021-02-05 17:16:41 +01:00
|
|
|
|
2021-02-05 13:54:36 +01:00
|
|
|
const { API, styleable, Provider, builderStore, ActionTypes } = getContext(
|
|
|
|
"sdk"
|
|
|
|
)
|
2020-11-24 12:02:10 +01:00
|
|
|
const component = getContext("component")
|
2020-11-18 12:24:01 +01:00
|
|
|
let rows = []
|
2021-01-26 10:48:41 +01:00
|
|
|
let loaded = false
|
2020-06-03 00:26:06 +02:00
|
|
|
|
2021-01-21 11:42:14 +01:00
|
|
|
$: fetchData(datasource)
|
2021-02-05 17:16:41 +01:00
|
|
|
$: actions = [
|
|
|
|
{
|
|
|
|
type: ActionTypes.RefreshDatasource,
|
|
|
|
callback: () => fetchData(datasource),
|
|
|
|
metadata: { datasource },
|
|
|
|
},
|
|
|
|
]
|
2021-01-11 21:17:56 +01:00
|
|
|
|
2021-01-21 11:42:14 +01:00
|
|
|
async function fetchData(datasource) {
|
2020-08-26 18:03:30 +02:00
|
|
|
if (!isEmpty(datasource)) {
|
2021-01-21 11:42:14 +01:00
|
|
|
rows = await API.fetchDatasource(datasource)
|
2020-06-03 00:26:06 +02:00
|
|
|
}
|
2021-01-26 10:48:41 +01:00
|
|
|
loaded = true
|
2021-01-21 11:42:14 +01:00
|
|
|
}
|
2020-06-03 00:26:06 +02:00
|
|
|
</script>
|
|
|
|
|
2021-02-05 13:54:36 +01:00
|
|
|
<Provider {actions}>
|
2021-02-10 19:34:45 +01:00
|
|
|
<div use:styleable={$component.styles}>
|
|
|
|
{#if rows.length > 0}
|
2021-02-05 13:54:36 +01:00
|
|
|
{#if $component.children === 0 && $builderStore.inBuilder}
|
2021-02-11 10:20:25 +01:00
|
|
|
<p><i class="ri-image-line" />Add some components to display.</p>
|
2021-02-05 13:54:36 +01:00
|
|
|
{:else}
|
|
|
|
{#each rows as row}
|
|
|
|
<Provider data={row}>
|
|
|
|
<slot />
|
|
|
|
</Provider>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
2021-02-10 19:34:45 +01:00
|
|
|
{:else if loaded && noRowsMessage}
|
|
|
|
<p><i class="ri-list-check-2" />{noRowsMessage}</p>
|
2021-01-26 10:48:41 +01:00
|
|
|
{/if}
|
2021-02-10 19:34:45 +01:00
|
|
|
</div>
|
2021-02-05 13:54:36 +01:00
|
|
|
</Provider>
|
2021-01-19 15:11:21 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
p {
|
2021-02-10 19:34:45 +01:00
|
|
|
margin: 0 var(--spacing-m);
|
|
|
|
background-color: var(--grey-2);
|
|
|
|
color: var(--grey-6);
|
|
|
|
font-size: var(--font-size-s);
|
|
|
|
padding: var(--spacing-l);
|
|
|
|
border-radius: var(--border-radius-s);
|
2021-01-19 15:11:21 +01:00
|
|
|
display: grid;
|
|
|
|
place-items: center;
|
2021-02-10 19:34:45 +01:00
|
|
|
}
|
|
|
|
p i {
|
|
|
|
margin-bottom: var(--spacing-m);
|
|
|
|
font-size: 1.5rem;
|
|
|
|
color: var(--grey-5);
|
2021-01-19 15:11:21 +01:00
|
|
|
}
|
2021-01-22 11:49:03 +01:00
|
|
|
</style>
|