From b07f608ffef82b08a0570213c1494475f842e764 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 25 Jun 2020 18:32:51 +0100 Subject: [PATCH 1/9] merge --- packages/builder/src/builderStore/store/backend.js | 6 ++---- .../components/nav/ModelNavigator/EmptyModel.svelte | 10 +++------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index e5e5413111..130ca0c454 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -80,13 +80,11 @@ export const getBackendUiStore = () => { state.draftModel.schema = {} } - const id = uuid() - state.draftModel.schema = { ...state.draftModel.schema, - [id]: field, + [field.name]: field, } - state.selectedField = id + state.selectedField = field.name state.tabs.NAVIGATION_PANEL = "NAVIGATE" return state diff --git a/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte b/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte index 5feb5b3a57..cd7024af0a 100644 --- a/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte +++ b/packages/builder/src/components/nav/ModelNavigator/EmptyModel.svelte @@ -12,16 +12,12 @@ function createModel(model) { const { schema, ...rest } = $backendUiStore.selectedModel - const newModel = { ...model, schema: {} } - - // TODO: could be better - for (let key in model.schema) { - newModel.schema[uuid()] = model.schema[key] - } + // const newModel = { ...model, schema: {} } backendUiStore.actions.models.save({ model: { - ...newModel, + ...model, + schema: {}, ...rest, }, }) From 48f339215254c92e49a32c993955f55f8c6b8a5c Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 25 Jun 2020 20:04:58 +0100 Subject: [PATCH 2/9] record keys as names --- packages/builder/src/App.svelte | 10 +++++++ .../builder/src/builderStore/store/backend.js | 6 ++--- .../common/LinkedRecordSelector.svelte | 2 +- .../ModelDataTable/LinkedRecord.svelte | 2 +- .../nav/ModelNavigator/BlockNavigator.svelte | 2 +- .../nav/ModelNavigator/EmptyModel.svelte | 9 +++---- .../nav/ModelNavigator/ModelNavigator.svelte | 8 +++--- .../nav/ModelSetupNav/ModelFieldEditor.svelte | 27 +++++++++---------- packages/server/src/api/controllers/model.js | 4 +-- packages/server/src/api/controllers/record.js | 4 +-- 10 files changed, 40 insertions(+), 34 deletions(-) diff --git a/packages/builder/src/App.svelte b/packages/builder/src/App.svelte index d10c04727f..163a78ac73 100644 --- a/packages/builder/src/App.svelte +++ b/packages/builder/src/App.svelte @@ -5,6 +5,16 @@ import { routes } from "../routify/routes" import { store, initialise } from "builderStore" import NotificationDisplay from "components/common/Notification/NotificationDisplay.svelte" + import { notifier } from "builderStore/store/notifications" + + function showErrorBanner() { + notifier.danger("Whoops! Looks like we're having trouble. Please refresh the page.") + } + + onMount(async () => { + window.addEventListener("error", showErrorBanner) + window.addEventListener("unhandledrejection", showErrorBanner) + }) $basepath = "/_builder" diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 130ca0c454..ecb2b6550e 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -68,11 +68,11 @@ export const getBackendUiStore = () => { return state }), save: async ({ model }) => { - const updatedModel = cloneDeep(model) - const SAVE_MODEL_URL = `/api/models` - await api.post(SAVE_MODEL_URL, updatedModel) + const response = await api.post(SAVE_MODEL_URL, model) + const json = await response.json() await store.actions.models.fetch() + store.actions.models.select(json) }, addField: field => { store.update(state => { diff --git a/packages/builder/src/components/common/LinkedRecordSelector.svelte b/packages/builder/src/components/common/LinkedRecordSelector.svelte index bad03f436d..a494abc805 100644 --- a/packages/builder/src/components/common/LinkedRecordSelector.svelte +++ b/packages/builder/src/components/common/LinkedRecordSelector.svelte @@ -60,7 +60,7 @@ diff --git a/packages/server/src/api/routes/tests/model.spec.js b/packages/server/src/api/routes/tests/model.spec.js index 89aa9aa25b..49f6be41ad 100644 --- a/packages/server/src/api/routes/tests/model.spec.js +++ b/packages/server/src/api/routes/tests/model.spec.js @@ -26,7 +26,6 @@ describe("/models", () => { }) describe("create", () => { - beforeEach(async () => { instance = await createInstance(request, app._id); }); @@ -51,6 +50,50 @@ describe("/models", () => { }); }) + it("renames all the record fields for a model when a schema key is renamed", async () => { + const testModel = await createModel(request, app._id, instance._id); + + const testRecord = await request + .post(`/api/${testModel._id}/records`) + .send({ + name: "test" + }) + .set(defaultHeaders(app._id, instance._id)) + .expect('Content-Type', /json/) + .expect(200) + + const updatedModel = await request + .post(`/api/models`) + .send({ + _id: testModel._id, + _rev: testModel._rev, + name: "TestModel", + key: "name", + _rename: { + old: "name", + updated: "updatedName" + }, + schema: { + updatedName: { type: "string" } + } + }) + .set(defaultHeaders(app._id, instance._id)) + .expect('Content-Type', /json/) + .expect(200) + + expect(updatedModel.res.statusMessage).toEqual("Model TestModel saved successfully."); + expect(updatedModel.body.name).toEqual("TestModel"); + + const res = await request + .get(`/api/${testModel._id}/records/${testRecord.body._id}`) + .set(defaultHeaders(app._id, instance._id)) + .expect('Content-Type', /json/) + .expect(200) + + expect(res.body.updatedName).toEqual("test"); + expect(res.body.name).toBeUndefined(); + }); + it("should apply authorization to endpoint", async () => { await builderEndpointShouldBlockNormalUsers({ request, From fcdfddf6dae817ebd4f47e4a7d31295a93173052 Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Fri, 26 Jun 2020 10:31:03 +0100 Subject: [PATCH 8/9] Add _instanceName to login template --- .../appDirectoryTemplate/pages/unauthenticated/page.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json b/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json index 6ff1bfcd98..7aad3e6dca 100644 --- a/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json +++ b/packages/server/src/utilities/appDirectoryTemplate/pages/unauthenticated/page.json @@ -24,6 +24,7 @@ "passwordLabel": "Password", "loginButtonLabel": "Login", "buttonClass": "", + "_instanceName": "Login", "inputClass": "", "_children": [], "name": "{{ name }}", From b7670bcc6a9379629f467199c5c2f6a6e1665a65 Mon Sep 17 00:00:00 2001 From: Conor_Mack Date: Fri, 26 Jun 2020 11:53:08 +0100 Subject: [PATCH 9/9] Fixing Colorpicker Duplication Issues --- .../Colorpicker/Colorpicker.svelte | 33 ------------------- .../userInterface/Colorpicker/Input.svelte | 3 -- .../userInterface/Colorpicker/Slider.svelte | 13 -------- 3 files changed, 49 deletions(-) diff --git a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte index c50b119e53..2ae31385aa 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Colorpicker.svelte @@ -149,39 +149,6 @@ $: shrink = swatches.length > 0 -
- -
- -
- -
-
-
- -
- -
-
- setHue(hue.detail)} /> - - - setAlpha(alpha.detail)} /> - - -
-
- -
- - handleColorInput(event.target.value)} /> -
-
- -
-
- -
diff --git a/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte b/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte index 906f5f0d6a..a6abab6ca1 100644 --- a/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte +++ b/packages/builder/src/components/userInterface/Colorpicker/Slider.svelte @@ -29,19 +29,6 @@ $: style = `transform: translateX(${thumbPosition - 6}px);` -
handleClick(event.clientX)} - class="color-format-slider" - class:hue={type === 'hue'} - class:alpha={type === 'alpha'}> -
handleClick(e.detail)} - class="slider-thumb" - {style} /> -