diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index ded766e755..153cba784f 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -13,6 +13,8 @@ import { constructHierarchy, templateApi, isIndex, + canDeleteIndex, + canDeleteRecord } from "../../common/core" export const getBackendUiStore = () => { @@ -183,7 +185,7 @@ export const saveCurrentNode = store => () => { const defaultIndex = templateApi(state.hierarchy).getNewIndexTemplate( cloned.parent() ) - defaultIndex.name = `all_${cloned.collectionName}` + defaultIndex.name = `all_${cloned.name}s` defaultIndex.allowedRecordNodeIds = [cloned.nodeId] } @@ -202,14 +204,27 @@ export const deleteCurrentNode = store => () => { ? state.hierarchy.children.find(node => node !== state.currentNode) : nodeToDelete.parent() - const recordOrIndexKey = hierarchyFunctions.isRecord(nodeToDelete) ? "children" : "indexes"; + const isRecord = hierarchyFunctions.isRecord(nodeToDelete) + + const check = isRecord + ? canDeleteRecord(nodeToDelete) + : canDeleteIndex(nodeToDelete) + + if (!check.canDelete) { + state.errors = check.errors.map(e => ({ error: e })) + return state + } + + const recordOrIndexKey = isRecord ? "children" : "indexes" // remove the selected record or index - nodeToDelete.parent()[recordOrIndexKey] = remove( - nodeToDelete.parent()[recordOrIndexKey], - node => node.nodeId === nodeToDelete.nodeId + const newCollection = remove( + node => node.nodeId === nodeToDelete.nodeId, + nodeToDelete.parent()[recordOrIndexKey] ) + nodeToDelete.parent()[recordOrIndexKey] = newCollection + state.errors = [] saveBackend(state) return state diff --git a/packages/builder/src/common/ErrorsBox.svelte b/packages/builder/src/common/ErrorsBox.svelte index 9ddea77a49..117f3aae5a 100644 --- a/packages/builder/src/common/ErrorsBox.svelte +++ b/packages/builder/src/common/ErrorsBox.svelte @@ -5,25 +5,14 @@ {#if hasErrors} -