From 0cc2069929461319a0795fcb73a02fef917de043 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 9 Nov 2021 17:40:31 +0100 Subject: [PATCH 01/10] fixes for templates, ensured iframetemplate fires ready event --- .../src/components/deploy/RevertModal.svelte | 18 ++++++++++++++++-- .../AppPreview/CurrentItemPreview.svelte | 1 + .../design/AppPreview/iframeTemplate.js | 9 ++++++++- .../src/components/start/CreateAppModal.svelte | 7 ++++++- packages/builder/src/stores/portal/auth.js | 9 ++++++--- .../server/src/api/controllers/application.js | 5 +++-- 6 files changed, 40 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/components/deploy/RevertModal.svelte b/packages/builder/src/components/deploy/RevertModal.svelte index 7f4decebee..bc2ad0d0aa 100644 --- a/packages/builder/src/components/deploy/RevertModal.svelte +++ b/packages/builder/src/components/deploy/RevertModal.svelte @@ -1,9 +1,16 @@ diff --git a/packages/builder/src/components/start/CreateAppModal.svelte b/packages/builder/src/components/start/CreateAppModal.svelte index 1db5e46261..68845e075b 100644 --- a/packages/builder/src/components/start/CreateAppModal.svelte +++ b/packages/builder/src/components/start/CreateAppModal.svelte @@ -157,6 +157,11 @@ } return title } + + async function onCancel() { + template = null + await auth.setInitInfo({}) + } {#if showTemplateSelection} @@ -186,7 +191,7 @@ title={getModalTitle()} confirmText={template?.fromFile ? "Import app" : "Create app"} onConfirm={createNewApp} - onCancel={inline ? () => (template = null) : null} + onCancel={inline ? onCancel : null} cancelText={inline ? "Back" : undefined} showCloseIcon={!inline} disabled={!valid} diff --git a/packages/builder/src/stores/portal/auth.js b/packages/builder/src/stores/portal/auth.js index bd08611fc9..9a12667a7e 100644 --- a/packages/builder/src/stores/portal/auth.js +++ b/packages/builder/src/stores/portal/auth.js @@ -80,6 +80,10 @@ export function createAuthStore() { } } + async function setInitInfo(info) { + await api.post(`/api/global/auth/init`, info) + } + return { subscribe: store.subscribe, setOrganisation: setOrganisation, @@ -87,9 +91,7 @@ export function createAuthStore() { const response = await api.get(`/api/global/auth/init`) return await response.json() }, - setInitInfo: async info => { - await api.post(`/api/global/auth/init`, info) - }, + setInitInfo, checkQueryString: async () => { const urlParams = new URLSearchParams(window.location.search) if (urlParams.has("tenantId")) { @@ -129,6 +131,7 @@ export function createAuthStore() { throw "Unable to create logout" } await response.json() + await setInitInfo({}) setUser(null) }, updateSelf: async fields => { diff --git a/packages/server/src/api/controllers/application.js b/packages/server/src/api/controllers/application.js index f27efff29e..4ea308a790 100644 --- a/packages/server/src/api/controllers/application.js +++ b/packages/server/src/api/controllers/application.js @@ -323,7 +323,7 @@ exports.delete = async ctx => { ctx.body = result } -exports.sync = async ctx => { +exports.sync = async (ctx, next) => { const appId = ctx.params.appId if (!isDevAppID(appId)) { ctx.throw(400, "This action cannot be performed for production apps") @@ -336,10 +336,11 @@ exports.sync = async ctx => { if (info.error) throw info.error } catch (err) { // the database doesn't exist. Don't replicate + ctx.status = 200 ctx.body = { message: "App sync not required, app not deployed.", } - return + return next() } const replication = new Replication({ From 4367c9adf679ad5a65107b21a98da75c11486c6d Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 9 Nov 2021 18:00:32 +0100 Subject: [PATCH 02/10] prevent redirect to acct portal when not necessary --- .../builder/src/pages/builder/_layout.svelte | 6 ++++- packages/builder/src/stores/portal/auth.js | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index 179131107f..6227f7938c 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -30,7 +30,11 @@ if (user && user.tenantId) { // no tenant in the url - send to account portal to fix this if (!urlTenantId) { - window.location.href = $admin.accountPortalUrl + let redirectUrl = $admin.accountPortalUrl + if (!window.location.host.includes("localhost")) { + const redirectUrl = redirectUrl.replace("://", `://${user.tenantId}.`) + } + window.location.href = redirectUrl return } diff --git a/packages/builder/src/stores/portal/auth.js b/packages/builder/src/stores/portal/auth.js index 9a12667a7e..df4e3f8462 100644 --- a/packages/builder/src/stores/portal/auth.js +++ b/packages/builder/src/stores/portal/auth.js @@ -81,16 +81,29 @@ export function createAuthStore() { } async function setInitInfo(info) { - await api.post(`/api/global/auth/init`, info) + const response = await api.post(`/api/global/auth/init`, info) + const json = await response.json() + auth.update(store => { + store.initInfo = json + return store + }) + return json + } + + async function getInitInfo() { + const response = await api.get(`/api/global/auth/init`) + const json = response.json() + auth.update(store => { + store.initInfo = json + return store + }) + return json } return { subscribe: store.subscribe, setOrganisation: setOrganisation, - getInitInfo: async () => { - const response = await api.get(`/api/global/auth/init`) - return await response.json() - }, + getInitInfo, setInitInfo, checkQueryString: async () => { const urlParams = new URLSearchParams(window.location.search) From 7a2491b62ce518572f7cc74c5c133fc73be20be5 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 9 Nov 2021 18:14:37 +0100 Subject: [PATCH 03/10] review --- packages/builder/src/pages/builder/_layout.svelte | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index 6227f7938c..6e879228e0 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -30,11 +30,11 @@ if (user && user.tenantId) { // no tenant in the url - send to account portal to fix this if (!urlTenantId) { - let redirectUrl = $admin.accountPortalUrl if (!window.location.host.includes("localhost")) { - const redirectUrl = redirectUrl.replace("://", `://${user.tenantId}.`) + let redirectUrl = window.location.href + redirectUrl = redirectUrl.replace("://", `://${user.tenantId}.`) + window.location.href = redirectUrl } - window.location.href = redirectUrl return } From 878fe986b6a38dbfee1e48235cb1b3ebf44a8719 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 9 Nov 2021 18:16:52 +0100 Subject: [PATCH 04/10] update redundant comment --- packages/builder/src/pages/builder/_layout.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/_layout.svelte b/packages/builder/src/pages/builder/_layout.svelte index 6e879228e0..bf55be5534 100644 --- a/packages/builder/src/pages/builder/_layout.svelte +++ b/packages/builder/src/pages/builder/_layout.svelte @@ -28,8 +28,8 @@ } if (user && user.tenantId) { - // no tenant in the url - send to account portal to fix this if (!urlTenantId) { + // redirect to correct tenantId subdomain if (!window.location.host.includes("localhost")) { let redirectUrl = window.location.href redirectUrl = redirectUrl.replace("://", `://${user.tenantId}.`) From 8683a74b2d90d7c9fb43d7d16a05701a56e7a302 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Tue, 9 Nov 2021 18:30:51 +0100 Subject: [PATCH 05/10] adding check for delete app --- packages/builder/src/components/common/ConfirmDialog.svelte | 2 ++ packages/builder/src/pages/builder/portal/apps/index.svelte | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/packages/builder/src/components/common/ConfirmDialog.svelte b/packages/builder/src/components/common/ConfirmDialog.svelte index cf2bf989b9..ece20fe102 100644 --- a/packages/builder/src/components/common/ConfirmDialog.svelte +++ b/packages/builder/src/components/common/ConfirmDialog.svelte @@ -8,6 +8,7 @@ export let onOk = undefined export let onCancel = undefined export let warning = true + export let disabled let modal @@ -26,6 +27,7 @@ confirmText={okText} {cancelText} {warning} + {disabled} > {body} diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index 2c8cbb1097..d465f7b978 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -6,6 +6,7 @@ ActionButton, ActionGroup, ButtonGroup, + Input, Select, Modal, Page, @@ -36,6 +37,7 @@ let loaded = false let searchTerm = "" let cloud = $admin.cloud + let appName = "" $: enrichedApps = enrichApps($apps, $auth.user, sortBy) $: filteredApps = enrichedApps.filter(app => @@ -296,8 +298,12 @@ title="Confirm deletion" okText="Delete app" onOk={confirmDeleteApp} + disabled={appName !== selectedApp?.name} > Are you sure you want to delete the app {selectedApp?.name}? + +

Please enter the app name below to confirm.

+ Date: Tue, 9 Nov 2021 18:35:19 +0100 Subject: [PATCH 06/10] updating delete app cypress command --- packages/builder/cypress/support/commands.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 82e3c45a1f..ff1d13d6cb 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -43,7 +43,7 @@ Cypress.Commands.add("createApp", name => { }) }) -Cypress.Commands.add("deleteApp", () => { +Cypress.Commands.add("deleteApp", appName => { cy.visit(`localhost:${Cypress.env("PORT")}/builder`) cy.wait(1000) cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`) @@ -52,6 +52,7 @@ Cypress.Commands.add("deleteApp", () => { console.log(val) if (val.length > 0) { cy.get(".title > :nth-child(3) > .spectrum-Icon").click() + cy.get("input").type(appName) cy.contains("Delete").click() cy.get(".spectrum-Button--warning").click() } @@ -60,7 +61,7 @@ Cypress.Commands.add("deleteApp", () => { Cypress.Commands.add("createTestApp", () => { const appName = "Cypress Tests" - cy.deleteApp() + cy.deleteApp(appName) cy.createApp(appName, "This app is used for Cypress testing.") }) From 7cf916a00d73b9a3a5bb32f2e876f2ccb6a5e952 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 10 Nov 2021 12:12:33 +0100 Subject: [PATCH 07/10] code review, simplify iframeTemplate --- .../design/AppPreview/CurrentItemPreview.svelte | 16 +++++++--------- .../design/AppPreview/iframeTemplate.js | 8 +------- packages/builder/src/stores/portal/auth.js | 9 ++++----- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte index a97cf22442..4001db44b6 100644 --- a/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte +++ b/packages/builder/src/components/design/AppPreview/CurrentItemPreview.svelte @@ -95,12 +95,12 @@ const handlers = { [MessageTypes.READY]: () => { // Initialise the app when mounted - // Display preview immediately if the intelligent loading feature - // is not supported if ($store.clientFeatures.messagePassing) { if (!loading) return } + // Display preview immediately if the intelligent loading feature + // is not supported if (!$store.clientFeatures.intelligentLoading) { loading = false } @@ -119,9 +119,8 @@ } onMount(() => { - if ($store.clientFeatures.messagePassing) { - window.addEventListener("message", receiveMessage) - } else { + window.addEventListener("message", receiveMessage) + if (!$store.clientFeatures.messagePassing) { // Legacy - remove in later versions of BB iframe.contentWindow.addEventListener("ready", () => { receiveMessage({ data: { type: MessageTypes.READY }}) @@ -132,15 +131,14 @@ // Add listener for events sent by client library in preview iframe.contentWindow.addEventListener("bb-event", handleBudibaseEvent) iframe.contentWindow.addEventListener("keydown", handleKeydownEvent) - } + } }) // Remove all iframe event listeners on component destroy onDestroy(() => { if (iframe.contentWindow) { - if ($store.clientFeatures.messagePassing) { - window.removeEventListener("message", receiveMessage) - } else { + window.removeEventListener("message", receiveMessage) + if (!$store.clientFeatures.messagePassing) { // Legacy - remove in later versions of BB iframe.contentWindow.removeEventListener("bb-event", handleBudibaseEvent) iframe.contentWindow.removeEventListener("keydown", handleKeydownEvent) diff --git a/packages/builder/src/components/design/AppPreview/iframeTemplate.js b/packages/builder/src/components/design/AppPreview/iframeTemplate.js index 8bc14f42b9..372eac24f7 100644 --- a/packages/builder/src/components/design/AppPreview/iframeTemplate.js +++ b/packages/builder/src/components/design/AppPreview/iframeTemplate.js @@ -65,7 +65,6 @@ export default ` theme, customTheme, previewDevice, - messagePassing } = parsed // Set some flags so the app knows we're in the builder @@ -90,11 +89,7 @@ export default ` throw "The client library couldn't be loaded" } } catch (error) { - if (messagePassing) { - window.parent.postMessage({ type: "error", error }) - } else { - window.dispatchEvent(new CustomEvent("error", { detail: error })) - } + window.parent.postMessage({ type: "error", error }) } } @@ -104,7 +99,6 @@ export default ` }) window.parent.postMessage({ type: "ready" }) - window.dispatchEvent(new Event("ready")) diff --git a/packages/builder/src/stores/portal/auth.js b/packages/builder/src/stores/portal/auth.js index df4e3f8462..2f558c88b2 100644 --- a/packages/builder/src/stores/portal/auth.js +++ b/packages/builder/src/stores/portal/auth.js @@ -81,13 +81,12 @@ export function createAuthStore() { } async function setInitInfo(info) { - const response = await api.post(`/api/global/auth/init`, info) - const json = await response.json() + await api.post(`/api/global/auth/init`, info) auth.update(store => { - store.initInfo = json + store.initInfo = info return store }) - return json + return info } async function getInitInfo() { @@ -102,7 +101,7 @@ export function createAuthStore() { return { subscribe: store.subscribe, - setOrganisation: setOrganisation, + setOrganisation, getInitInfo, setInitInfo, checkQueryString: async () => { From f5406cecf2a68b06ef715f15a1b6335b2e79351e Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 10 Nov 2021 13:04:59 +0100 Subject: [PATCH 08/10] fix cypress tests --- packages/builder/cypress/support/commands.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index ff1d13d6cb..5682dcb2e2 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -43,16 +43,14 @@ Cypress.Commands.add("createApp", name => { }) }) -Cypress.Commands.add("deleteApp", appName => { +Cypress.Commands.add("deleteApp", () => { cy.visit(`localhost:${Cypress.env("PORT")}/builder`) cy.wait(1000) cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`) .its("body") .then(val => { - console.log(val) if (val.length > 0) { cy.get(".title > :nth-child(3) > .spectrum-Icon").click() - cy.get("input").type(appName) cy.contains("Delete").click() cy.get(".spectrum-Button--warning").click() } From 8f7b57837e74a301bc097759c95163457ccd3e94 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 10 Nov 2021 14:08:34 +0100 Subject: [PATCH 09/10] adding cypress tag to input --- packages/builder/cypress/support/commands.js | 4 ++-- packages/builder/src/pages/builder/portal/apps/index.svelte | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index 5682dcb2e2..af60272d49 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -43,7 +43,7 @@ Cypress.Commands.add("createApp", name => { }) }) -Cypress.Commands.add("deleteApp", () => { +Cypress.Commands.add("deleteApp", appName => { cy.visit(`localhost:${Cypress.env("PORT")}/builder`) cy.wait(1000) cy.request(`localhost:${Cypress.env("PORT")}/api/applications?status=all`) @@ -51,7 +51,7 @@ Cypress.Commands.add("deleteApp", () => { .then(val => { if (val.length > 0) { cy.get(".title > :nth-child(3) > .spectrum-Icon").click() - cy.contains("Delete").click() + cy.get(`[data-cy="delete-app-confirmation"]`).type(appName) cy.get(".spectrum-Button--warning").click() } }) diff --git a/packages/builder/src/pages/builder/portal/apps/index.svelte b/packages/builder/src/pages/builder/portal/apps/index.svelte index d465f7b978..53ad661f72 100644 --- a/packages/builder/src/pages/builder/portal/apps/index.svelte +++ b/packages/builder/src/pages/builder/portal/apps/index.svelte @@ -303,7 +303,7 @@ Are you sure you want to delete the app {selectedApp?.name}?

Please enter the app name below to confirm.

- +
Date: Wed, 10 Nov 2021 14:57:46 +0100 Subject: [PATCH 10/10] fix renaming an app --- .../cypress/integration/renameAnApplication.spec.js | 3 ++- packages/builder/cypress/support/commands.js | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/builder/cypress/integration/renameAnApplication.spec.js b/packages/builder/cypress/integration/renameAnApplication.spec.js index b9da64989b..95a152c017 100644 --- a/packages/builder/cypress/integration/renameAnApplication.spec.js +++ b/packages/builder/cypress/integration/renameAnApplication.spec.js @@ -11,7 +11,8 @@ it("should rename an unpublished application", () => { renameApp(appRename) cy.searchForApplication(appRename) cy.get(".appGrid").find(".wrapper").should("have.length", 1) - }) + cy.deleteApp(appRename) +}) xit("Should rename a published application", () => { // It is not possible to rename a published application diff --git a/packages/builder/cypress/support/commands.js b/packages/builder/cypress/support/commands.js index af60272d49..ca758e46d0 100644 --- a/packages/builder/cypress/support/commands.js +++ b/packages/builder/cypress/support/commands.js @@ -51,8 +51,11 @@ Cypress.Commands.add("deleteApp", appName => { .then(val => { if (val.length > 0) { cy.get(".title > :nth-child(3) > .spectrum-Icon").click() - cy.get(`[data-cy="delete-app-confirmation"]`).type(appName) - cy.get(".spectrum-Button--warning").click() + cy.contains("Delete").click() + cy.get(".spectrum-Modal").within(() => { + cy.get("input").type(appName) + cy.get(".spectrum-Button--warning").click() + }) } }) })