adds method on store to get path of IDs to component
This commit is contained in:
parent
59624741de
commit
1be5a248cb
|
@ -2,7 +2,7 @@
|
||||||
import { filter, cloneDeep, last, concat, isEmpty, values } from "lodash/fp"
|
import { filter, cloneDeep, last, concat, isEmpty, values } from "lodash/fp"
|
||||||
import { pipe, getNode, constructHierarchy } from "components/common/core"
|
import { pipe, getNode, constructHierarchy } from "components/common/core"
|
||||||
import * as backendStoreActions from "./backend"
|
import * as backendStoreActions from "./backend"
|
||||||
import { writable } from "svelte/store"
|
import { writable, get } from "svelte/store"
|
||||||
import { defaultPagesObject } from "components/userInterface/pagesParsing/defaultPagesObject"
|
import { defaultPagesObject } from "components/userInterface/pagesParsing/defaultPagesObject"
|
||||||
import api from "../api"
|
import api from "../api"
|
||||||
import { getExactComponent } from "components/userInterface/pagesParsing/searchComponents"
|
import { getExactComponent } from "components/userInterface/pagesParsing/searchComponents"
|
||||||
|
@ -92,6 +92,7 @@ export const getStore = () => {
|
||||||
store.moveUpComponent = moveUpComponent(store)
|
store.moveUpComponent = moveUpComponent(store)
|
||||||
store.moveDownComponent = moveDownComponent(store)
|
store.moveDownComponent = moveDownComponent(store)
|
||||||
store.copyComponent = copyComponent(store)
|
store.copyComponent = copyComponent(store)
|
||||||
|
store.getPathToComponent = getPathToComponent(store)
|
||||||
store.addTemplatedComponent = addTemplatedComponent(store)
|
store.addTemplatedComponent = addTemplatedComponent(store)
|
||||||
store.setMetadataProp = setMetadataProp(store)
|
store.setMetadataProp = setMetadataProp(store)
|
||||||
return 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) => {
|
const getParent = (rootProps, child) => {
|
||||||
let parent
|
let parent
|
||||||
walkProps(rootProps, (p, breakWalk) => {
|
walkProps(rootProps, (p, breakWalk) => {
|
||||||
|
|
Loading…
Reference in New Issue