From b7ec577efd3ec7f97164ebf1f5ca520075d5ed5d Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 12 Dec 2023 16:57:41 +0100 Subject: [PATCH 01/28] Add redirect --- packages/builder/src/api.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/builder/src/api.js b/packages/builder/src/api.js index 37894d9bbc..e93dae65f8 100644 --- a/packages/builder/src/api.js +++ b/packages/builder/src/api.js @@ -45,4 +45,9 @@ export const API = createAPIClient({ } } }, + onMigrationDetected: appId => { + window.location = `/builder/updating/${appId}?returnUrl=${encodeURI( + window.location + )}` + }, }) From 9067d38dce059718577f7fee214f7a31495e14c4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 12 Dec 2023 18:38:29 +0100 Subject: [PATCH 02/28] Create updating page --- packages/builder/src/api.js | 10 +++++++--- .../src/pages/builder/updating/[appId].svelte | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 packages/builder/src/pages/builder/updating/[appId].svelte diff --git a/packages/builder/src/api.js b/packages/builder/src/api.js index e93dae65f8..2fa48273f0 100644 --- a/packages/builder/src/api.js +++ b/packages/builder/src/api.js @@ -46,8 +46,12 @@ export const API = createAPIClient({ } }, onMigrationDetected: appId => { - window.location = `/builder/updating/${appId}?returnUrl=${encodeURI( - window.location - )}` + const updatingUrl = `/builder/updating/${appId}` + + if (window.location.pathname === updatingUrl) { + return + } + + window.location = `${updatingUrl}?returnUrl=${encodeURI(window.location)}` }, }) diff --git a/packages/builder/src/pages/builder/updating/[appId].svelte b/packages/builder/src/pages/builder/updating/[appId].svelte new file mode 100644 index 0000000000..69a2d58eed --- /dev/null +++ b/packages/builder/src/pages/builder/updating/[appId].svelte @@ -0,0 +1,14 @@ + + +
+ +
+ + From a2cb32225d35a02179ba41d2ab191485b88a0678 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 12 Dec 2023 18:38:44 +0100 Subject: [PATCH 03/28] Checks --- .../src/pages/builder/updating/[appId].svelte | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/builder/src/pages/builder/updating/[appId].svelte b/packages/builder/src/pages/builder/updating/[appId].svelte index 69a2d58eed..25092dd1a0 100644 --- a/packages/builder/src/pages/builder/updating/[appId].svelte +++ b/packages/builder/src/pages/builder/updating/[appId].svelte @@ -1,5 +1,22 @@
From 0b8d7904dfba652c68751f709643b80f399866a1 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 13 Dec 2023 12:44:32 +0100 Subject: [PATCH 04/28] Encode url properly --- packages/builder/src/api.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/api.js b/packages/builder/src/api.js index 2fa48273f0..4817ac2716 100644 --- a/packages/builder/src/api.js +++ b/packages/builder/src/api.js @@ -52,6 +52,8 @@ export const API = createAPIClient({ return } - window.location = `${updatingUrl}?returnUrl=${encodeURI(window.location)}` + window.location = `${updatingUrl}?returnUrl=${encodeURIComponent( + window.location + )}` }, }) From 342a1b487bc17d4aea7ddfd6d0d53037d523960c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 13 Dec 2023 16:15:11 +0100 Subject: [PATCH 05/28] Update url --- packages/builder/src/api.js | 2 +- .../[appId].svelte => app/[application]/updating.svelte} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/builder/src/pages/builder/{updating/[appId].svelte => app/[application]/updating.svelte} (100%) diff --git a/packages/builder/src/api.js b/packages/builder/src/api.js index 4817ac2716..a854137e2b 100644 --- a/packages/builder/src/api.js +++ b/packages/builder/src/api.js @@ -46,7 +46,7 @@ export const API = createAPIClient({ } }, onMigrationDetected: appId => { - const updatingUrl = `/builder/updating/${appId}` + const updatingUrl = `/builder/app/${appId}/updating` if (window.location.pathname === updatingUrl) { return diff --git a/packages/builder/src/pages/builder/updating/[appId].svelte b/packages/builder/src/pages/builder/app/[application]/updating.svelte similarity index 100% rename from packages/builder/src/pages/builder/updating/[appId].svelte rename to packages/builder/src/pages/builder/app/[application]/updating.svelte From 3a2a2a242cb906cf714864b95fdf0101bd808f15 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 14 Dec 2023 12:52:51 +0100 Subject: [PATCH 06/28] Change interval for timeout --- .../builder/app/[application]/updating.svelte | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/packages/builder/src/pages/builder/app/[application]/updating.svelte b/packages/builder/src/pages/builder/app/[application]/updating.svelte index 25092dd1a0..22d6371c18 100644 --- a/packages/builder/src/pages/builder/app/[application]/updating.svelte +++ b/packages/builder/src/pages/builder/app/[application]/updating.svelte @@ -2,19 +2,27 @@ import Spinner from "components/common/Spinner.svelte" import { API } from "api" - setInterval(async () => { - const response = await API.get({ url: "/api/migrations/status" }) - if (!response.migrated) { - return - } + let timeout + async function checkMigrationsFinished() { + timeout = setTimeout(async () => { + const response = await API.get({ url: "/api/migrations/status" }) + if (!response.migrated) { + checkMigrationsFinished() + return + } - const urlParams = new URLSearchParams(window.location.search) - const returnUrl = urlParams.get("returnUrl") + const urlParams = new URLSearchParams(window.location.search) + const returnUrl = urlParams.get("returnUrl") - window.location = returnUrl - }, 1000) + window.location = returnUrl + }, 1000) + } + + checkMigrationsFinished() setTimeout(() => { + clearTimeout(timeout) + // TODO alert("Something went wrong 💀") }, 60000) From 5f6210e9a06ae5c9b3e94f487314a22228bef841 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 14 Dec 2023 16:01:49 +0100 Subject: [PATCH 07/28] Use routify --- .../src/pages/builder/app/[application]/updating.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/pages/builder/app/[application]/updating.svelte b/packages/builder/src/pages/builder/app/[application]/updating.svelte index 22d6371c18..a89a3a7165 100644 --- a/packages/builder/src/pages/builder/app/[application]/updating.svelte +++ b/packages/builder/src/pages/builder/app/[application]/updating.svelte @@ -1,5 +1,7 @@
diff --git a/packages/frontend-core/src/api/index.js b/packages/frontend-core/src/api/index.js index d4b4f3636e..066ab16f6e 100644 --- a/packages/frontend-core/src/api/index.js +++ b/packages/frontend-core/src/api/index.js @@ -33,6 +33,7 @@ import { buildEnvironmentVariableEndpoints } from "./environmentVariables" import { buildEventEndpoints } from "./events" import { buildAuditLogsEndpoints } from "./auditLogs" import { buildLogsEndpoints } from "./logs" +import { buildMigrationEndpoints } from "./migrations" /** * Random identifier to uniquely identify a session in a tab. This is @@ -298,6 +299,7 @@ export const createAPIClient = config => { ...buildEventEndpoints(API), ...buildAuditLogsEndpoints(API), ...buildLogsEndpoints(API), + ...buildMigrationEndpoints(API), viewV2: buildViewV2Endpoints(API), } } diff --git a/packages/frontend-core/src/api/migrations.js b/packages/frontend-core/src/api/migrations.js new file mode 100644 index 0000000000..2da70d6fcb --- /dev/null +++ b/packages/frontend-core/src/api/migrations.js @@ -0,0 +1,10 @@ +export const buildMigrationEndpoints = API => ({ + /** + * Gets the info about the current app migration + */ + getMigrationStatus: async () => { + return await API.get({ + url: "/api/migrations/status", + }) + }, +}) From c80504ca93d9afd54bc91a78d2bb2575aceb7711 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 18 Dec 2023 10:59:33 +0100 Subject: [PATCH 13/28] Use ?params --- packages/builder/src/api.js | 2 +- .../src/pages/builder/app/[application]/updating.svelte | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/builder/src/api.js b/packages/builder/src/api.js index 9130c60dea..febf6603bb 100644 --- a/packages/builder/src/api.js +++ b/packages/builder/src/api.js @@ -53,7 +53,7 @@ export const API = createAPIClient({ } get(navigation).goto( - `${updatingUrl}?returnUrl=${encodeURIComponent(window.location)}` + `${updatingUrl}?returnUrl=${encodeURIComponent(window.location.pathname)}` ) }, }) diff --git a/packages/builder/src/pages/builder/app/[application]/updating.svelte b/packages/builder/src/pages/builder/app/[application]/updating.svelte index dca01e3495..0ea9de2ee3 100644 --- a/packages/builder/src/pages/builder/app/[application]/updating.svelte +++ b/packages/builder/src/pages/builder/app/[application]/updating.svelte @@ -1,6 +1,6 @@
+

+ 🛠️ We are updating the system.
Please wait, we will be back in a + second! +

+
@@ -40,5 +45,15 @@ .loading { display: flex; justify-content: center; + align-items: center; + justify-content: center; + flex-direction: column; + gap: var(--spacing-xl); + height: 100vh; + margin: 0; + } + .loading-message { + text-align: center; + font-size: 18px; } From ec4324697427d58e3ab5a211813f5dc9baf6c240 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Thu, 4 Jan 2024 12:28:36 +0100 Subject: [PATCH 16/28] Error --- .../builder/app/updating/[application].svelte | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/builder/src/pages/builder/app/updating/[application].svelte b/packages/builder/src/pages/builder/app/updating/[application].svelte index bbcdccf917..ff8a873700 100644 --- a/packages/builder/src/pages/builder/app/updating/[application].svelte +++ b/packages/builder/src/pages/builder/app/updating/[application].svelte @@ -7,6 +7,8 @@ const timeoutMs = 60000 // 1 minute const loadTime = Date.now() + let timedOut = false + async function checkMigrationsFinished() { setTimeout(async () => { const response = await API.getMigrationStatus() @@ -27,18 +29,23 @@ checkMigrationsFinished() function migrationTimeout() { - // TODO - alert("Something went wrong 💀") + timedOut = true }
-

- 🛠️ We are updating the system.
Please wait, we will be back in a - second! -

+ {#if !timedOut} +

+ 🛠️ We are updating the system.
Please wait, we will be back in a + second! +

- + + {:else} +

+ An error occurred. Please try again later. +

+ {/if}
From b115ead329e7da914bfceb035ade56543998a38e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 10:46:14 +0100 Subject: [PATCH 17/28] Format frontend --- .../builder/app/updating/[application].svelte | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/packages/builder/src/pages/builder/app/updating/[application].svelte b/packages/builder/src/pages/builder/app/updating/[application].svelte index ff8a873700..6994331eff 100644 --- a/packages/builder/src/pages/builder/app/updating/[application].svelte +++ b/packages/builder/src/pages/builder/app/updating/[application].svelte @@ -1,10 +1,9 @@ -
- {#if !timedOut} -

- 🛠️ We are updating the system.
Please wait, we will be back in a - second! -

- - - {:else} -

- An error occurred. Please try again later. -

- {/if} +
+ {text} + {subtext}
From a427b322beaa5ab63bc9969f83cde54ac1bd7b3e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 11:11:46 +0100 Subject: [PATCH 18/28] Move ui to frontend-core --- .../builder/app/updating/[application].svelte | 64 +++---------------- .../src/components/Updating.svelte | 61 ++++++++++++++++++ .../frontend-core/src/components/index.js | 1 + 3 files changed, 71 insertions(+), 55 deletions(-) create mode 100644 packages/frontend-core/src/components/Updating.svelte diff --git a/packages/builder/src/pages/builder/app/updating/[application].svelte b/packages/builder/src/pages/builder/app/updating/[application].svelte index 6994331eff..ec6196aaca 100644 --- a/packages/builder/src/pages/builder/app/updating/[application].svelte +++ b/packages/builder/src/pages/builder/app/updating/[application].svelte @@ -1,65 +1,19 @@ -
- {text} - {subtext} -
- - + diff --git a/packages/frontend-core/src/components/Updating.svelte b/packages/frontend-core/src/components/Updating.svelte new file mode 100644 index 0000000000..b591c7e61c --- /dev/null +++ b/packages/frontend-core/src/components/Updating.svelte @@ -0,0 +1,61 @@ + + +
+ {text} + {subtext} +
+ + diff --git a/packages/frontend-core/src/components/index.js b/packages/frontend-core/src/components/index.js index 01a7c78cb8..f724e1e4d9 100644 --- a/packages/frontend-core/src/components/index.js +++ b/packages/frontend-core/src/components/index.js @@ -3,4 +3,5 @@ export { default as TestimonialPage } from "./TestimonialPage.svelte" export { default as Testimonial } from "./Testimonial.svelte" export { default as UserAvatar } from "./UserAvatar.svelte" export { default as UserAvatars } from "./UserAvatars.svelte" +export { default as Updating } from "./Updating.svelte" export { Grid } from "./grid" From d46b22e4a6af1dccd8353d176c879b5a48643682 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 11:52:31 +0100 Subject: [PATCH 19/28] Fix initial checks --- packages/server/src/appMigrations/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/appMigrations/index.ts b/packages/server/src/appMigrations/index.ts index b382d8b533..0758b9f324 100644 --- a/packages/server/src/appMigrations/index.ts +++ b/packages/server/src/appMigrations/index.ts @@ -17,7 +17,7 @@ export const getLatestMigrationId = () => .sort() .reverse()[0] -const getTimestamp = (versionId: string) => versionId?.split("_")[0] +const getTimestamp = (versionId: string) => versionId?.split("_")[0] || "" export async function checkMissingMigrations( ctx: UserCtx, From a8019d86cca93376a5e00f1697a09e6d67e8c54a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 12:09:24 +0100 Subject: [PATCH 20/28] Move api checks --- .../src/pages/builder/app/updating/[application].svelte | 9 +-------- packages/frontend-core/src/components/Updating.svelte | 8 +++++--- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/pages/builder/app/updating/[application].svelte b/packages/builder/src/pages/builder/app/updating/[application].svelte index ec6196aaca..ec851fa08d 100644 --- a/packages/builder/src/pages/builder/app/updating/[application].svelte +++ b/packages/builder/src/pages/builder/app/updating/[application].svelte @@ -2,13 +2,6 @@ import { Updating } from "@budibase/frontend-core" import { redirect, params } from "@roxi/routify" - import { API } from "api" - - async function isMigrationDone() { - const response = await API.getMigrationStatus() - return response.migrated - } - async function onMigrationDone() { // For some reason routify params is not stripping the ? properly, so we need to check both with and without ? const returnUrl = $params.returnUrl || $params["?returnUrl"] @@ -16,4 +9,4 @@ } - + diff --git a/packages/frontend-core/src/components/Updating.svelte b/packages/frontend-core/src/components/Updating.svelte index b591c7e61c..57433c1164 100644 --- a/packages/frontend-core/src/components/Updating.svelte +++ b/packages/frontend-core/src/components/Updating.svelte @@ -1,5 +1,6 @@
- {text} - {subtext} + + {#if !timedOut} + System update + {:else} + Something went wrong! + {/if} + + + {#if !timedOut} + Please wait and we will be back in a second! + {:else} + An error occurred, please try again later. +
+ Contact support if the issue persists. + {/if}
From 43aca917d718d4b75f0280fa5f2087d79958b234 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 8 Jan 2024 13:33:41 +0100 Subject: [PATCH 26/28] Fix import --- packages/frontend-core/src/components/Updating.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/Updating.svelte b/packages/frontend-core/src/components/Updating.svelte index 7a13de3ca5..0b80fd2391 100644 --- a/packages/frontend-core/src/components/Updating.svelte +++ b/packages/frontend-core/src/components/Updating.svelte @@ -1,5 +1,5 @@ - + diff --git a/packages/frontend-core/src/components/Updating.svelte b/packages/frontend-core/src/components/Updating.svelte index 16e4b51de4..7d4a101fee 100644 --- a/packages/frontend-core/src/components/Updating.svelte +++ b/packages/frontend-core/src/components/Updating.svelte @@ -1,18 +1,17 @@