record keys as names

This commit is contained in:
Martin McKeaveney 2020-06-25 20:04:58 +01:00
parent b07f608ffe
commit 48f3392152
10 changed files with 40 additions and 34 deletions

View File

@ -5,6 +5,16 @@
import { routes } from "../routify/routes" import { routes } from "../routify/routes"
import { store, initialise } from "builderStore" import { store, initialise } from "builderStore"
import NotificationDisplay from "components/common/Notification/NotificationDisplay.svelte" import NotificationDisplay from "components/common/Notification/NotificationDisplay.svelte"
import { notifier } from "builderStore/store/notifications"
function showErrorBanner() {
notifier.danger("Whoops! Looks like we're having trouble. Please refresh the page.")
}
onMount(async () => {
window.addEventListener("error", showErrorBanner)
window.addEventListener("unhandledrejection", showErrorBanner)
})
$basepath = "/_builder" $basepath = "/_builder"
</script> </script>

View File

@ -68,11 +68,11 @@ export const getBackendUiStore = () => {
return state return state
}), }),
save: async ({ model }) => { save: async ({ model }) => {
const updatedModel = cloneDeep(model)
const SAVE_MODEL_URL = `/api/models` const SAVE_MODEL_URL = `/api/models`
await api.post(SAVE_MODEL_URL, updatedModel) const response = await api.post(SAVE_MODEL_URL, model)
const json = await response.json()
await store.actions.models.fetch() await store.actions.models.fetch()
store.actions.models.select(json)
}, },
addField: field => { addField: field => {
store.update(state => { store.update(state => {

View File

@ -60,7 +60,7 @@
<style> <style>
.fields.selected { .fields.selected {
background: var(--light-grey); background: var(--grey-1);
} }
h3 { h3 {

View File

@ -88,7 +88,7 @@
position: absolute; position: absolute;
right: 15%; right: 15%;
padding: 20px; padding: 20px;
background: var(--light-grey); background: var(--grey-1);
border: 1px solid var(--grey); border: 1px solid var(--grey);
} }

View File

@ -58,7 +58,7 @@
border-radius: 3px; border-radius: 3px;
color: var(--ink-lighter); color: var(--ink-lighter);
font-size: 14px; font-size: 14px;
background: var(--light-grey); background: var(--grey-1);
} }
span:hover { span:hover {

View File

@ -2,6 +2,7 @@
import { backendUiStore } from "builderStore" import { backendUiStore } from "builderStore"
import { uuid } from "builderStore/uuid" import { uuid } from "builderStore/uuid"
import { fade } from "svelte/transition" import { fade } from "svelte/transition"
import { notifier } from "builderStore/store/notifications"
import { FIELDS, BLOCKS, MODELS } from "constants/backend" import { FIELDS, BLOCKS, MODELS } from "constants/backend"
import Block from "components/common/Block.svelte" import Block from "components/common/Block.svelte"
@ -12,15 +13,13 @@
function createModel(model) { function createModel(model) {
const { schema, ...rest } = $backendUiStore.selectedModel const { schema, ...rest } = $backendUiStore.selectedModel
// const newModel = { ...model, schema: {} }
backendUiStore.actions.models.save({ backendUiStore.actions.models.save({
model: { model: {
...model, ...model,
schema: {}, ...rest
...rest,
}, },
}) })
notifier.success(`${model.name} model created.`)
} }
</script> </script>

View File

@ -64,13 +64,13 @@
on:click={() => selectModel(model)} /> on:click={() => selectModel(model)} />
{#if model._id === $backendUiStore.selectedModel._id} {#if model._id === $backendUiStore.selectedModel._id}
<div in:slide> <div in:slide>
{#each Object.keys(model.schema) as fieldId} {#each Object.keys(model.schema) as fieldName}
<ListItem <ListItem
selected={model._id === $backendUiStore.selectedModel._id && fieldId === $backendUiStore.selectedField} selected={model._id === $backendUiStore.selectedModel._id && fieldName === $backendUiStore.selectedField}
indented indented
icon="ri-layout-column-fill" icon="ri-layout-column-fill"
title={model.schema[fieldId].name} title={model.schema[fieldName].name}
on:click={() => selectModel(model, fieldId)} /> on:click={() => selectModel(model, fieldName)} />
{/each} {/each}
</div> </div>
{/if} {/if}

View File

@ -23,17 +23,17 @@
field.constraints.presence && field.constraints.presence &&
!constraints.presence.allowEmpty !constraints.presence.allowEmpty
function attachModelIdToSchema(evt) { // function attachModelIdToSchema(evt) {
const { draftModel } = $backendUiStore // const { draftModel } = $backendUiStore
if ($backendUiStore.selectedField !== evt.target.value) { // if ($backendUiStore.selectedField !== evt.target.value) {
delete draftModel.schema[$backendUiStore.selectedField] // delete draftModel.schema[$backendUiStore.selectedField]
draftModel.schema[evt.target.value] = field // draftModel.schema[evt.target.value] = field
backendUiStore.update(state => { // backendUiStore.update(state => {
state.selectedField = evt.target.value // state.selectedField = evt.target.value
return state // return state
}) // })
} // }
} // }
</script> </script>
<div class="info"> <div class="info">
@ -78,10 +78,7 @@
{:else if field.type === 'link'} {:else if field.type === 'link'}
<div class="field"> <div class="field">
<label>Link</label> <label>Link</label>
<select <select class="budibase__input" bind:value={field.modelId}>
class="budibase__input"
bind:value={field.modelId}
on:change={attachModelIdToSchema}>
<option value={''} /> <option value={''} />
{#each $backendUiStore.models as model} {#each $backendUiStore.models as model}
{#if model._id !== $backendUiStore.draftModel._id} {#if model._id !== $backendUiStore.draftModel._id}

View File

@ -51,7 +51,7 @@ exports.save = async function(ctx) {
[`all_${modelToSave._id}`]: { [`all_${modelToSave._id}`]: {
map: `function(doc) { map: `function(doc) {
if (doc.modelId === "${modelToSave._id}") { if (doc.modelId === "${modelToSave._id}") {
emit(doc[doc.key], doc._id); emit(doc._id);
} }
}`, }`,
}, },
@ -75,7 +75,7 @@ exports.destroy = async function(ctx) {
// Delete all records for that model // Delete all records for that model
const records = await db.query(`database/${modelViewId}`) const records = await db.query(`database/${modelViewId}`)
await db.bulkDocs( await db.bulkDocs(
records.rows.map(record => ({ id: record.id, _deleted: true })) records.rows.map(record => ({ _id: record.id, _deleted: true }))
) )
// Delete linked record fields in dependent models // Delete linked record fields in dependent models

View File

@ -56,8 +56,8 @@ exports.save = async function(ctx) {
const doc = row.doc const doc = row.doc
return { return {
...doc, ...doc,
[model._id]: doc[model._id] [model.name]: doc[model.name]
? [...doc[model._id], record._id] ? [...doc[model.name], record._id]
: [record._id], : [record._id],
} }
}) })