record keys as names
This commit is contained in:
parent
b07f608ffe
commit
48f3392152
|
@ -5,6 +5,16 @@
|
|||
import { routes } from "../routify/routes"
|
||||
import { store, initialise } from "builderStore"
|
||||
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"
|
||||
</script>
|
||||
|
|
|
@ -68,11 +68,11 @@ export const getBackendUiStore = () => {
|
|||
return state
|
||||
}),
|
||||
save: async ({ model }) => {
|
||||
const updatedModel = cloneDeep(model)
|
||||
|
||||
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()
|
||||
store.actions.models.select(json)
|
||||
},
|
||||
addField: field => {
|
||||
store.update(state => {
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
|
||||
<style>
|
||||
.fields.selected {
|
||||
background: var(--light-grey);
|
||||
background: var(--grey-1);
|
||||
}
|
||||
|
||||
h3 {
|
||||
|
|
|
@ -88,7 +88,7 @@
|
|||
position: absolute;
|
||||
right: 15%;
|
||||
padding: 20px;
|
||||
background: var(--light-grey);
|
||||
background: var(--grey-1);
|
||||
border: 1px solid var(--grey);
|
||||
}
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
border-radius: 3px;
|
||||
color: var(--ink-lighter);
|
||||
font-size: 14px;
|
||||
background: var(--light-grey);
|
||||
background: var(--grey-1);
|
||||
}
|
||||
|
||||
span:hover {
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { backendUiStore } from "builderStore"
|
||||
import { uuid } from "builderStore/uuid"
|
||||
import { fade } from "svelte/transition"
|
||||
import { notifier } from "builderStore/store/notifications"
|
||||
import { FIELDS, BLOCKS, MODELS } from "constants/backend"
|
||||
import Block from "components/common/Block.svelte"
|
||||
|
||||
|
@ -12,15 +13,13 @@
|
|||
function createModel(model) {
|
||||
const { schema, ...rest } = $backendUiStore.selectedModel
|
||||
|
||||
// const newModel = { ...model, schema: {} }
|
||||
|
||||
backendUiStore.actions.models.save({
|
||||
model: {
|
||||
...model,
|
||||
schema: {},
|
||||
...rest,
|
||||
...model,
|
||||
...rest
|
||||
},
|
||||
})
|
||||
notifier.success(`${model.name} model created.`)
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
|
@ -64,13 +64,13 @@
|
|||
on:click={() => selectModel(model)} />
|
||||
{#if model._id === $backendUiStore.selectedModel._id}
|
||||
<div in:slide>
|
||||
{#each Object.keys(model.schema) as fieldId}
|
||||
{#each Object.keys(model.schema) as fieldName}
|
||||
<ListItem
|
||||
selected={model._id === $backendUiStore.selectedModel._id && fieldId === $backendUiStore.selectedField}
|
||||
selected={model._id === $backendUiStore.selectedModel._id && fieldName === $backendUiStore.selectedField}
|
||||
indented
|
||||
icon="ri-layout-column-fill"
|
||||
title={model.schema[fieldId].name}
|
||||
on:click={() => selectModel(model, fieldId)} />
|
||||
title={model.schema[fieldName].name}
|
||||
on:click={() => selectModel(model, fieldName)} />
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
@ -23,17 +23,17 @@
|
|||
field.constraints.presence &&
|
||||
!constraints.presence.allowEmpty
|
||||
|
||||
function attachModelIdToSchema(evt) {
|
||||
const { draftModel } = $backendUiStore
|
||||
if ($backendUiStore.selectedField !== evt.target.value) {
|
||||
delete draftModel.schema[$backendUiStore.selectedField]
|
||||
draftModel.schema[evt.target.value] = field
|
||||
backendUiStore.update(state => {
|
||||
state.selectedField = evt.target.value
|
||||
return state
|
||||
})
|
||||
}
|
||||
}
|
||||
// function attachModelIdToSchema(evt) {
|
||||
// const { draftModel } = $backendUiStore
|
||||
// if ($backendUiStore.selectedField !== evt.target.value) {
|
||||
// delete draftModel.schema[$backendUiStore.selectedField]
|
||||
// draftModel.schema[evt.target.value] = field
|
||||
// backendUiStore.update(state => {
|
||||
// state.selectedField = evt.target.value
|
||||
// return state
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
</script>
|
||||
|
||||
<div class="info">
|
||||
|
@ -78,10 +78,7 @@
|
|||
{:else if field.type === 'link'}
|
||||
<div class="field">
|
||||
<label>Link</label>
|
||||
<select
|
||||
class="budibase__input"
|
||||
bind:value={field.modelId}
|
||||
on:change={attachModelIdToSchema}>
|
||||
<select class="budibase__input" bind:value={field.modelId}>
|
||||
<option value={''} />
|
||||
{#each $backendUiStore.models as model}
|
||||
{#if model._id !== $backendUiStore.draftModel._id}
|
||||
|
|
|
@ -51,7 +51,7 @@ exports.save = async function(ctx) {
|
|||
[`all_${modelToSave._id}`]: {
|
||||
map: `function(doc) {
|
||||
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
|
||||
const records = await db.query(`database/${modelViewId}`)
|
||||
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
|
||||
|
|
|
@ -56,8 +56,8 @@ exports.save = async function(ctx) {
|
|||
const doc = row.doc
|
||||
return {
|
||||
...doc,
|
||||
[model._id]: doc[model._id]
|
||||
? [...doc[model._id], record._id]
|
||||
[model.name]: doc[model.name]
|
||||
? [...doc[model.name], record._id]
|
||||
: [record._id],
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue