Add single button action for changing form step

This commit is contained in:
Andrew Kingston 2021-08-20 09:54:54 +01:00
parent 10066bf3e0
commit 7f07390277
14 changed files with 93 additions and 111 deletions

View File

@ -33,7 +33,7 @@
$: selectedActionComponent = $: selectedActionComponent =
selectedAction && selectedAction &&
actionTypes.find(t => t.name === selectedAction[EVENT_TYPE_KEY]).component actionTypes.find(t => t.name === selectedAction[EVENT_TYPE_KEY])?.component
// Select the first action if we delete an action // Select the first action if we delete an action
$: { $: {
@ -116,7 +116,7 @@
</ActionMenu> </ActionMenu>
</Layout> </Layout>
<Layout noPadding> <Layout noPadding>
{#if selectedAction} {#if selectedActionComponent}
<div class="selected-action-container"> <div class="selected-action-container">
<svelte:component <svelte:component
this={selectedActionComponent} this={selectedActionComponent}

View File

@ -0,0 +1,68 @@
<script>
import { Select, Label, Stepper } from "@budibase/bbui"
import { currentAsset, store } from "builderStore"
import { getActionProviderComponents } from "builderStore/dataBinding"
import { onMount } from "svelte"
export let parameters
$: actionProviders = getActionProviderComponents(
$currentAsset,
$store.selectedComponentId,
"ChangeFormStep"
)
const typeOptions = [
{
label: "Next step",
value: "next",
},
{
label: "Previous step",
value: "prev",
},
{
label: "First step",
value: "first",
},
{
label: "Specific step",
value: "specific",
},
]
onMount(() => {
if (!parameters.type) {
parameters.type = "next"
}
})
</script>
<div class="root">
<Label small>Form</Label>
<Select
placeholder={null}
bind:value={parameters.componentId}
options={actionProviders}
getOptionLabel={x => x._instanceName}
getOptionValue={x => x._id}
/>
<Label small>Step</Label>
<Select bind:value={parameters.type} options={typeOptions} />
{#if parameters.type === "specific"}
<Label small>Number</Label>
<Stepper bind:value={parameters.number} />
{/if}
</div>
<style>
.root {
display: grid;
column-gap: var(--spacing-l);
row-gap: var(--spacing-s);
grid-template-columns: 60px 1fr;
align-items: center;
max-width: 400px;
margin: 0 auto;
}
</style>

View File

@ -29,7 +29,7 @@
row-gap: var(--spacing-s); row-gap: var(--spacing-s);
grid-template-columns: 60px 1fr; grid-template-columns: 60px 1fr;
align-items: center; align-items: center;
max-width: 800px; max-width: 400px;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>

View File

@ -11,7 +11,6 @@
<style> <style>
.root { .root {
max-width: 800px;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>

View File

@ -8,7 +8,6 @@
<style> <style>
.root { .root {
max-width: 800px;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>

View File

@ -25,7 +25,7 @@
align-items: center; align-items: center;
gap: var(--spacing-m); gap: var(--spacing-m);
grid-template-columns: auto 1fr; grid-template-columns: auto 1fr;
max-width: 800px; max-width: 400px;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>

View File

@ -1,35 +0,0 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, store } from "builderStore"
import { getActionProviderComponents } from "builderStore/dataBinding"
export let parameters
$: actionProviders = getActionProviderComponents(
$currentAsset,
$store.selectedComponentId,
"NextFormStep"
)
</script>
<div class="root">
<Label small>Form</Label>
<Select
bind:value={parameters.componentId}
options={actionProviders}
getOptionLabel={x => x._instanceName}
getOptionValue={x => x._id}
/>
</div>
<style>
.root {
display: grid;
column-gap: var(--spacing-l);
row-gap: var(--spacing-s);
grid-template-columns: 60px 1fr;
align-items: center;
max-width: 800px;
margin: 0 auto;
}
</style>

View File

@ -1,35 +0,0 @@
<script>
import { Select, Label } from "@budibase/bbui"
import { currentAsset, store } from "builderStore"
import { getActionProviderComponents } from "builderStore/dataBinding"
export let parameters
$: actionProviders = getActionProviderComponents(
$currentAsset,
$store.selectedComponentId,
"PrevFormStep"
)
</script>
<div class="root">
<Label small>Form</Label>
<Select
bind:value={parameters.componentId}
options={actionProviders}
getOptionLabel={x => x._instanceName}
getOptionValue={x => x._id}
/>
</div>
<style>
.root {
display: grid;
column-gap: var(--spacing-l);
row-gap: var(--spacing-s);
grid-template-columns: 60px 1fr;
align-items: center;
max-width: 800px;
margin: 0 auto;
}
</style>

View File

@ -34,7 +34,7 @@
row-gap: var(--spacing-s); row-gap: var(--spacing-s);
grid-template-columns: 60px 1fr; grid-template-columns: 60px 1fr;
align-items: center; align-items: center;
max-width: 800px; max-width: 400px;
margin: 0 auto; margin: 0 auto;
} }
</style> </style>

View File

@ -7,8 +7,7 @@ import ValidateForm from "./ValidateForm.svelte"
import LogOut from "./LogOut.svelte" import LogOut from "./LogOut.svelte"
import ClearForm from "./ClearForm.svelte" import ClearForm from "./ClearForm.svelte"
import CloseScreenModal from "./CloseScreenModal.svelte" import CloseScreenModal from "./CloseScreenModal.svelte"
import NextFormStep from "./NextFormStep.svelte" import ChangeFormStep from "./ChangeFormStep.svelte"
import PrevFormStep from "./PrevFormStep.svelte"
// Defines which actions are available to configure in the front end. // Defines which actions are available to configure in the front end.
// Unfortunately the "name" property is used as the identifier so please don't // Unfortunately the "name" property is used as the identifier so please don't
@ -55,11 +54,7 @@ export default [
component: CloseScreenModal, component: CloseScreenModal,
}, },
{ {
name: "Next Form Step", name: "Change Form Step",
component: NextFormStep, component: ChangeFormStep,
},
{
name: "Previous Form Step",
component: PrevFormStep,
}, },
] ]

View File

@ -7,8 +7,7 @@ export const ActionTypes = {
RefreshDatasource: "RefreshDatasource", RefreshDatasource: "RefreshDatasource",
SetDataProviderQuery: "SetDataProviderQuery", SetDataProviderQuery: "SetDataProviderQuery",
ClearForm: "ClearForm", ClearForm: "ClearForm",
NextFormStep: "NextFormStep", ChangeFormStep: "ChangeFormStep",
PrevFormStep: "PrevFormStep",
} }
export const ApiVersion = "1" export const ApiVersion = "1"

View File

@ -105,19 +105,12 @@ const clearFormHandler = async (action, context) => {
) )
} }
const nextFormStepHandler = async (action, context) => { const changeFormStepHandler = async (action, context) => {
return await executeActionHandler( return await executeActionHandler(
context, context,
action.parameters.componentId, action.parameters.componentId,
ActionTypes.NextFormStep ActionTypes.ChangeFormStep,
) action.parameters
}
const prevFormStepHandler = async (action, context) => {
return await executeActionHandler(
context,
action.parameters.componentId,
ActionTypes.PrevFormStep
) )
} }
@ -138,8 +131,7 @@ const handlerMap = {
["Log Out"]: logoutHandler, ["Log Out"]: logoutHandler,
["Clear Form"]: clearFormHandler, ["Clear Form"]: clearFormHandler,
["Close Screen Modal"]: closeScreenModalHandler, ["Close Screen Modal"]: closeScreenModalHandler,
["Next Form Step"]: nextFormStepHandler, ["Change Form Step"]: changeFormStepHandler,
["Previous Form Step"]: prevFormStepHandler,
} }
const confirmTextMap = { const confirmTextMap = {

View File

@ -1706,8 +1706,7 @@
"actions": [ "actions": [
"ValidateForm", "ValidateForm",
"ClearForm", "ClearForm",
"NextFormStep", "ChangeFormStep"
"PrevFormStep"
], ],
"styles": ["size"], "styles": ["size"],
"settings": [ "settings": [
@ -1768,9 +1767,6 @@
"icon": "Form", "icon": "Form",
"hasChildren": true, "hasChildren": true,
"illegalChildren": ["section"], "illegalChildren": ["section"],
"actions": [
"ValidateFormStep"
],
"styles": ["size"], "styles": ["size"],
"settings": [ "settings": [
{ {

View File

@ -140,11 +140,16 @@
get(field).fieldApi.clearValue() get(field).fieldApi.clearValue()
}) })
}, },
nextStep: () => { changeStep: ({ type, number }) => {
currentStep.update(step => step + 1) if (type === "next") {
}, currentStep.update(step => step + 1)
prevStep: () => { } else if (type === "prev") {
currentStep.update(step => Math.max(1, step - 1)) currentStep.update(step => Math.max(1, step - 1))
} else if (type === "first") {
currentStep.set(1)
} else if (type === "specific" && number && !isNaN(number)) {
currentStep.set(number)
}
}, },
setStep: step => { setStep: step => {
if (step) { if (step) {
@ -249,8 +254,7 @@
const actions = [ const actions = [
{ type: ActionTypes.ValidateForm, callback: formApi.validate }, { type: ActionTypes.ValidateForm, callback: formApi.validate },
{ type: ActionTypes.ClearForm, callback: formApi.clear }, { type: ActionTypes.ClearForm, callback: formApi.clear },
{ type: ActionTypes.NextFormStep, callback: formApi.nextStep }, { type: ActionTypes.ChangeFormStep, callback: formApi.changeStep },
{ type: ActionTypes.PrevFormStep, callback: formApi.prevStep },
] ]
</script> </script>