diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 71fa50acaa..83c241f818 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -1,5 +1,6 @@ import { writable } from "svelte/store" import { cloneDeep } from "lodash/fp" +import { uuid } from "builderStore/uuid" import api from "../api" export const getBackendUiStore = () => { @@ -61,14 +62,15 @@ export const getBackendUiStore = () => { save: async ({ model }) => { const updatedModel = cloneDeep(model) - // TODO: refactor - for (let key in updatedModel.schema) { - const field = updatedModel.schema[key] - if (field.name && field.name !== key) { - updatedModel.schema[field.name] = field - delete updatedModel.schema[key] - } - } + // // TODO: refactor + // for (let key in updatedModel.schema) { + // const field = updatedModel.schema[key] + // // TODO: use IDs + // if (field.name && field.name !== key) { + // updatedModel.schema[field.name] = field + // delete updatedModel.schema[key] + // } + // } const SAVE_MODEL_URL = `/api/models` const response = await api.post(SAVE_MODEL_URL, updatedModel) @@ -86,8 +88,6 @@ export const getBackendUiStore = () => { state.models = state.models } - // TODO: fetch models - store.actions.models.select(savedModel) return state }) @@ -98,13 +98,13 @@ export const getBackendUiStore = () => { state.draftModel.schema = {} } + const id = uuid() + state.draftModel.schema = { ...state.draftModel.schema, - [field.name]: field, + [id]: field, } - - state.selectedField = field.name - + state.selectedField = id state.tabs.NAVIGATION_PANEL = "NAVIGATE" return state diff --git a/packages/builder/src/components/common/LinkedRecordSelector.svelte b/packages/builder/src/components/common/LinkedRecordSelector.svelte index 4323ba6164..24c8d8f5d8 100644 --- a/packages/builder/src/components/common/LinkedRecordSelector.svelte +++ b/packages/builder/src/components/common/LinkedRecordSelector.svelte @@ -18,6 +18,7 @@ "_id", "_rev", $backendUiStore.selectedModel.name, + modelId ] async function fetchRecords() { @@ -26,10 +27,6 @@ records = await response.json() } - onMount(() => { - fetchRecords() - }) - function linkRecord(id) { if (linkedRecords.has(id)) { linkedRecords.delete(id) @@ -39,6 +36,10 @@ linkedRecords = linkedRecords } + + onMount(() => { + fetchRecords() + })
diff --git a/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte b/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte index 9402c26003..96e611ad27 100644 --- a/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte +++ b/packages/builder/src/components/database/ModelDataTable/LinkedRecord.svelte @@ -15,6 +15,7 @@ "type", "_id", "_rev", + $backendUiStore.selectedModel._id, $backendUiStore.selectedModel.name, ] diff --git a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte index 8424c12048..27c9694cc1 100644 --- a/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte +++ b/packages/builder/src/components/database/ModelDataTable/ModelDataTable.svelte @@ -48,9 +48,6 @@ if ($backendUiStore.selectedView) { api.fetchDataForView($backendUiStore.selectedView).then(records => { data = records || [] - headers = Object.keys($backendUiStore.selectedModel.schema).filter( - key => !INTERNAL_HEADERS.includes(key) - ) }) } } @@ -62,6 +59,12 @@ ) : [] + $: headers = Object.keys($backendUiStore.selectedModel.schema).filter( + id => !INTERNAL_HEADERS.includes(id) + ) + + $: schema = $backendUiStore.selectedModel.schema + const createNewRecord = () => { open( CreateEditRecordModal, @@ -94,7 +97,7 @@ Edit {#each headers as header} - {header} + {$backendUiStore.selectedModel.schema[header].name} {/each} @@ -129,9 +132,11 @@ {#each headers as header} - {#if Array.isArray(row[header])} - - {:else}{row[header] || 0}{/if} + {#if schema[header].type === "link"} + + {:else} + {row[header]} + {/if} {/each} diff --git a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte index 60f0cd9fa3..c988e5d762 100644 --- a/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte +++ b/packages/builder/src/components/database/ModelDataTable/modals/CreateEditRecord.svelte @@ -79,13 +79,13 @@ {#if meta.type === 'link'} {:else} {/if} @@ -101,7 +101,7 @@ header { margin-bottom: 40px; display: grid; - grid-gap: 5px; + grid-gap: 20px; grid-template-columns: 40px 1fr; align-items: center; } @@ -115,7 +115,6 @@ background: var(--secondary); color: var(--ink); font-size: 20px; - margin-right: 20px; border-radius: 3px; } diff --git a/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte b/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte index db424f8ef7..5feb5b3a57 100644 --- a/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte +++ b/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte @@ -1,5 +1,6 @@
@@ -66,10 +78,12 @@ {:else if field.type === 'link'}
- + {#if model._id !== $backendUiStore.draftModel._id} + + {/if} {/each}
diff --git a/packages/builder/src/components/nav/ModelSetupNav/ModelSetupNav.svelte b/packages/builder/src/components/nav/ModelSetupNav/ModelSetupNav.svelte index 6097210d51..24a3079484 100644 --- a/packages/builder/src/components/nav/ModelSetupNav/ModelSetupNav.svelte +++ b/packages/builder/src/components/nav/ModelSetupNav/ModelSetupNav.svelte @@ -43,6 +43,8 @@ const response = await api.delete(DELETE_MODEL_URL) backendUiStore.update(state => { state.selectedView = null + state.selectedModel = {} + state.draftModel = {} state.models = state.models.filter(({ _id }) => _id !== model._id) notifier.danger(`${model.name} deleted successfully.`) return state @@ -64,7 +66,7 @@ {#if selectedTab === 'SETUP'} {#if $backendUiStore.selectedField} - {:else} + {:else if $backendUiStore.draftModel.schema}
Name
clientId lookup - const masterDb = new CouchDB("clientAppLookup") + const masterDb = new CouchDB("client_app_lookup") await masterDb.put({ _id: appId, @@ -132,7 +132,7 @@ const createEmptyAppPackage = async (ctx, app) => { } const lookupClientId = async appId => { - const masterDb = new CouchDB("clientAppLookup") + const masterDb = new CouchDB("client_app_lookup") const { clientId } = await masterDb.get(appId) return clientId } diff --git a/packages/server/src/api/controllers/auth.js b/packages/server/src/api/controllers/auth.js index e9570e270f..4f0ddbf0d8 100644 --- a/packages/server/src/api/controllers/auth.js +++ b/packages/server/src/api/controllers/auth.js @@ -11,7 +11,7 @@ exports.authenticate = async ctx => { if (!username) ctx.throw(400, "Username Required.") if (!password) ctx.throw(400, "Password Required") - const masterDb = new CouchDB("clientAppLookup") + const masterDb = new CouchDB("client_app_lookup") const { clientId } = await masterDb.get(ctx.user.appId) diff --git a/packages/server/src/api/controllers/component.js b/packages/server/src/api/controllers/component.js index a3b4d9c2bb..3d631bcaec 100644 --- a/packages/server/src/api/controllers/component.js +++ b/packages/server/src/api/controllers/component.js @@ -7,7 +7,7 @@ const { } = require("../../utilities/budibaseDir") exports.fetchAppComponentDefinitions = async function(ctx) { - const masterDb = new CouchDB("clientAppLookup") + const masterDb = new CouchDB("client_app_lookup") const { clientId } = await masterDb.get(ctx.params.appId) const db = new CouchDB(ClientDb.name(clientId)) const app = await db.get(ctx.params.appId) diff --git a/packages/server/src/api/controllers/instance.js b/packages/server/src/api/controllers/instance.js index 903d3ff651..4bc22bd650 100644 --- a/packages/server/src/api/controllers/instance.js +++ b/packages/server/src/api/controllers/instance.js @@ -8,7 +8,7 @@ exports.create = async function(ctx) { const appShortId = appId.substring(0, 7) const instanceId = `inst_${appShortId}_${newid()}` - const masterDb = new CouchDB("clientAppLookup") + const masterDb = new CouchDB("client_app_lookup") const { clientId } = await masterDb.get(appId) const db = new CouchDB(instanceId) diff --git a/packages/server/src/api/controllers/model.js b/packages/server/src/api/controllers/model.js index 1bb507f08f..65bc367a08 100644 --- a/packages/server/src/api/controllers/model.js +++ b/packages/server/src/api/controllers/model.js @@ -16,7 +16,7 @@ exports.find = async function(ctx) { ctx.body = model } -exports.create = async function(ctx) { +exports.save = async function(ctx) { const db = new CouchDB(ctx.user.instanceId) const modelToSave = { type: "model", @@ -33,7 +33,7 @@ exports.create = async function(ctx) { if (schema[key].type === "link") { // create the link field in the other model const linkedModel = await db.get(schema[key].modelId) - linkedModel.schema[modelToSave.name] = { + linkedModel.schema[modelToSave._id] = { name: modelToSave.name, type: "link", modelId: modelToSave._id, diff --git a/packages/server/src/api/controllers/record.js b/packages/server/src/api/controllers/record.js index 273175c2b1..d4e70b3ed4 100644 --- a/packages/server/src/api/controllers/record.js +++ b/packages/server/src/api/controllers/record.js @@ -56,8 +56,8 @@ exports.save = async function(ctx) { const doc = row.doc return { ...doc, - [model.name]: doc[model.name] - ? [...doc[model.name], record._id] + [model._id]: doc[model._id] + ? [...doc[model._id], record._id] : [record._id], } }) diff --git a/packages/server/src/api/controllers/user.js b/packages/server/src/api/controllers/user.js index 71816f1c78..7805ad251d 100644 --- a/packages/server/src/api/controllers/user.js +++ b/packages/server/src/api/controllers/user.js @@ -41,7 +41,7 @@ exports.create = async function(ctx) { const response = await database.post(user) - const masterDb = new CouchDB("clientAppLookup") + const masterDb = new CouchDB("client_app_lookup") const { clientId } = await masterDb.get(appId) // the clientDB needs to store a map of users against the app diff --git a/packages/server/src/api/routes/model.js b/packages/server/src/api/routes/model.js index 10882aa057..00eb46d515 100644 --- a/packages/server/src/api/routes/model.js +++ b/packages/server/src/api/routes/model.js @@ -12,8 +12,7 @@ router authorized(READ_MODEL, ctx => ctx.params.id), modelController.find ) - .post("/api/models", authorized(BUILDER), modelController.create) - // .patch("/api/:instanceId/models", controller.update) + .post("/api/models", authorized(BUILDER), modelController.save) .delete( "/api/models/:modelId/:revId", authorized(BUILDER),