diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js index 8c1538e098..81b1109a07 100644 --- a/packages/builder/src/builderStore/store/index.js +++ b/packages/builder/src/builderStore/store/index.js @@ -2,7 +2,7 @@ import { filter, cloneDeep, last, concat, isEmpty, values } from "lodash/fp" import { pipe, getNode, constructHierarchy } from "components/common/core" import * as backendStoreActions from "./backend" -import { writable } from "svelte/store" +import { writable, get } from "svelte/store" import { defaultPagesObject } from "components/userInterface/pagesParsing/defaultPagesObject" import api from "../api" import { getExactComponent } from "components/userInterface/pagesParsing/searchComponents" @@ -92,6 +92,7 @@ export const getStore = () => { store.moveUpComponent = moveUpComponent(store) store.moveDownComponent = moveDownComponent(store) store.copyComponent = copyComponent(store) + store.getPathToComponent = getPathToComponent(store) store.addTemplatedComponent = addTemplatedComponent(store) store.setMetadataProp = setMetadataProp(store) return store @@ -667,6 +668,38 @@ const copyComponent = store => component => { }) } +const getPathToComponent = store => component => { + + // Gets all the components to needed to construct a path. + const tempStore = get(store) + let pathComponents = [] + let parent = component; + let root = false + while (!root) { + parent = getParent(tempStore.currentPreviewItem.props, parent) + if (!parent) { + root = true + } else { + pathComponents.push(parent) + } + } + + // Remove root entry since it's the screen or page layout. + // Reverse array since we need the correct order of the IDs + const reversedComponents = pathComponents.reverse().slice(1) + + // Add component + const allComponents = [...reversedComponents, component] + + // Map IDs + const IdList = allComponents.map(c => c._id) + + // Construct ID Path: + const path = IdList.join('/') + + return path +} + const getParent = (rootProps, child) => { let parent walkProps(rootProps, (p, breakWalk) => { diff --git a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte index 2df4f8feef..72e91d0600 100644 --- a/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte +++ b/packages/builder/src/components/userInterface/ComponentsHierarchy.svelte @@ -1,4 +1,5 @@