1
0
Fork 0
mirror of synced 2024-07-10 16:55:46 +12:00
This commit is contained in:
Andrew Kingston 2023-12-08 16:40:50 +00:00
parent 173a76dc52
commit f4d2efdaa1
4 changed files with 28 additions and 33 deletions

View file

@ -31,6 +31,7 @@
$: dataSource = getDatasourceForProvider($currentAsset, componentInstance) $: dataSource = getDatasourceForProvider($currentAsset, componentInstance)
$: emitCurrentStep(currentStep) $: emitCurrentStep(currentStep)
$: sectionName = getSectionName($multiStepStore) $: sectionName = getSectionName($multiStepStore)
$: stepConfigInstance = buildPseudoInstance(value[currentStep] || {})
$: stepDef = { $: stepDef = {
settings: [ settings: [
{ {
@ -39,7 +40,7 @@
settings: [ settings: [
{ {
type: "formStepControls", type: "formStepControls",
label: "Multi-steps", label: "Steps",
key: "steps", key: "steps",
}, },
{ {
@ -88,40 +89,32 @@
} }
const addStep = () => { const addStep = () => {
const nextStep = currentStep + 1 dispatch("change", value.toSpliced(currentStep + 1, 0, {}))
dispatch("change", [
...value.slice(0, nextStep),
{},
...value.slice(nextStep),
])
multiStepStore.update(state => ({ multiStepStore.update(state => ({
...state, ...state,
currentStep: nextStep, currentStep: currentStep + 1,
})) }))
} }
const removeStep = () => { const removeStep = () => {
dispatch("change", value.toSpliced(currentStep, 1)) dispatch("change", value.toSpliced(currentStep, 1))
const newStep = Math.min(currentStep, stepCount - 2)
multiStepStore.update(state => ({ multiStepStore.update(state => ({
...state, ...state,
currentStep: newStep, currentStep: Math.min(currentStep, stepCount - 2),
})) }))
} }
const previousStep = () => { const previousStep = () => {
const prevStepIdx = Math.max(currentStep - 1, 0)
multiStepStore.update(state => ({ multiStepStore.update(state => ({
...state, ...state,
currentStep: prevStepIdx, currentStep: Math.max(currentStep - 1, 0),
})) }))
} }
const nextStep = () => { const nextStep = () => {
const nextStepIdx = currentStep + 1
multiStepStore.update(state => ({ multiStepStore.update(state => ({
...state, ...state,
currentStep: Math.min(nextStepIdx, value.length - 1), currentStep: Math.min(currentStep + 1, value.length - 1),
})) }))
} }
@ -130,9 +123,7 @@
...value[currentStep], ...value[currentStep],
[field.key]: val, [field.key]: val,
} }
let newValue = value.slice() dispatch("change", value.toSpliced(currentStep, 1, newStep))
newValue[currentStep] = newStep
dispatch("change", newValue)
} }
const handleStepAction = action => { const handleStepAction = action => {
@ -162,18 +153,17 @@
const buildPseudoInstance = ({ buttons, fields, title, desc }) => { const buildPseudoInstance = ({ buttons, fields, title, desc }) => {
return { return {
_id: Helpers.uuid(), _id: Helpers.uuid(),
_component: "@budibase/standard-components/multistepformblock-step", _component: "@budibase/standard-components/multistepformblockstep",
_instanceName: `Step ${currentStep + 1}`,
buttons: buttons || defaultButtonConfig, buttons: buttons || defaultButtonConfig,
fields, fields,
title, title,
desc, desc,
// Needed for field configuration
dataSource, dataSource,
step: currentStep + 1,
_instanceName: `Step ${currentStep + 1}`,
} }
} }
$: stepConfigInstance = buildPseudoInstance(value[currentStep] || {})
</script> </script>
<div class="nested-section"> <div class="nested-section">

View file

@ -15,15 +15,17 @@
</script> </script>
{#if stepCount === 1} {#if stepCount === 1}
<ActionButton <div class="stretch">
icon="MultipleAdd" <ActionButton
secondary icon="MultipleAdd"
on:click={() => { secondary
stepAction("addStep") on:click={() => {
}} stepAction("addStep")
> }}
Add Step >
</ActionButton> Add Step
</ActionButton>
</div>
{:else} {:else}
<div class="step-actions"> <div class="step-actions">
<ActionButton <ActionButton
@ -65,11 +67,13 @@
{/if} {/if}
<style> <style>
.stretch :global(.spectrum-ActionButton) {
width: 100%;
}
.step-actions { .step-actions {
display: flex; display: flex;
gap: var(--spacing-s); gap: var(--spacing-s);
} }
.step-actions :global(.spectrum-ActionButton) { .step-actions :global(.spectrum-ActionButton) {
height: 32px; height: 32px;
} }

View file

@ -210,7 +210,7 @@
</DetailSummary> </DetailSummary>
{/if} {/if}
{/each} {/each}
{#if componentDefinition?.block && !tag} {#if componentDefinition?.block && !tag && componentDefinition.ejectable !== false}
<DetailSummary name="Eject" collapsible={false}> <DetailSummary name="Eject" collapsible={false}>
<EjectBlockButton /> <EjectBlockButton />
</DetailSummary> </DetailSummary>

View file

@ -6038,6 +6038,7 @@
"icon": "AssetsAdded", "icon": "AssetsAdded",
"block": true, "block": true,
"hasChildren": false, "hasChildren": false,
"ejectable": false,
"size": { "size": {
"width": 400, "width": 400,
"height": 400 "height": 400