diff --git a/packages/builder/package.json b/packages/builder/package.json
index f560d8b5c3..26af308a29 100644
--- a/packages/builder/package.json
+++ b/packages/builder/package.json
@@ -57,7 +57,7 @@
]
},
"dependencies": {
- "@budibase/bbui": "^1.22.3",
+ "@budibase/bbui": "^1.23.0",
"@budibase/client": "^0.1.1",
"@budibase/colorpicker": "^1.0.1",
"@nx-js/compiler-util": "^2.0.0",
diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js
index b0d5fcee29..5708c98a98 100644
--- a/packages/builder/src/builderStore/store/backend.js
+++ b/packages/builder/src/builderStore/store/backend.js
@@ -83,21 +83,31 @@ export const getBackendUiStore = () => {
await store.actions.models.fetch()
store.actions.models.select(savedModel)
},
- addField: field => {
+ saveField: ({ originalName, field }) => {
store.update(state => {
- if (!state.draftModel.schema) {
- state.draftModel.schema = {}
- }
+ // TODO: is this necessary?
+ // if (!state.draftModel.schema) {
+ // state.draftModel.schema = {}
+ // }
+
+ // delete the original if renaming
+ delete state.draftModel.schema[originalName]
state.draftModel.schema = {
...state.draftModel.schema,
[field.name]: cloneDeep(field),
}
- state.selectedField = field.name
-
+ store.actions.models.save({ model: state.draftModel })
return state
})
},
+ deleteField: field => {
+ store.update(state => {
+ delete state.draftModel.schema[field.name]
+ store.actions.models.save({ model: state.draftModel })
+ return state
+ })
+ }
},
views: {
select: view =>
diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditTable.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditTable.svelte
index 5c1137cdd9..987ee45cd7 100644
--- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditTable.svelte
+++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditTable.svelte
@@ -20,6 +20,8 @@
export let field = {}
export let columnName
+ let originalName = columnName
+
$: required =
field.constraints &&
field.constraints.presence &&
@@ -33,13 +35,18 @@
}
async function saveColumn() {
- backendUiStore.actions.models.addField({
- name: columnName,
- field,
- })
+ // if existing
+ // update the name and type
+ backendUiStore.update(state => {
+ backendUiStore.actions.models.saveField({
+ originalName,
+ field: {
+ ...field,
+ name: columnName
+ }
+ })
- backendUiStore.actions.models.save({
- model: $backendUiStore.draftModel,
+ return state
})
onClosed()
}
diff --git a/packages/builder/src/components/database/ModelDataTable/popovers/Column.svelte b/packages/builder/src/components/database/ModelDataTable/popovers/Column.svelte
index 44bc751f5e..44f733ca06 100644
--- a/packages/builder/src/components/database/ModelDataTable/popovers/Column.svelte
+++ b/packages/builder/src/components/database/ModelDataTable/popovers/Column.svelte
@@ -18,8 +18,10 @@
Create Column