column CRUD

This commit is contained in:
Martin McKeaveney 2020-08-07 17:41:20 +01:00
parent 10d798fe62
commit 160703863b
6 changed files with 46 additions and 57 deletions

View File

@ -57,7 +57,7 @@
] ]
}, },
"dependencies": { "dependencies": {
"@budibase/bbui": "^1.22.3", "@budibase/bbui": "^1.23.0",
"@budibase/client": "^0.1.1", "@budibase/client": "^0.1.1",
"@budibase/colorpicker": "^1.0.1", "@budibase/colorpicker": "^1.0.1",
"@nx-js/compiler-util": "^2.0.0", "@nx-js/compiler-util": "^2.0.0",

View File

@ -83,21 +83,31 @@ export const getBackendUiStore = () => {
await store.actions.models.fetch() await store.actions.models.fetch()
store.actions.models.select(savedModel) store.actions.models.select(savedModel)
}, },
addField: field => { saveField: ({ originalName, field }) => {
store.update(state => { store.update(state => {
if (!state.draftModel.schema) { // TODO: is this necessary?
state.draftModel.schema = {} // if (!state.draftModel.schema) {
} // state.draftModel.schema = {}
// }
// delete the original if renaming
delete state.draftModel.schema[originalName]
state.draftModel.schema = { state.draftModel.schema = {
...state.draftModel.schema, ...state.draftModel.schema,
[field.name]: cloneDeep(field), [field.name]: cloneDeep(field),
} }
state.selectedField = field.name store.actions.models.save({ model: state.draftModel })
return state return state
}) })
}, },
deleteField: field => {
store.update(state => {
delete state.draftModel.schema[field.name]
store.actions.models.save({ model: state.draftModel })
return state
})
}
}, },
views: { views: {
select: view => select: view =>

View File

@ -20,6 +20,8 @@
export let field = {} export let field = {}
export let columnName export let columnName
let originalName = columnName
$: required = $: required =
field.constraints && field.constraints &&
field.constraints.presence && field.constraints.presence &&
@ -33,13 +35,18 @@
} }
async function saveColumn() { async function saveColumn() {
backendUiStore.actions.models.addField({ // if existing
name: columnName, // update the name and type
field, backendUiStore.update(state => {
}) backendUiStore.actions.models.saveField({
originalName,
field: {
...field,
name: columnName
}
})
backendUiStore.actions.models.save({ return state
model: $backendUiStore.draftModel,
}) })
onClosed() onClosed()
} }

View File

@ -18,8 +18,10 @@
</Button> </Button>
</div> </div>
<DropdownMenu bind:this={dropdown} {anchor} align="left"> <DropdownMenu bind:this={dropdown} {anchor} align="left">
<h5>Create Column</h5>
<CreateEditTable onClosed={dropdown.hide} /> <CreateEditTable onClosed={dropdown.hide} />
</DropdownMenu> </DropdownMenu>
<style> <style>
</style> </style>

View File

@ -23,7 +23,7 @@
} }
function deleteField() { function deleteField() {
alert("Delete Field Not Implemented") backendUiStore.actions.models.deleteField(field)
} }
function save() {} function save() {}
@ -88,27 +88,4 @@
li:active { li:active {
color: var(--blue); color: var(--blue);
} }
.editor {
padding: var(--spacing-xl);
}
footer {
padding: var(--spacing-xl);
display: grid;
grid-template-columns: 1fr 1fr 1fr 1fr;
gap: 20px;
border-bottom-left-radius: 0.5rem;
border-bottom-left-radius: 0.5rem;
}
.button-margin-3 {
grid-column-start: 3;
display: grid;
}
.button-margin-4 {
grid-column-start: 4;
display: grid;
}
</style> </style>

View File

@ -51,26 +51,19 @@
{#if $backendUiStore.selectedDatabase && $backendUiStore.selectedDatabase._id} {#if $backendUiStore.selectedDatabase && $backendUiStore.selectedDatabase._id}
<div class="hierarchy"> <div class="hierarchy">
<div class="components-list-container"> <div class="components-list-container">
<Switcher <h3>Tables</h3>
headings={HEADINGS} <Button primary wide on:click={setupForNewModel}>
bind:value={$backendUiStore.tabs.NAVIGATION_PANEL}> Create New Table
{#if selectedTab === 'NAVIGATE'} </Button>
<Button purple wide on:click={setupForNewModel}> <div class="hierarchy-items-container">
Create New Table {#each $backendUiStore.models as model}
</Button> <ListItem
<div class="hierarchy-items-container"> selected={!$backendUiStore.selectedField && model._id === $backendUiStore.selectedModel._id}
{#each $backendUiStore.models as model} title={model.name}
<ListItem icon="ri-table-fill"
selected={!$backendUiStore.selectedField && model._id === $backendUiStore.selectedModel._id} on:click={() => selectModel(model)} />
title={model.name} {/each}
icon="ri-table-fill" </div>
on:click={() => selectModel(model)} />
{/each}
</div>
{:else if selectedTab === 'ADD'}
<BlockNavigator />
{/if}
</Switcher>
</div> </div>
</div> </div>
{/if} {/if}