bugfix: views duplicated
This commit is contained in:
parent
6ab3003106
commit
9ee1132185
|
@ -12,6 +12,7 @@ import {
|
||||||
validate,
|
validate,
|
||||||
constructHierarchy,
|
constructHierarchy,
|
||||||
templateApi,
|
templateApi,
|
||||||
|
isIndex,
|
||||||
} from "../../common/core"
|
} from "../../common/core"
|
||||||
|
|
||||||
export const getBackendUiStore = () => {
|
export const getBackendUiStore = () => {
|
||||||
|
@ -81,6 +82,20 @@ export const saveBackend = async state => {
|
||||||
},
|
},
|
||||||
accessLevels: state.accessLevels,
|
accessLevels: state.accessLevels,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const instances_currentFirst = state.selectedDatabase
|
||||||
|
? [
|
||||||
|
state.appInstances.find(i => i.id === state.selectedDatabase.id),
|
||||||
|
...state.appInstances.filter(i => i.id !== state.selectedDatabase.id),
|
||||||
|
]
|
||||||
|
: state.appInstances
|
||||||
|
|
||||||
|
for (let instance of instances_currentFirst) {
|
||||||
|
await api.post(
|
||||||
|
`/_builder/instance/${state.appname}/${instance.id}/api/upgradeData`,
|
||||||
|
{ newHierarchy: state.hierarchy }
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const newRecord = (store, useRoot) => () => {
|
export const newRecord = (store, useRoot) => () => {
|
||||||
|
@ -111,14 +126,16 @@ export const selectExistingNode = store => nodeId => {
|
||||||
|
|
||||||
export const newIndex = (store, useRoot) => () => {
|
export const newIndex = (store, useRoot) => () => {
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
const shadowHierarchy = createShadowHierarchy(state.hierarchy)
|
state.shadowHierarchy = createShadowHierarchy(state.hierarchy)
|
||||||
state.currentNodeIsNew = true
|
state.currentNodeIsNew = true
|
||||||
state.errors = []
|
state.errors = []
|
||||||
const parent = useRoot
|
const parent = useRoot
|
||||||
? state.hierarchy
|
? state.shadowHierarchy
|
||||||
: getNode(state.hierarchy, state.currentNode.nodeId)
|
: getNode(state.shadowHierarchy, state.currentNode.nodeId)
|
||||||
|
|
||||||
state.currentNode = templateApi(shadowHierarchy).getNewIndexTemplate(parent)
|
state.currentNode = templateApi(state.shadowHierarchy).getNewIndexTemplate(
|
||||||
|
parent
|
||||||
|
)
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -130,7 +147,10 @@ export const saveCurrentNode = store => () => {
|
||||||
if (errors.length > 0) {
|
if (errors.length > 0) {
|
||||||
return state
|
return state
|
||||||
}
|
}
|
||||||
const parentNode = getNode(state.hierarchy, state.currentNode.parent().nodeId)
|
const parentNode = getNode(
|
||||||
|
state.hierarchy,
|
||||||
|
state.currentNode.parent().nodeId
|
||||||
|
)
|
||||||
|
|
||||||
const existingNode = getNode(state.hierarchy, state.currentNode.nodeId)
|
const existingNode = getNode(state.hierarchy, state.currentNode.nodeId)
|
||||||
|
|
||||||
|
@ -138,21 +158,27 @@ export const saveCurrentNode = store => () => {
|
||||||
if (existingNode) {
|
if (existingNode) {
|
||||||
// remove existing
|
// remove existing
|
||||||
index = existingNode.parent().children.indexOf(existingNode)
|
index = existingNode.parent().children.indexOf(existingNode)
|
||||||
existingNode.parent().children = existingNode.parent().children.filter(node => node.nodeId !== existingNode.nodeId);
|
if (isIndex(existingNode)) {
|
||||||
|
parentNode.indexes = parentNode.indexes.filter(
|
||||||
|
node => node.nodeId !== existingNode.nodeId
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
parentNode.children = parentNode.children.filter(
|
||||||
|
node => node.nodeId !== existingNode.nodeId
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// should add node into existing hierarchy
|
// should add node into existing hierarchy
|
||||||
const cloned = cloneDeep(state.currentNode)
|
const cloned = cloneDeep(state.currentNode)
|
||||||
templateApi(state.hierarchy).constructNode(parentNode, cloned)
|
templateApi(state.hierarchy).constructNode(parentNode, cloned)
|
||||||
|
|
||||||
const newIndexOfChild = child => {
|
if (isIndex(existingNode)) {
|
||||||
if (child === cloned) return index
|
parentNode.children = sortBy("name", parentNode.children)
|
||||||
const currentIndex = parentNode.children.indexOf(child)
|
} else {
|
||||||
return currentIndex >= index ? currentIndex + 1 : currentIndex
|
parentNode.indexes = sortBy("name", parentNode.indexes)
|
||||||
}
|
}
|
||||||
|
|
||||||
parentNode.children = sortBy(newIndexOfChild, parentNode.children)
|
|
||||||
|
|
||||||
if (!existingNode && state.currentNode.type === "record") {
|
if (!existingNode && state.currentNode.type === "record") {
|
||||||
const defaultIndex = templateApi(state.hierarchy).getNewIndexTemplate(
|
const defaultIndex = templateApi(state.hierarchy).getNewIndexTemplate(
|
||||||
cloned.parent()
|
cloned.parent()
|
||||||
|
|
|
@ -192,7 +192,6 @@ const useAnalytics = store => () => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const importAppDefinition = store => appDefinition => {
|
const importAppDefinition = store => appDefinition => {
|
||||||
store.update(s => {
|
store.update(s => {
|
||||||
s.hierarchy = appDefinition.hierarchy
|
s.hierarchy = appDefinition.hierarchy
|
||||||
|
@ -207,7 +206,6 @@ const importAppDefinition = store => appDefinition => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const createShadowHierarchy = hierarchy =>
|
const createShadowHierarchy = hierarchy =>
|
||||||
constructHierarchy(JSON.parse(JSON.stringify(hierarchy)))
|
constructHierarchy(JSON.parse(JSON.stringify(hierarchy)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue