Add button action to refresh a datasource
This commit is contained in:
parent
af74e6a592
commit
6bdde675a2
|
@ -0,0 +1,37 @@
|
|||
<script>
|
||||
import { Select, Label } from "@budibase/bbui"
|
||||
import { currentAsset, store } from "builderStore"
|
||||
import { getDataProviderComponents } from "builderStore/dataBinding"
|
||||
|
||||
export let parameters
|
||||
|
||||
$: dataProviders = getDataProviderComponents(
|
||||
$currentAsset.props,
|
||||
$store.selectedComponentId
|
||||
)
|
||||
</script>
|
||||
|
||||
<div class="root">
|
||||
<Label size="m" color="dark">Form</Label>
|
||||
<Select secondary bind:value={parameters.componentId}>
|
||||
<option value="" />
|
||||
{#if dataProviders}
|
||||
{#each dataProviders as component}
|
||||
<option value={component._id}>{component._instanceName}</option>
|
||||
{/each}
|
||||
{/if}
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.root {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.root :global(> div) {
|
||||
flex: 1;
|
||||
margin-left: var(--spacing-l);
|
||||
}
|
||||
</style>
|
|
@ -4,6 +4,7 @@ import DeleteRow from "./DeleteRow.svelte"
|
|||
import ExecuteQuery from "./ExecuteQuery.svelte"
|
||||
import TriggerAutomation from "./TriggerAutomation.svelte"
|
||||
import ValidateForm from "./ValidateForm.svelte"
|
||||
import RefreshDatasource from "./RefreshDatasource.svelte"
|
||||
|
||||
// defines what actions are available, when adding a new one
|
||||
// the component is the setup panel for the action
|
||||
|
@ -35,4 +36,8 @@ export default [
|
|||
name: "Validate Form",
|
||||
component: ValidateForm,
|
||||
},
|
||||
{
|
||||
name: "Refresh Datasource",
|
||||
component: RefreshDatasource,
|
||||
},
|
||||
]
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
$: providerKey = key || $component.id
|
||||
|
||||
// Add data context
|
||||
$: newContext.actions.provideData(providerKey, data)
|
||||
$: data !== undefined && newContext.actions.provideData(providerKey, data)
|
||||
|
||||
// Add actions context
|
||||
$: {
|
||||
|
|
|
@ -4,4 +4,5 @@ export const TableNames = {
|
|||
|
||||
export const ActionTypes = {
|
||||
ValidateForm: "ValidateForm",
|
||||
RefreshDatasource: "RefreshDatasource",
|
||||
}
|
||||
|
|
|
@ -50,14 +50,29 @@ const queryExecutionHandler = async action => {
|
|||
})
|
||||
}
|
||||
|
||||
const validateFormHandler = async (action, context) => {
|
||||
const { componentId } = action.parameters
|
||||
const fn = context[`${componentId}_${ActionTypes.ValidateForm}`]
|
||||
const executeActionHandler = async (context, componentId, actionType) => {
|
||||
const fn = context[`${componentId}_${actionType}`]
|
||||
if (fn) {
|
||||
return await fn()
|
||||
}
|
||||
}
|
||||
|
||||
const validateFormHandler = async (action, context) => {
|
||||
return await executeActionHandler(
|
||||
context,
|
||||
action.parameters.componentId,
|
||||
ActionTypes.ValidateForm
|
||||
)
|
||||
}
|
||||
|
||||
const refreshDatasourceHandler = async (action, context) => {
|
||||
return await executeActionHandler(
|
||||
context,
|
||||
action.parameters.componentId,
|
||||
ActionTypes.RefreshDatasource
|
||||
)
|
||||
}
|
||||
|
||||
const handlerMap = {
|
||||
["Save Row"]: saveRowHandler,
|
||||
["Delete Row"]: deleteRowHandler,
|
||||
|
@ -65,6 +80,7 @@ const handlerMap = {
|
|||
["Execute Query"]: queryExecutionHandler,
|
||||
["Trigger Automation"]: triggerAutomationHandler,
|
||||
["Validate Form"]: validateFormHandler,
|
||||
["Refresh Datasource"]: refreshDatasourceHandler,
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -106,6 +106,7 @@
|
|||
"styleable": true,
|
||||
"hasChildren": true,
|
||||
"dataProvider": true,
|
||||
"actions": ["RefreshDatasource"],
|
||||
"settings": [
|
||||
{
|
||||
"type": "datasource",
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
import { getContext } from "svelte"
|
||||
import { isEmpty } from "lodash/fp"
|
||||
|
||||
const { API, styleable, Provider, builderStore } = getContext("sdk")
|
||||
const { API, styleable, Provider, builderStore, ActionTypes } = getContext(
|
||||
"sdk"
|
||||
)
|
||||
const component = getContext("component")
|
||||
|
||||
export let datasource = []
|
||||
|
@ -18,25 +20,34 @@
|
|||
}
|
||||
loaded = true
|
||||
}
|
||||
|
||||
$: actions = [
|
||||
{
|
||||
type: ActionTypes.RefreshDatasource,
|
||||
callback: () => fetchData(datasource),
|
||||
},
|
||||
]
|
||||
</script>
|
||||
|
||||
{#if rows.length > 0}
|
||||
<div use:styleable={$component.styles}>
|
||||
{#if $component.children === 0 && $builderStore.inBuilder}
|
||||
<p>Add some components too</p>
|
||||
{:else}
|
||||
{#each rows as row}
|
||||
<Provider data={row}>
|
||||
<slot />
|
||||
</Provider>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
{:else if loaded && $builderStore.inBuilder}
|
||||
<div use:styleable={$component.styles}>
|
||||
<p>Feed me some data</p>
|
||||
</div>
|
||||
{/if}
|
||||
<Provider {actions}>
|
||||
{#if rows.length > 0}
|
||||
<div use:styleable={$component.styles}>
|
||||
{#if $component.children === 0 && $builderStore.inBuilder}
|
||||
<p>Add some components too</p>
|
||||
{:else}
|
||||
{#each rows as row}
|
||||
<Provider data={row}>
|
||||
<slot />
|
||||
</Provider>
|
||||
{/each}
|
||||
{/if}
|
||||
</div>
|
||||
{:else if loaded && $builderStore.inBuilder}
|
||||
<div use:styleable={$component.styles}>
|
||||
<p>Feed me some data</p>
|
||||
</div>
|
||||
{/if}
|
||||
</Provider>
|
||||
|
||||
<style>
|
||||
p {
|
||||
|
|
Loading…
Reference in New Issue