Merge branch 'master' into BUDI-7571/refactor-fetching-external-ds

This commit is contained in:
Adria Navarro 2024-01-08 16:30:22 +01:00 committed by GitHub
commit 8c0554c3a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 230 additions and 14 deletions

@ -1 +1 @@
Subproject commit 8ee2734e77709438cbcaaabc024f677c7b24c883
Subproject commit bcd86d9034ba954f013da4c10171bf495ab88189

View File

@ -5,7 +5,7 @@ import {
} from "@budibase/frontend-core"
import { store } from "./builderStore"
import { get } from "svelte/store"
import { auth } from "./stores/portal"
import { auth, navigation } from "./stores/portal"
export const API = createAPIClient({
attachHeaders: headers => {
@ -45,4 +45,15 @@ export const API = createAPIClient({
}
}
},
onMigrationDetected: appId => {
const updatingUrl = `/builder/app/updating/${appId}`
if (window.location.pathname === updatingUrl) {
return
}
get(navigation).goto(
`${updatingUrl}?returnUrl=${encodeURIComponent(window.location.pathname)}`
)
},
})

View File

@ -1,6 +1,6 @@
<script>
import { isActive, redirect, params } from "@roxi/routify"
import { admin, auth, licensing } from "stores/portal"
import { admin, auth, licensing, navigation } from "stores/portal"
import { onMount } from "svelte"
import { CookieUtils, Constants } from "@budibase/frontend-core"
import { API } from "api"
@ -17,6 +17,8 @@
$: useAccountPortal = cloud && !$admin.disableAccountPortal
navigation.actions.init($redirect)
const validateTenantId = async () => {
const host = window.location.host
if (host.includes("localhost:") || !baseUrl) {

View File

@ -0,0 +1,19 @@
<script>
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"]
$redirect(returnUrl)
}
</script>
<Updating {isMigrationDone} {onMigrationDone} />

View File

@ -16,5 +16,6 @@ export { environment } from "./environment"
export { menu } from "./menu"
export { auditLogs } from "./auditLogs"
export { features } from "./features"
export { navigation } from "./navigation"
export const sideBarCollapsed = writable(false)

View File

@ -0,0 +1,31 @@
import { writable } from "svelte/store"
export function createNavigationStore() {
const store = writable({
initialisated: false,
goto: undefined,
})
const { set, subscribe } = store
const init = gotoFunc => {
if (typeof gotoFunc !== "function") {
throw new Error(
`gotoFunc must be a function, found a "${typeof gotoFunc}" instead`
)
}
set({
initialisated: true,
goto: gotoFunc,
})
}
return {
subscribe,
actions: {
init,
},
}
}
export const navigation = createNavigationStore()

View File

@ -37,7 +37,6 @@
"downloadjs": "1.4.7",
"html5-qrcode": "^2.2.1",
"leaflet": "^1.7.1",
"regexparam": "^1.3.0",
"sanitize-html": "^2.7.0",
"screenfull": "^6.0.1",
"shortid": "^2.2.15",

View File

@ -77,4 +77,10 @@ export const API = createAPIClient({
// Log all errors to console
console.warn(`[Client] HTTP ${status} on ${method}:${url}\n\t${message}`)
},
onMigrationDetected: _appId => {
if (!window.MIGRATING_APP) {
// We will force a reload, that will display the updating screen until the migration is running
window.location.reload()
}
},
})

View File

@ -0,0 +1,23 @@
<script>
import { Updating } from "@budibase/frontend-core"
import { API } from "../api"
async function isMigrationDone() {
const response = await API.getMigrationStatus()
return response.migrated
}
async function onMigrationDone() {
window.location.reload()
}
</script>
<div class="updating">
<Updating {isMigrationDone} {onMigrationDone} />
</div>
<style>
.updating {
font-family: var(--font-sans);
}
</style>

View File

@ -1,4 +1,5 @@
import ClientApp from "./components/ClientApp.svelte"
import UpdatingApp from "./components/UpdatingApp.svelte"
import {
builderStore,
appStore,
@ -52,6 +53,13 @@ const loadBudibase = async () => {
window["##BUDIBASE_APP_EMBEDDED##"] === "true"
)
if (window.MIGRATING_APP) {
new UpdatingApp({
target: window.document.body,
})
return
}
// Fetch environment info
if (!get(environmentStore)?.loaded) {
await environmentStore.actions.fetchEnvironment()

View File

@ -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),
}
}

View File

@ -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",
})
},
})

View File

@ -0,0 +1,79 @@
<script>
export let isMigrationDone
export let onMigrationDone
export let timeoutSeconds = 10 // 3 minutes
const loadTime = Date.now()
let timedOut = false
async function checkMigrationsFinished() {
setTimeout(async () => {
const isMigrated = await isMigrationDone()
const timeoutMs = timeoutSeconds * 1000
if (!isMigrated) {
if (loadTime + timeoutMs > Date.now()) {
return checkMigrationsFinished()
}
return migrationTimeout()
}
onMigrationDone()
}, 1000)
}
checkMigrationsFinished()
function migrationTimeout() {
timedOut = true
}
</script>
<div class="loading" class:timeout={timedOut}>
<span class="header">
{#if !timedOut}
System update
{:else}
Something went wrong!
{/if}
</span>
<span class="subtext">
{#if !timedOut}
Please wait and we will be back in a second!
{:else}
An error occurred, please try again later.
<br />
Contact
<a href="https://budibase.com/support/" target="_blank">support</a> if the
issue persists.
{/if}</span
>
</div>
<style>
.loading {
display: flex;
justify-content: center;
flex-direction: column;
gap: var(--spacing-l);
height: 100vh;
text-align: center;
font-size: 18px;
}
.header {
font-weight: 700;
}
.timeout .header {
color: rgb(196, 46, 46);
}
.subtext {
font-size: 16px;
color: var(--grey-7);
}
.subtext a {
color: var(--grey-7);
font-weight: 700;
}
</style>

View File

@ -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"

View File

@ -7,7 +7,7 @@
"../shared-core",
"../string-templates"
],
"ext": "js,ts,json",
"ext": "js,ts,json,svelte",
"ignore": ["src/**/*.spec.ts", "src/**/*.spec.js", "../*/dist/**/*"],
"exec": "yarn build && node ./dist/index.js"
}

View File

@ -25,8 +25,12 @@ import fs from "fs"
import sdk from "../../../sdk"
import * as pro from "@budibase/pro"
import { App, Ctx, ProcessAttachmentResponse } from "@budibase/types"
import {
getAppMigrationVersion,
getLatestMigrationId,
} from "../../../appMigrations"
const send = require("koa-send")
import send from "koa-send"
export const toggleBetaUiFeature = async function (ctx: Ctx) {
const cookieName = `beta:${ctx.params.feature}`
@ -125,7 +129,26 @@ export const deleteObjects = async function (ctx: Ctx) {
)
}
const requiresMigration = async (ctx: Ctx) => {
const appId = context.getAppId()
if (!appId) {
ctx.throw("AppId could not be found")
}
const latestMigration = getLatestMigrationId()
if (!latestMigration) {
return false
}
const latestMigrationApplied = await getAppMigrationVersion(appId)
const requiresMigrations = latestMigrationApplied !== latestMigration
return requiresMigrations
}
export const serveApp = async function (ctx: Ctx) {
const needMigrations = await requiresMigration(ctx)
const bbHeaderEmbed =
ctx.request.get("x-budibase-embed")?.toLowerCase() === "true"
@ -145,8 +168,8 @@ export const serveApp = async function (ctx: Ctx) {
let appId = context.getAppId()
if (!env.isJest()) {
const App = require("./templates/BudibaseApp.svelte").default
const plugins = objectStore.enrichPluginURLs(appInfo.usedPlugins)
const App = require("./templates/BudibaseApp.svelte").default
const { head, html, css } = App.render({
metaImage:
branding?.metaImageUrl ||
@ -167,6 +190,7 @@ export const serveApp = async function (ctx: Ctx) {
config?.logoUrl !== ""
? objectStore.getGlobalFileUrl("settings", "logoUrl")
: "",
appMigrating: needMigrations,
})
const appHbs = loadHandlebarsFile(appHbsPath)
ctx.body = await processString(appHbs, {
@ -273,7 +297,6 @@ export const getSignedUploadURL = async function (ctx: Ctx) {
const { bucket, key } = ctx.request.body || {}
if (!bucket || !key) {
ctx.throw(400, "bucket and key values are required")
return
}
try {
const s3 = new AWS.S3({

View File

@ -8,6 +8,7 @@
export let clientLibPath
export let usedPlugins
export let appMigrating
</script>
<svelte:head>
@ -110,6 +111,11 @@
<script type="application/javascript">
window.INIT_TIME = Date.now()
</script>
{#if appMigrating}
<script type="application/javascript">
window.MIGRATING_APP = true
</script>
{/if}
<script type="application/javascript" src={clientLibPath}>
</script>
<!-- Custom components need inserted after the core client library -->

View File

@ -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,

View File

@ -18312,11 +18312,6 @@ regexparam@2.0.1:
resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-2.0.1.tgz#c912f5dae371e3798100b3c9ce22b7414d0889fa"
integrity sha512-zRgSaYemnNYxUv+/5SeoHI0eJIgTL/A2pUtXUPLHQxUldagouJ9p+K6IbIZ/JiQuCEv2E2B1O11SjVQy3aMCkw==
regexparam@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-1.3.0.tgz#2fe42c93e32a40eff6235d635e0ffa344b92965f"
integrity sha512-6IQpFBv6e5vz1QAqI+V4k8P2e/3gRrqfCJ9FI+O1FLQTO+Uz6RXZEZOPmTJ6hlGj7gkERzY5BRCv09whKP96/g==
regexpu-core@^5.3.1:
version "5.3.1"
resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-5.3.1.tgz#66900860f88def39a5cb79ebd9490e84f17bcdfb"