Add UI to revert app version and initial work on app revert backend

This commit is contained in:
Andrew Kingston 2021-07-07 17:35:28 +01:00
parent 0a44b1e3d8
commit 9440e4a5bf
3 changed files with 61 additions and 17 deletions

View File

@ -76,6 +76,7 @@ export const getFrontendStore = () => {
clientLibPath,
previousTopNavPath: {},
version: application.version,
revertableVersion: application.revertableVersion,
}))
await hostingStore.actions.fetch()

View File

@ -5,6 +5,7 @@
notifications,
ModalContent,
Body,
Button,
} from "@budibase/bbui"
import { store } from "builderStore"
import api from "builderStore/api"
@ -14,6 +15,19 @@
$: appId = $store.appId
$: updateAvailable = clientPackage.version !== $store.version
$: 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)
}
}
const update = async () => {
try {
@ -24,18 +38,7 @@
if (response.status !== 200) {
throw json.message
}
// Reset frontend state after revert
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)
}
await refreshAppPackage()
notifications.success(
`App updated successfully to version ${clientPackage.version}`
)
@ -43,6 +46,25 @@
notifications.error(`Error updating app: ${err}`)
}
}
const revert = async () => {
try {
const response = await api.post(
`/api/applications/${appId}/client/revert`
)
const json = await response.json()
if (response.status !== 200) {
throw json.message
}
await refreshAppPackage()
notifications.success(
`App reverted successfully to version ${$store.revertableVersion}`
)
} catch (err) {
notifications.error(`Error reverting app: ${err}`)
}
updateModal.hide()
}
</script>
<div class="icon-wrapper" class:highlight={updateAvailable}>
@ -56,13 +78,16 @@
onConfirm={update}
showConfirmButton={updateAvailable}
>
<div slot="footer">
{#if revertAvailable}
<Button quiet secondary on:click={revert}>Revert</Button>
{/if}
</div>
{#if updateAvailable}
<Body size="S">
This app is currently using version <b>{$store.version}</b>, but version
<b>{clientPackage.version}</b> is available. Updates can contain new
features, performance improvements and bug fixes.
<br /><br />
Would you like to update this app?
<b>{clientPackage.version}</b> is available. Updates can contain new features,
performance improvements and bug fixes.
</Body>
{:else}
<Body size="S">
@ -70,6 +95,13 @@
latest version available.
</Body>
{/if}
{#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}
</ModalContent>
</Modal>

View File

@ -241,8 +241,19 @@ exports.update = async function (ctx) {
}
exports.updateClient = async function (ctx) {
// Get current app version
const db = new CouchDB(ctx.params.appId)
const application = await db.get(DocumentTypes.APP_METADATA)
const currentVersion = application.version
// Update client library and manifest
await uploadClientLibrary(ctx.params.appId)
const appPackageUpdates = { version: packageJson.version }
// Update versions in app package
const appPackageUpdates = {
version: packageJson.version,
revertableVersion: currentVersion,
}
const data = await updateAppPackage(ctx, appPackageUpdates, ctx.params.appId)
ctx.status = 200
ctx.body = data