Add UI to revert app version and initial work on app revert backend
This commit is contained in:
parent
0a44b1e3d8
commit
9440e4a5bf
|
@ -76,6 +76,7 @@ export const getFrontendStore = () => {
|
||||||
clientLibPath,
|
clientLibPath,
|
||||||
previousTopNavPath: {},
|
previousTopNavPath: {},
|
||||||
version: application.version,
|
version: application.version,
|
||||||
|
revertableVersion: application.revertableVersion,
|
||||||
}))
|
}))
|
||||||
await hostingStore.actions.fetch()
|
await hostingStore.actions.fetch()
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
notifications,
|
notifications,
|
||||||
ModalContent,
|
ModalContent,
|
||||||
Body,
|
Body,
|
||||||
|
Button,
|
||||||
} from "@budibase/bbui"
|
} from "@budibase/bbui"
|
||||||
import { store } from "builderStore"
|
import { store } from "builderStore"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
@ -14,6 +15,19 @@
|
||||||
|
|
||||||
$: appId = $store.appId
|
$: appId = $store.appId
|
||||||
$: updateAvailable = clientPackage.version !== $store.version
|
$: 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 () => {
|
const update = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -24,18 +38,7 @@
|
||||||
if (response.status !== 200) {
|
if (response.status !== 200) {
|
||||||
throw json.message
|
throw json.message
|
||||||
}
|
}
|
||||||
|
await refreshAppPackage()
|
||||||
// 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)
|
|
||||||
}
|
|
||||||
|
|
||||||
notifications.success(
|
notifications.success(
|
||||||
`App updated successfully to version ${clientPackage.version}`
|
`App updated successfully to version ${clientPackage.version}`
|
||||||
)
|
)
|
||||||
|
@ -43,6 +46,25 @@
|
||||||
notifications.error(`Error updating app: ${err}`)
|
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>
|
</script>
|
||||||
|
|
||||||
<div class="icon-wrapper" class:highlight={updateAvailable}>
|
<div class="icon-wrapper" class:highlight={updateAvailable}>
|
||||||
|
@ -56,13 +78,16 @@
|
||||||
onConfirm={update}
|
onConfirm={update}
|
||||||
showConfirmButton={updateAvailable}
|
showConfirmButton={updateAvailable}
|
||||||
>
|
>
|
||||||
|
<div slot="footer">
|
||||||
|
{#if revertAvailable}
|
||||||
|
<Button quiet secondary on:click={revert}>Revert</Button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
{#if updateAvailable}
|
{#if updateAvailable}
|
||||||
<Body size="S">
|
<Body size="S">
|
||||||
This app is currently using version <b>{$store.version}</b>, but version
|
This app is currently using version <b>{$store.version}</b>, but version
|
||||||
<b>{clientPackage.version}</b> is available. Updates can contain new
|
<b>{clientPackage.version}</b> is available. Updates can contain new features,
|
||||||
features, performance improvements and bug fixes.
|
performance improvements and bug fixes.
|
||||||
<br /><br />
|
|
||||||
Would you like to update this app?
|
|
||||||
</Body>
|
</Body>
|
||||||
{:else}
|
{:else}
|
||||||
<Body size="S">
|
<Body size="S">
|
||||||
|
@ -70,6 +95,13 @@
|
||||||
latest version available.
|
latest version available.
|
||||||
</Body>
|
</Body>
|
||||||
{/if}
|
{/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>
|
</ModalContent>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
|
|
@ -241,8 +241,19 @@ exports.update = async function (ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.updateClient = 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)
|
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)
|
const data = await updateAppPackage(ctx, appPackageUpdates, ctx.params.appId)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.body = data
|
ctx.body = data
|
||||||
|
|
Loading…
Reference in New Issue