Merge branch 'new-backend' of github.com:Budibase/budibase into new-backend

This commit is contained in:
Martin McKeaveney 2020-03-26 10:10:37 +00:00
commit 993af0e2c8
2 changed files with 20 additions and 19 deletions

View File

@ -12,6 +12,7 @@ import { generate } from "shortid"
export { canDeleteIndex } from "../../../core/src/templateApi/canDeleteIndex" export { canDeleteIndex } from "../../../core/src/templateApi/canDeleteIndex"
export { canDeleteRecord } from "../../../core/src/templateApi/canDeleteRecord" export { canDeleteRecord } from "../../../core/src/templateApi/canDeleteRecord"
export { userWithFullAccess } from "../../../core/src/index" export { userWithFullAccess } from "../../../core/src/index"
export { joinKey } from "../../../core/src/common"
export const pipe = common.$ export const pipe = common.$

View File

@ -5,14 +5,12 @@
import Modal from "../../../common/Modal.svelte" import Modal from "../../../common/Modal.svelte"
import ActionButton from "../../../common/ActionButton.svelte" import ActionButton from "../../../common/ActionButton.svelte"
import Select from "../../../common/Select.svelte" import Select from "../../../common/Select.svelte"
import { getNewRecord } from "../../../common/core" import { getNewRecord, joinKey } from "../../../common/core"
import * as api from "../api" import * as api from "../api"
export let record export let record
export let onClosed export let onClosed
let selectedModel
const childModelsForModel = compose( const childModelsForModel = compose(
flatten, flatten,
map("children"), map("children"),
@ -23,24 +21,38 @@
appname: $store.appname, appname: $store.appname,
instanceId: $backendUiStore.selectedDatabase.id, instanceId: $backendUiStore.selectedDatabase.id,
} }
$: recordFields = record ? Object.keys(record) : []
$: models = $backendUiStore.selectedRecord $: models = $backendUiStore.selectedRecord
? childModelsForModel($store.hierarchy) ? childModelsForModel($store.hierarchy)
: $store.hierarchy.children : $store.hierarchy.children
$: selectedModel = selectedModel || models[0]
$: modelFields = selectedModel $: modelFields = selectedModel
? selectedModel.fields.map(({ name }) => name) ? 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() { async function saveRecord() {
const recordResponse = await api.saveRecord( const recordResponse = await api.saveRecord(
record || selectedModel, editingRecord,
currentAppInfo currentAppInfo
) )
backendUiStore.update(state => { backendUiStore.update(state => {
state.selectedView = state.selectedView state.selectedView = state.selectedView
return state return state
}) })
onClosed() closed()
} }
</script> </script>
@ -66,19 +78,7 @@
class="uk-input" class="uk-input"
id="form-stacked-text" id="form-stacked-text"
type="text" type="text"
bind:value={selectedModel[field]} /> bind:value={editingRecord[field]} />
</div>
</div>
{/each}
{#each recordFields as field}
<div class="uk-margin">
<label class="uk-form-label" for="form-stacked-text">{field}</label>
<div class="uk-form-controls">
<input
class="uk-input"
id="form-stacked-text"
type="text"
bind:value={record[field]} />
</div> </div>
</div> </div>
{/each} {/each}