From 3113e7ce9144314d3e3d11eb6e4d6d2a09fe5496 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Thu, 26 Mar 2020 09:45:04 +0000 Subject: [PATCH] bugfix: model renamed on record creation --- packages/builder/src/common/core.js | 1 + .../modals/CreateEditRecord.svelte | 38 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/builder/src/common/core.js b/packages/builder/src/common/core.js index 2274d9d028..e996fbe229 100644 --- a/packages/builder/src/common/core.js +++ b/packages/builder/src/common/core.js @@ -12,6 +12,7 @@ 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 { joinKey } from "../../../core/src/common" export const pipe = common.$ diff --git a/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte b/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte index 23e85900c2..c7ac755825 100644 --- a/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte +++ b/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte @@ -5,14 +5,12 @@ import Modal from "../../../common/Modal.svelte" import ActionButton from "../../../common/ActionButton.svelte" import Select from "../../../common/Select.svelte" - import { getNewRecord } from "../../../common/core" + import { getNewRecord, joinKey } from "../../../common/core" import * as api from "../api" export let record export let onClosed - let selectedModel - const childModelsForModel = compose( flatten, map("children"), @@ -23,24 +21,38 @@ appname: $store.appname, instanceId: $backendUiStore.selectedDatabase.id, } - $: recordFields = record ? Object.keys(record) : [] $: models = $backendUiStore.selectedRecord ? childModelsForModel($store.hierarchy) : $store.hierarchy.children + + $: selectedModel = selectedModel || models[0] + $: modelFields = selectedModel ? selectedModel.fields.map(({ name }) => name) : [] + $: currentCollectionKey = + $store.selectedRecord + ? joinKey($store.selectedRecord.key, selectedModel.collectionName) + : joinKey(selectedModel.collectionName) + + $: editingRecord = editingRecord || record || getNewRecord(selectedModel, currentCollectionKey) + + function closed() { + editingRecord = null + onClosed() + } + async function saveRecord() { const recordResponse = await api.saveRecord( - record || selectedModel, + editingRecord, currentAppInfo ) backendUiStore.update(state => { state.selectedView = state.selectedView return state }) - onClosed() + closed() } @@ -66,19 +78,7 @@ class="uk-input" id="form-stacked-text" type="text" - bind:value={selectedModel[field]} /> - - - {/each} - {#each recordFields as field} -
- -
- + bind:value={editingRecord[field]} />
{/each}