From f04b860146e4881595436de8850a3ba768f5ddb1 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 20 Aug 2021 14:12:52 +0100 Subject: [PATCH] Automatically name and number form step components upon creation --- .../src/builderStore/store/frontend.js | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 1924ae07a2..192ade9e5d 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -20,7 +20,12 @@ import { fetchComponentLibDefinitions } from "../loadComponentLibraries" import api from "../api" import { FrontendTypes } from "constants" import analytics from "analytics" -import { findComponentType, findComponentParent } from "../storeUtils" +import { + findComponentType, + findComponentParent, + findClosestMatchingComponent, + findAllMatchingComponents, +} from "../storeUtils" import { uuid } from "../uuid" import { removeBindings } from "../dataBinding" @@ -334,6 +339,18 @@ export const getFrontendStore = () => { if (definition.hasChildren) { extras._children = [] } + if (componentName.endsWith("/formstep")) { + const parentForm = findClosestMatchingComponent( + get(currentAsset).props, + get(selectedComponent)._id, + component => component._component.endsWith("/form") + ) + const formSteps = findAllMatchingComponents(parentForm, component => + component._component.endsWith("/formstep") + ) + extras.step = formSteps.length + 1 + extras._instanceName = `Step ${formSteps.length + 1}` + } return { _id: uuid(),