2021-07-08 04:07:42 +12:00
|
|
|
<script>
|
|
|
|
import {
|
|
|
|
Icon,
|
|
|
|
Modal,
|
|
|
|
notifications,
|
|
|
|
ModalContent,
|
|
|
|
Body,
|
2021-07-08 04:35:28 +12:00
|
|
|
Button,
|
2021-07-08 04:07:42 +12:00
|
|
|
} from "@budibase/bbui"
|
|
|
|
import { store } from "builderStore"
|
|
|
|
import api from "builderStore/api"
|
|
|
|
import clientPackage from "@budibase/client/package.json"
|
|
|
|
|
|
|
|
let updateModal
|
|
|
|
|
|
|
|
$: appId = $store.appId
|
|
|
|
$: updateAvailable = clientPackage.version !== $store.version
|
2021-07-08 04:35:28 +12:00
|
|
|
$: revertAvailable = $store.revertableVersion != null
|
|
|
|
|
|
|
|
const refreshAppPackage = async () => {
|
|
|
|
const applicationPkg = await api.get(
|
|
|
|
`/api/applications/${appId}/appPackage`
|
|
|
|
)
|
|
|
|
const pkg = await applicationPkg.json()
|
|
|
|
if (applicationPkg.ok) {
|
|
|
|
await store.actions.initialise(pkg)
|
|
|
|
} else {
|
|
|
|
throw new Error(pkg)
|
|
|
|
}
|
|
|
|
}
|
2021-07-08 04:07:42 +12:00
|
|
|
|
|
|
|
const update = async () => {
|
|
|
|
try {
|
|
|
|
const response = await api.post(
|
|
|
|
`/api/applications/${appId}/client/update`
|
|
|
|
)
|
|
|
|
const json = await response.json()
|
|
|
|
if (response.status !== 200) {
|
|
|
|
throw json.message
|
|
|
|
}
|
2021-07-08 23:56:35 +12:00
|
|
|
|
|
|
|
// Don't wait for the async refresh, since this causes modal flashing
|
|
|
|
refreshAppPackage()
|
2021-07-08 04:35:28 +12:00
|
|
|
notifications.success(
|
|
|
|
`App updated successfully to version ${clientPackage.version}`
|
|
|
|
)
|
|
|
|
} catch (err) {
|
|
|
|
notifications.error(`Error updating app: ${err}`)
|
|
|
|
}
|
|
|
|
}
|
2021-07-08 04:07:42 +12:00
|
|
|
|
2021-07-08 04:35:28 +12:00
|
|
|
const revert = async () => {
|
|
|
|
try {
|
2021-07-08 23:56:35 +12:00
|
|
|
const revertableVersion = $store.revertableVersion
|
2021-07-08 04:35:28 +12:00
|
|
|
const response = await api.post(
|
|
|
|
`/api/applications/${appId}/client/revert`
|
2021-07-08 04:07:42 +12:00
|
|
|
)
|
2021-07-08 04:35:28 +12:00
|
|
|
const json = await response.json()
|
|
|
|
if (response.status !== 200) {
|
|
|
|
throw json.message
|
2021-07-08 04:07:42 +12:00
|
|
|
}
|
2021-07-08 23:56:35 +12:00
|
|
|
|
|
|
|
// Don't wait for the async refresh, since this causes modal flashing
|
|
|
|
refreshAppPackage()
|
2021-07-08 04:07:42 +12:00
|
|
|
notifications.success(
|
2021-07-08 23:56:35 +12:00
|
|
|
`App reverted successfully to version ${revertableVersion}`
|
2021-07-08 04:07:42 +12:00
|
|
|
)
|
|
|
|
} catch (err) {
|
2021-07-08 04:35:28 +12:00
|
|
|
notifications.error(`Error reverting app: ${err}`)
|
2021-07-08 04:07:42 +12:00
|
|
|
}
|
2021-07-08 04:35:28 +12:00
|
|
|
updateModal.hide()
|
2021-07-08 04:07:42 +12:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="icon-wrapper" class:highlight={updateAvailable}>
|
|
|
|
<Icon name="Refresh" hoverable on:click={updateModal.show} />
|
|
|
|
</div>
|
|
|
|
<Modal bind:this={updateModal}>
|
|
|
|
<ModalContent
|
|
|
|
title="App version"
|
|
|
|
confirmText="Update"
|
|
|
|
cancelText={updateAvailable ? "Cancel" : "Close"}
|
|
|
|
onConfirm={update}
|
|
|
|
showConfirmButton={updateAvailable}
|
|
|
|
>
|
2021-07-08 04:35:28 +12:00
|
|
|
<div slot="footer">
|
|
|
|
{#if revertAvailable}
|
|
|
|
<Button quiet secondary on:click={revert}>Revert</Button>
|
|
|
|
{/if}
|
|
|
|
</div>
|
2021-07-08 04:07:42 +12:00
|
|
|
{#if updateAvailable}
|
|
|
|
<Body size="S">
|
|
|
|
This app is currently using version <b>{$store.version}</b>, but version
|
2021-07-08 04:35:28 +12:00
|
|
|
<b>{clientPackage.version}</b> is available. Updates can contain new features,
|
|
|
|
performance improvements and bug fixes.
|
2021-07-08 04:07:42 +12:00
|
|
|
</Body>
|
|
|
|
{:else}
|
|
|
|
<Body size="S">
|
|
|
|
This app is currently using version <b>{$store.version}</b> which is the
|
|
|
|
latest version available.
|
|
|
|
</Body>
|
|
|
|
{/if}
|
2021-07-08 04:35:28 +12:00
|
|
|
{#if revertAvailable}
|
|
|
|
<Body size="S">
|
|
|
|
You can revert this app to version
|
|
|
|
<b>{$store.revertableVersion}</b>
|
|
|
|
if you're experiencing issues with the current version.
|
|
|
|
</Body>
|
|
|
|
{/if}
|
2021-07-08 04:07:42 +12:00
|
|
|
</ModalContent>
|
|
|
|
</Modal>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.icon-wrapper {
|
|
|
|
display: contents;
|
|
|
|
}
|
|
|
|
.icon-wrapper.highlight :global(svg) {
|
|
|
|
color: var(--spectrum-global-color-blue-600);
|
|
|
|
}
|
|
|
|
</style>
|