new model creation, requires styling and CSS updates
This commit is contained in:
parent
987135f7b4
commit
374a6b4bc6
|
@ -1,4 +1,5 @@
|
||||||
import { writable } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
|
import { cloneDeep } from "lodash/fp";
|
||||||
import api from "../api"
|
import api from "../api"
|
||||||
|
|
||||||
export const getBackendUiStore = () => {
|
export const getBackendUiStore = () => {
|
||||||
|
@ -56,38 +57,47 @@ export const getBackendUiStore = () => {
|
||||||
select: model => store.update(state => {
|
select: model => store.update(state => {
|
||||||
state.selectedModel = model;
|
state.selectedModel = model;
|
||||||
// TODO: prevent pointing to same obj
|
// TODO: prevent pointing to same obj
|
||||||
state.draftModel = model;
|
state.draftModel = cloneDeep(model);
|
||||||
state.selectedField = null
|
state.selectedField = null
|
||||||
return state
|
return state;
|
||||||
}),
|
}),
|
||||||
save: model =>
|
save: async ({ instanceId, model }) => {
|
||||||
store.update(async state => {
|
const SAVE_MODEL_URL = `/api/${instanceId}/models`
|
||||||
const SAVE_MODEL_URL = `/api/${state.selectedDatabase._id}/models`
|
const response = await api.post(SAVE_MODEL_URL, model)
|
||||||
const response = await api.post(SAVE_MODEL_URL, model)
|
const savedModel = await response.json()
|
||||||
const savedModel = await response.json()
|
|
||||||
|
store.update(state => {
|
||||||
|
// New model
|
||||||
|
if (!model._id) {
|
||||||
|
state.models = [...state.models, savedModel]
|
||||||
|
} else {
|
||||||
|
const existingIdx = state.models.findIndex(({ _id }) => _id === model._id);
|
||||||
|
state.models.splice(existingIdx, 1, savedModel);
|
||||||
|
state.models = state.models
|
||||||
|
}
|
||||||
|
|
||||||
state.models = [...state.models, savedModel]
|
|
||||||
state.selectedModel = savedModel
|
state.selectedModel = savedModel
|
||||||
state.draftModel = savedModel
|
state.draftModel = savedModel
|
||||||
state.selectedView = `all_${savedModel._id}`
|
state.selectedView = `all_${savedModel._id}`
|
||||||
return state
|
return state
|
||||||
}),
|
})
|
||||||
addField: field => {
|
},
|
||||||
store.update(state => {
|
addField: field => {
|
||||||
if (!state.draftModel.schema) {
|
store.update(state => {
|
||||||
state.draftModel.schema = {}
|
if (!state.draftModel.schema) {
|
||||||
}
|
state.draftModel.schema = {}
|
||||||
|
}
|
||||||
|
|
||||||
state.draftModel.schema = {
|
state.draftModel.schema = {
|
||||||
...state.draftModel.schema,
|
...state.draftModel.schema,
|
||||||
[field.name]: field
|
[field.name]: field
|
||||||
}
|
}
|
||||||
|
|
||||||
state.selectedField = field
|
state.selectedField = field
|
||||||
|
|
||||||
return state
|
return state
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
views: {
|
views: {
|
||||||
select: view =>
|
select: view =>
|
||||||
|
|
|
@ -21,12 +21,11 @@
|
||||||
$: required =
|
$: required =
|
||||||
constraints && constraints.presence && !constraints.presence.allowEmpty
|
constraints && constraints.presence && !constraints.presence.allowEmpty
|
||||||
|
|
||||||
$: console.log(field)
|
|
||||||
|
|
||||||
const save = () => {
|
const save = () => {
|
||||||
// constraints.presence = required ? { allowEmpty: false } : false
|
backendUiStore.actions.models.save({
|
||||||
// draft[field.name] = { type, constraints }
|
instanceId: $backendUiStore.selectedDatabase._id,
|
||||||
backendUiStore.actions.models.save($backendUiStore.draftModel)
|
model: $backendUiStore.draftModel
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
import { Button, Switcher } from "@budibase/bbui"
|
import { Button, Switcher } from "@budibase/bbui"
|
||||||
import { store, backendUiStore } from "builderStore"
|
import { store, backendUiStore } from "builderStore"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
import FieldView from "./FieldView.svelte"
|
import FieldView from "./FieldView.svelte";
|
||||||
|
|
||||||
const { open, close } = getContext("simple-modal")
|
const { open, close } = getContext("simple-modal")
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
let selectedTab = "SETUP"
|
let selectedTab = "SETUP"
|
||||||
|
|
||||||
// TODO: draftModel undefined after save
|
|
||||||
$: edited = $backendUiStore.draftModel.name !== $backendUiStore.selectedModel.name
|
$: edited = $backendUiStore.draftModel.name !== $backendUiStore.selectedModel.name
|
||||||
|
|
||||||
async function deleteModel() {
|
async function deleteModel() {
|
||||||
|
@ -41,7 +40,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
async function saveModel() {
|
async function saveModel() {
|
||||||
await backendUiStore.actions.models.save($backendUiStore.draftModel)
|
await backendUiStore.actions.models.save({
|
||||||
|
instanceId: $backendUiStore.selectedDatabase._id,
|
||||||
|
model: $backendUiStore.draftModel
|
||||||
|
})
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -63,7 +65,12 @@
|
||||||
<Button wide secondary>Import CSV</Button>
|
<Button wide secondary>Import CSV</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<Button attention wide on:click={saveModel}>Save</Button>
|
<Button
|
||||||
|
attention
|
||||||
|
wide
|
||||||
|
on:click={saveModel}>
|
||||||
|
Save
|
||||||
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
{:else if selectedTab === 'DELETE'}
|
{:else if selectedTab === 'DELETE'}
|
||||||
<div class="titled-input">
|
<div class="titled-input">
|
||||||
|
|
Loading…
Reference in New Issue