budibase/packages/builder/src/components/deploy/VersionModal.svelte

112 lines
2.9 KiB
Svelte
Raw Normal View History

<script>
import {
Modal,
notifications,
ModalContent,
Body,
Button,
StatusLight,
} from "@budibase/bbui"
2023-10-30 13:46:44 +01:00
import { appStore, initialise } from "stores/frontend"
import { API } from "api"
export function show() {
updateModal.show()
}
export function hide() {
updateModal.hide()
}
export let onComplete = () => {}
export let hideIcon = false
let updateModal
2023-10-30 13:46:44 +01:00
$: appId = $appStore.appId
2023-03-02 00:05:17 +01:00
$: updateAvailable =
2023-10-30 13:46:44 +01:00
$appStore.upgradableVersion &&
$appStore.version &&
$appStore.upgradableVersion !== $appStore.version
$: revertAvailable = $appStore.revertableVersion != null
const refreshAppPackage = async () => {
try {
const pkg = await API.fetchAppPackage(appId)
2023-10-30 13:46:44 +01:00
await initialise(pkg)
} catch (error) {
notifications.error("Error fetching app package")
}
}
const update = async () => {
try {
await API.updateAppClientVersion(appId)
// Don't wait for the async refresh, since this causes modal flashing
refreshAppPackage()
notifications.success(
2023-10-30 13:46:44 +01:00
`App updated successfully to version ${$appStore.upgradableVersion}`
)
onComplete()
} catch (err) {
notifications.error(`Error updating app: ${err}`)
}
updateModal.hide()
}
const revert = async () => {
try {
await API.revertAppClientVersion(appId)
// Don't wait for the async refresh, since this causes modal flashing
refreshAppPackage()
notifications.success(
2023-10-30 13:46:44 +01:00
`App reverted successfully to version ${$appStore.revertableVersion}`
)
} catch (err) {
notifications.error(`Error reverting app: ${err}`)
}
updateModal.hide()
}
</script>
{#if !hideIcon && updateAvailable}
<StatusLight hoverable on:click={updateModal.show} notice>Update</StatusLight>
{/if}
<Modal bind:this={updateModal}>
<ModalContent
title="App version"
confirmText="Update"
cancelText={updateAvailable ? "Cancel" : "Close"}
onConfirm={update}
showConfirmButton={updateAvailable}
>
<div slot="footer">
{#if revertAvailable}
<Button quiet secondary on:click={revert}>Revert</Button>
{/if}
</div>
{#if updateAvailable}
<Body size="S">
2023-10-30 13:46:44 +01:00
This app is currently using version <b>{$appStore.version}</b>, but
version
<b>{$appStore.upgradableVersion}</b> is available. Updates can contain new
features, performance improvements and bug fixes.
</Body>
{:else}
<Body size="S">
2023-10-30 13:46:44 +01:00
This app is currently using version <b>{$appStore.version}</b> which is the
latest version available.
</Body>
{/if}
{#if revertAvailable}
<Body size="S">
You can revert this app to version
2023-10-30 13:46:44 +01:00
<b>{$appStore.revertableVersion}</b>
if you're experiencing issues with the current version.
</Body>
{/if}
</ModalContent>
</Modal>