Generate button context bindings for all button actions
This commit is contained in:
parent
2da952af24
commit
59ac6682ae
|
@ -132,6 +132,10 @@ const searchComponentTree = (rootComponent, matchComponent) => {
|
||||||
*/
|
*/
|
||||||
let componentSettingCache = {}
|
let componentSettingCache = {}
|
||||||
export const getComponentSettings = componentType => {
|
export const getComponentSettings = componentType => {
|
||||||
|
if (!componentType) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure whole component name is used
|
// Ensure whole component name is used
|
||||||
if (!componentType.startsWith("@budibase")) {
|
if (!componentType.startsWith("@budibase")) {
|
||||||
componentType = `@budibase/standard-components/${componentType}`
|
componentType = `@budibase/standard-components/${componentType}`
|
||||||
|
|
|
@ -381,28 +381,13 @@ const getUrlBindings = asset => {
|
||||||
* Gets all bindable properties exposed in a button actions flow up until
|
* Gets all bindable properties exposed in a button actions flow up until
|
||||||
* the specified action ID.
|
* the specified action ID.
|
||||||
*/
|
*/
|
||||||
export const getButtonContextBindings = (component, actionId) => {
|
export const getButtonContextBindings = (actions, actionId) => {
|
||||||
// Find the setting we are working on
|
// Get the steps leading up to this value
|
||||||
let settingValue = []
|
const index = actions?.findIndex(action => action.id === actionId)
|
||||||
const settings = getComponentSettings(component._component)
|
if (index == null || index === -1) {
|
||||||
const eventSettings = settings.filter(setting => setting.type === "event")
|
|
||||||
for (let i = 0; i < eventSettings.length; i++) {
|
|
||||||
const setting = component[eventSettings[i].key]
|
|
||||||
if (
|
|
||||||
Array.isArray(setting) &&
|
|
||||||
setting.find(action => action.id === actionId)
|
|
||||||
) {
|
|
||||||
settingValue = setting
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!settingValue?.length) {
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
const prevActions = actions.slice(0, index)
|
||||||
// Get the steps leading up to this value
|
|
||||||
const index = settingValue.findIndex(action => action.id === actionId)
|
|
||||||
const prevActions = settingValue.slice(0, index)
|
|
||||||
|
|
||||||
// Generate bindings for any steps which provide context
|
// Generate bindings for any steps which provide context
|
||||||
let bindings = []
|
let bindings = []
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { getAvailableActions } from "./actions"
|
import { getAvailableActions } from "./actions"
|
||||||
import { generate } from "shortid"
|
import { generate } from "shortid"
|
||||||
|
import { getButtonContextBindings } from "builderStore/dataBinding"
|
||||||
|
|
||||||
const flipDurationMs = 150
|
const flipDurationMs = 150
|
||||||
const EVENT_TYPE_KEY = "##eventHandlerType"
|
const EVENT_TYPE_KEY = "##eventHandlerType"
|
||||||
|
@ -19,7 +20,17 @@
|
||||||
export let actions
|
export let actions
|
||||||
export let bindings = []
|
export let bindings = []
|
||||||
|
|
||||||
// dndzone needs an id on the array items, so this adds some temporary ones.
|
let selectedAction = actions?.length ? actions[0] : null
|
||||||
|
|
||||||
|
// These are ephemeral bindings which only exist while executing actions
|
||||||
|
$: buttonContextBindings = getButtonContextBindings(
|
||||||
|
actions,
|
||||||
|
selectedAction?.id
|
||||||
|
)
|
||||||
|
$: console.log(buttonContextBindings)
|
||||||
|
$: allBindings = buttonContextBindings.concat(bindings)
|
||||||
|
|
||||||
|
// Assign a unique ID to each action
|
||||||
$: {
|
$: {
|
||||||
if (actions) {
|
if (actions) {
|
||||||
actions.forEach(action => {
|
actions.forEach(action => {
|
||||||
|
@ -30,8 +41,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let selectedAction = actions?.length ? actions[0] : null
|
|
||||||
|
|
||||||
$: selectedActionComponent =
|
$: selectedActionComponent =
|
||||||
selectedAction &&
|
selectedAction &&
|
||||||
actionTypes.find(t => t.name === selectedAction[EVENT_TYPE_KEY])?.component
|
actionTypes.find(t => t.name === selectedAction[EVENT_TYPE_KEY])?.component
|
||||||
|
@ -121,9 +130,8 @@
|
||||||
<div class="selected-action-container">
|
<div class="selected-action-container">
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={selectedActionComponent}
|
this={selectedActionComponent}
|
||||||
selectedActionId={selectedAction.id}
|
|
||||||
parameters={selectedAction.parameters}
|
parameters={selectedAction.parameters}
|
||||||
{bindings}
|
bindings={allBindings}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
<script>
|
<script>
|
||||||
import { Select, Label, Body, Checkbox, Input } from "@budibase/bbui"
|
import { Select, Label, Body, Checkbox, Input } from "@budibase/bbui"
|
||||||
import { store, currentAsset, selectedComponent } from "builderStore"
|
import { store, currentAsset } from "builderStore"
|
||||||
import { tables } from "stores/backend"
|
import { tables } from "stores/backend"
|
||||||
import {
|
import {
|
||||||
getButtonContextBindings,
|
|
||||||
getContextProviderComponents,
|
getContextProviderComponents,
|
||||||
getSchemaForDatasource,
|
getSchemaForDatasource,
|
||||||
} from "builderStore/dataBinding"
|
} from "builderStore/dataBinding"
|
||||||
import SaveFields from "./SaveFields.svelte"
|
import SaveFields from "./SaveFields.svelte"
|
||||||
|
|
||||||
export let selectedActionId
|
|
||||||
export let parameters
|
export let parameters
|
||||||
export let bindings = []
|
export let bindings = []
|
||||||
|
|
||||||
|
@ -26,11 +24,6 @@
|
||||||
$: providerOptions = getProviderOptions(formComponents, schemaComponents)
|
$: providerOptions = getProviderOptions(formComponents, schemaComponents)
|
||||||
$: schemaFields = getSchemaFields($currentAsset, parameters?.tableId)
|
$: schemaFields = getSchemaFields($currentAsset, parameters?.tableId)
|
||||||
$: tableOptions = $tables.list || []
|
$: tableOptions = $tables.list || []
|
||||||
$: buttonContextBindings = getButtonContextBindings(
|
|
||||||
$selectedComponent,
|
|
||||||
selectedActionId
|
|
||||||
)
|
|
||||||
$: console.log(buttonContextBindings)
|
|
||||||
|
|
||||||
// Gets a context definition of a certain type from a component definition
|
// Gets a context definition of a certain type from a component definition
|
||||||
const extractComponentContext = (component, contextType) => {
|
const extractComponentContext = (component, contextType) => {
|
||||||
|
|
Loading…
Reference in New Issue