diff --git a/packages/builder/src/database/DatabaseRoot.svelte b/packages/builder/src/database/DatabaseRoot.svelte index 547a62cee0..2109786ee0 100644 --- a/packages/builder/src/database/DatabaseRoot.svelte +++ b/packages/builder/src/database/DatabaseRoot.svelte @@ -8,6 +8,7 @@ import DropdownButton from "../common/DropdownButton.svelte" import ActionButton from "../common/ActionButton.svelte" import Modal from "../common/Modal.svelte" + import * as api from "./ModelDataTable/api" import { CreateEditRecordModal, CreateEditModelModal, @@ -19,8 +20,11 @@ let selectedRecord - function selectRecord(record) { - selectedRecord = record + async function selectRecord(record) { + selectedRecord = await api.loadRecord(record.key, { + appname: $store.appname, + instanceId: $backendUiStore.selectedDatabase.id, + }) } function onClosed() { diff --git a/packages/builder/src/database/ModelDataTable/api.js b/packages/builder/src/database/ModelDataTable/api.js index c4a8062971..0d9f275504 100644 --- a/packages/builder/src/database/ModelDataTable/api.js +++ b/packages/builder/src/database/ModelDataTable/api.js @@ -20,6 +20,12 @@ export async function deleteRecord(record, { appname, instanceId }) { return response } +export async function loadRecord(key, { appname, instanceId }) { + const LOAD_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record${key}` + const response = await api.get(LOAD_RECORDS_URL) + return await response.json() +} + export async function saveRecord(record, { appname, instanceId }) { let recordBase = { ...record } diff --git a/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte b/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte index 7d00256f3c..68e50db502 100644 --- a/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte +++ b/packages/builder/src/database/ModelDataTable/modals/CreateEditRecord.svelte @@ -5,12 +5,16 @@ import Modal from "../../../common/Modal.svelte" import ActionButton from "../../../common/ActionButton.svelte" import Select from "../../../common/Select.svelte" - import { getNewRecord, joinKey } from "../../../common/core" + import { getNewRecord, joinKey, getExactNodeForKey } from "../../../common/core" + import RecordFieldControl from "./RecordFieldControl.svelte" import * as api from "../api" + import ErrorsBox from "../../../common/ErrorsBox.svelte" export let record export let onClosed + let errors = [] + const childModelsForModel = compose( flatten, map("children"), @@ -25,12 +29,18 @@ ? childModelsForModel($store.hierarchy) : $store.hierarchy.children - $: selectedModel = selectedModel || models[0] + let selectedModel + $: { + if (record) { + selectedModel = getExactNodeForKey($store.hierarchy)(record.key) + } else { + selectedModel = selectedModel || models[0] + } + } $: modelFields = selectedModel - ? selectedModel.fields.map(({ name }) => name) + ? selectedModel.fields : [] - function getCurrentCollectionKey(selectedRecord) { return selectedRecord @@ -38,7 +48,7 @@ : joinKey(selectedModel.collectionName) } - $: editingRecord = editingRecord || record || getNewRecord(selectedModel, getCurrentCollectionKey($backendUiStore.selectedRecord)) + $: editingRecord = record || editingRecord || getNewRecord(selectedModel, getCurrentCollectionKey($backendUiStore.selectedRecord)) function closed() { editingRecord = null @@ -60,6 +70,7 @@

Create / Edit Record

+
{#if !record} @@ -72,17 +83,11 @@
{/if} - {#each modelFields as field} -
- -
- -
-
+ {#each (modelFields || []) as field} + {/each}