column CRUD
This commit is contained in:
parent
63f3623664
commit
9d1979114b
|
@ -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",
|
||||||
|
|
|
@ -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 =>
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -51,11 +51,8 @@
|
||||||
{#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}>
|
|
||||||
{#if selectedTab === 'NAVIGATE'}
|
|
||||||
<Button purple wide on:click={setupForNewModel}>
|
|
||||||
Create New Table
|
Create New Table
|
||||||
</Button>
|
</Button>
|
||||||
<div class="hierarchy-items-container">
|
<div class="hierarchy-items-container">
|
||||||
|
@ -67,10 +64,6 @@
|
||||||
on:click={() => selectModel(model)} />
|
on:click={() => selectModel(model)} />
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
{:else if selectedTab === 'ADD'}
|
|
||||||
<BlockNavigator />
|
|
||||||
{/if}
|
|
||||||
</Switcher>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Reference in New Issue