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 ExecuteQuery from "./ExecuteQuery.svelte"
|
||||||
import TriggerAutomation from "./TriggerAutomation.svelte"
|
import TriggerAutomation from "./TriggerAutomation.svelte"
|
||||||
import ValidateForm from "./ValidateForm.svelte"
|
import ValidateForm from "./ValidateForm.svelte"
|
||||||
|
import RefreshDatasource from "./RefreshDatasource.svelte"
|
||||||
|
|
||||||
// defines what actions are available, when adding a new one
|
// defines what actions are available, when adding a new one
|
||||||
// the component is the setup panel for the action
|
// the component is the setup panel for the action
|
||||||
|
@ -35,4 +36,8 @@ export default [
|
||||||
name: "Validate Form",
|
name: "Validate Form",
|
||||||
component: ValidateForm,
|
component: ValidateForm,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "Refresh Datasource",
|
||||||
|
component: RefreshDatasource,
|
||||||
|
},
|
||||||
]
|
]
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
$: providerKey = key || $component.id
|
$: providerKey = key || $component.id
|
||||||
|
|
||||||
// Add data context
|
// Add data context
|
||||||
$: newContext.actions.provideData(providerKey, data)
|
$: data !== undefined && newContext.actions.provideData(providerKey, data)
|
||||||
|
|
||||||
// Add actions context
|
// Add actions context
|
||||||
$: {
|
$: {
|
||||||
|
|
|
@ -4,4 +4,5 @@ export const TableNames = {
|
||||||
|
|
||||||
export const ActionTypes = {
|
export const ActionTypes = {
|
||||||
ValidateForm: "ValidateForm",
|
ValidateForm: "ValidateForm",
|
||||||
|
RefreshDatasource: "RefreshDatasource",
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,14 +50,29 @@ const queryExecutionHandler = async action => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const validateFormHandler = async (action, context) => {
|
const executeActionHandler = async (context, componentId, actionType) => {
|
||||||
const { componentId } = action.parameters
|
const fn = context[`${componentId}_${actionType}`]
|
||||||
const fn = context[`${componentId}_${ActionTypes.ValidateForm}`]
|
|
||||||
if (fn) {
|
if (fn) {
|
||||||
return await 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 = {
|
const handlerMap = {
|
||||||
["Save Row"]: saveRowHandler,
|
["Save Row"]: saveRowHandler,
|
||||||
["Delete Row"]: deleteRowHandler,
|
["Delete Row"]: deleteRowHandler,
|
||||||
|
@ -65,6 +80,7 @@ const handlerMap = {
|
||||||
["Execute Query"]: queryExecutionHandler,
|
["Execute Query"]: queryExecutionHandler,
|
||||||
["Trigger Automation"]: triggerAutomationHandler,
|
["Trigger Automation"]: triggerAutomationHandler,
|
||||||
["Validate Form"]: validateFormHandler,
|
["Validate Form"]: validateFormHandler,
|
||||||
|
["Refresh Datasource"]: refreshDatasourceHandler,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -106,6 +106,7 @@
|
||||||
"styleable": true,
|
"styleable": true,
|
||||||
"hasChildren": true,
|
"hasChildren": true,
|
||||||
"dataProvider": true,
|
"dataProvider": true,
|
||||||
|
"actions": ["RefreshDatasource"],
|
||||||
"settings": [
|
"settings": [
|
||||||
{
|
{
|
||||||
"type": "datasource",
|
"type": "datasource",
|
||||||
|
|
|
@ -2,7 +2,9 @@
|
||||||
import { getContext } from "svelte"
|
import { getContext } from "svelte"
|
||||||
import { isEmpty } from "lodash/fp"
|
import { isEmpty } from "lodash/fp"
|
||||||
|
|
||||||
const { API, styleable, Provider, builderStore } = getContext("sdk")
|
const { API, styleable, Provider, builderStore, ActionTypes } = getContext(
|
||||||
|
"sdk"
|
||||||
|
)
|
||||||
const component = getContext("component")
|
const component = getContext("component")
|
||||||
|
|
||||||
export let datasource = []
|
export let datasource = []
|
||||||
|
@ -18,8 +20,16 @@
|
||||||
}
|
}
|
||||||
loaded = true
|
loaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: actions = [
|
||||||
|
{
|
||||||
|
type: ActionTypes.RefreshDatasource,
|
||||||
|
callback: () => fetchData(datasource),
|
||||||
|
},
|
||||||
|
]
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<Provider {actions}>
|
||||||
{#if rows.length > 0}
|
{#if rows.length > 0}
|
||||||
<div use:styleable={$component.styles}>
|
<div use:styleable={$component.styles}>
|
||||||
{#if $component.children === 0 && $builderStore.inBuilder}
|
{#if $component.children === 0 && $builderStore.inBuilder}
|
||||||
|
@ -37,6 +47,7 @@
|
||||||
<p>Feed me some data</p>
|
<p>Feed me some data</p>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
</Provider>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
p {
|
p {
|
||||||
|
|
Loading…
Reference in New Issue