From 72ce6833c018bcfa0e42ecc705c50666ca864f5b Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Fri, 27 Mar 2020 10:32:37 +0000 Subject: [PATCH] rename record --- packages/builder/src/builderStore/store/backend.js | 2 +- packages/builder/src/database/FieldView.svelte | 2 +- packages/builder/src/database/ModelView.svelte | 4 ++-- packages/core/src/templateApi/fields.js | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index f6b20e7a90..1718c3adce 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -244,7 +244,7 @@ export const deleteCurrentNode = store => () => { export const saveField = store => field => { store.update(state => { - state.currentNode.fields = state.currentNode.fields.filter(f => f.name !== field.name) + state.currentNode.fields = state.currentNode.fields.filter(f => f.id !== field.id) templateApi(state.hierarchy).addField(state.currentNode, field) return state diff --git a/packages/builder/src/database/FieldView.svelte b/packages/builder/src/database/FieldView.svelte index 8e2fb98983..45944596cd 100644 --- a/packages/builder/src/database/FieldView.svelte +++ b/packages/builder/src/database/FieldView.svelte @@ -59,7 +59,7 @@ errors = validate.field(allFields)(clonedField) if (errors.length > 0) return field.typeOptions = cloneDeep(clonedField.typeOptions) - onFinished({ ...clonedField, ...field }) + onFinished({ ...field, ...clonedField }) } diff --git a/packages/builder/src/database/ModelView.svelte b/packages/builder/src/database/ModelView.svelte index eb3b7d21ad..d418083b23 100644 --- a/packages/builder/src/database/ModelView.svelte +++ b/packages/builder/src/database/ModelView.svelte @@ -38,8 +38,8 @@ $: models = $store.hierarchy.children $: parent = record && record.parent() - $: isChildModel = parent.name !== "root" - $: modelExistsInHierarchy = getNode( + $: isChildModel = parent && parent.name !== "root" + $: modelExistsInHierarchy = $store.currentNode && getNode( $store.hierarchy, $store.currentNode.nodeId ) diff --git a/packages/core/src/templateApi/fields.js b/packages/core/src/templateApi/fields.js index b8ac92c87e..f83fe63a01 100644 --- a/packages/core/src/templateApi/fields.js +++ b/packages/core/src/templateApi/fields.js @@ -9,6 +9,7 @@ import { import { all, getDefaultOptions } from "../types" import { applyRuleSet, makerule } from "../common/validationCommon" import { BadRequestError } from "../common/errors" +import { generate } from "shortid" export const fieldErrors = { AddFieldValidationFailed: "Add field validation: ", @@ -17,6 +18,7 @@ export const fieldErrors = { export const allowedTypes = () => keys(all) export const getNewField = type => ({ + id: generate(), name: "", // how field is referenced internally type, typeOptions: getDefaultOptions(type),