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} -
+
{#each errors as error} -
+
{error.field ? `${error.field}: ` : ''}{error.error}
{/each} -
+
+ + {/if} - diff --git a/packages/builder/src/common/core.js b/packages/builder/src/common/core.js index dbdd186aa3..2274d9d028 100644 --- a/packages/builder/src/common/core.js +++ b/packages/builder/src/common/core.js @@ -9,6 +9,8 @@ import { find, filter, keyBy, flatten, map } from "lodash/fp" import { generateSchema } from "../../../core/src/indexing/indexSchemaCreator" import { generate } from "shortid" +export { canDeleteIndex } from "../../../core/src/templateApi/canDeleteIndex" +export { canDeleteRecord } from "../../../core/src/templateApi/canDeleteRecord" export { userWithFullAccess } from "../../../core/src/index" export const pipe = common.$ diff --git a/packages/builder/src/database/ActionsHeader.svelte b/packages/builder/src/database/ActionsHeader.svelte index c763abc359..f012bd2bb3 100644 --- a/packages/builder/src/database/ActionsHeader.svelte +++ b/packages/builder/src/database/ActionsHeader.svelte @@ -31,9 +31,6 @@
- {#if $store.errors && $store.errors.length > 0} - - {/if}