Merge branch 'master' into feature/postgresql-multiple-schema

This commit is contained in:
Michael Drury 2024-01-08 15:20:07 +00:00 committed by GitHub
commit c4f6930815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 159 additions and 3 deletions

View File

@ -5,7 +5,7 @@ import {
} from "@budibase/frontend-core" } from "@budibase/frontend-core"
import { store } from "./builderStore" import { store } from "./builderStore"
import { get } from "svelte/store" import { get } from "svelte/store"
import { auth } from "./stores/portal" import { auth, navigation } from "./stores/portal"
export const API = createAPIClient({ export const API = createAPIClient({
attachHeaders: headers => { 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> <script>
import { isActive, redirect, params } from "@roxi/routify" 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 { onMount } from "svelte"
import { CookieUtils, Constants } from "@budibase/frontend-core" import { CookieUtils, Constants } from "@budibase/frontend-core"
import { API } from "api" import { API } from "api"
@ -17,6 +17,8 @@
$: useAccountPortal = cloud && !$admin.disableAccountPortal $: useAccountPortal = cloud && !$admin.disableAccountPortal
navigation.actions.init($redirect)
const validateTenantId = async () => { const validateTenantId = async () => {
const host = window.location.host const host = window.location.host
if (host.includes("localhost:") || !baseUrl) { 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 { menu } from "./menu"
export { auditLogs } from "./auditLogs" export { auditLogs } from "./auditLogs"
export { features } from "./features" export { features } from "./features"
export { navigation } from "./navigation"
export const sideBarCollapsed = writable(false) 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

@ -33,6 +33,7 @@ import { buildEnvironmentVariableEndpoints } from "./environmentVariables"
import { buildEventEndpoints } from "./events" import { buildEventEndpoints } from "./events"
import { buildAuditLogsEndpoints } from "./auditLogs" import { buildAuditLogsEndpoints } from "./auditLogs"
import { buildLogsEndpoints } from "./logs" import { buildLogsEndpoints } from "./logs"
import { buildMigrationEndpoints } from "./migrations"
/** /**
* Random identifier to uniquely identify a session in a tab. This is * Random identifier to uniquely identify a session in a tab. This is
@ -298,6 +299,7 @@ export const createAPIClient = config => {
...buildEventEndpoints(API), ...buildEventEndpoints(API),
...buildAuditLogsEndpoints(API), ...buildAuditLogsEndpoints(API),
...buildLogsEndpoints(API), ...buildLogsEndpoints(API),
...buildMigrationEndpoints(API),
viewV2: buildViewV2Endpoints(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 Testimonial } from "./Testimonial.svelte"
export { default as UserAvatar } from "./UserAvatar.svelte" export { default as UserAvatar } from "./UserAvatar.svelte"
export { default as UserAvatars } from "./UserAvatars.svelte" export { default as UserAvatars } from "./UserAvatars.svelte"
export { default as Updating } from "./Updating.svelte"
export { Grid } from "./grid" export { Grid } from "./grid"

View File

@ -17,7 +17,7 @@ export const getLatestMigrationId = () =>
.sort() .sort()
.reverse()[0] .reverse()[0]
const getTimestamp = (versionId: string) => versionId?.split("_")[0] const getTimestamp = (versionId: string) => versionId?.split("_")[0] || ""
export async function checkMissingMigrations( export async function checkMissingMigrations(
ctx: UserCtx, ctx: UserCtx,