add restore funtionality
This commit is contained in:
parent
f5c9e22d42
commit
047d605f2f
|
@ -1,5 +1,12 @@
|
|||
<script>
|
||||
import { ActionButton, ActionMenu, MenuItem, Icon } from "@budibase/bbui"
|
||||
import {
|
||||
ActionButton,
|
||||
ActionMenu,
|
||||
MenuItem,
|
||||
Icon,
|
||||
Heading,
|
||||
Body,
|
||||
} from "@budibase/bbui"
|
||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||
import { createEventDispatcher } from "svelte"
|
||||
|
||||
|
@ -7,13 +14,16 @@
|
|||
|
||||
let deleteDialog
|
||||
let restoreDialog
|
||||
let editDialog
|
||||
|
||||
let restoreBackupName
|
||||
|
||||
const dispatch = createEventDispatcher()
|
||||
|
||||
const onClickRestore = () => {
|
||||
dispatch("buttonclick", {
|
||||
type: "backupRestore",
|
||||
backupId: row._id,
|
||||
restoreBackupName,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -33,7 +43,8 @@
|
|||
</div>
|
||||
|
||||
<MenuItem on:click={deleteDialog.show} icon="Delete">Delete</MenuItem>
|
||||
<MenuItem on:click={editDialog.show} icon="Edit">Edit</MenuItem>
|
||||
<MenuItem icon="Edit">Edit</MenuItem>
|
||||
<MenuItem icon="Edit">Download</MenuItem>
|
||||
</ActionMenu>
|
||||
</div>
|
||||
|
||||
|
@ -55,8 +66,8 @@
|
|||
title="Confirm Restore"
|
||||
warning={false}
|
||||
>
|
||||
Are you sure you wish to restore this backup
|
||||
<i>{row.name}</i>. This action cannot be undone.
|
||||
<Heading size="S">{row.name}</Heading>
|
||||
<Body size="S">{new Date(row.timestamp).toLocaleString()}</Body>
|
||||
</ConfirmDialog>
|
||||
|
||||
<style>
|
||||
|
|
|
@ -80,9 +80,21 @@
|
|||
|
||||
function flattenBackups(backups) {
|
||||
let flattened = backups.map(backup => {
|
||||
if (!backup.name) {
|
||||
if (backup.trigger === "publish") {
|
||||
backup.name = "Published Backup"
|
||||
} else if (backup.trigger === "scheduled") {
|
||||
backup.name = "Scheduled Backup"
|
||||
}
|
||||
}
|
||||
|
||||
if (backup.type === "restore") {
|
||||
backup.trigger = "restore"
|
||||
backup.name = "Restored"
|
||||
}
|
||||
return {
|
||||
...backup,
|
||||
days: getDaysBetween(backup.createdAt),
|
||||
days: getDaysBetween(backup.timestamp),
|
||||
...backup?.contents,
|
||||
}
|
||||
})
|
||||
|
@ -123,19 +135,15 @@
|
|||
}
|
||||
}
|
||||
|
||||
function selectBackup({ detail }) {
|
||||
console.log(detail)
|
||||
}
|
||||
async function deleteBackup(backupId) {
|
||||
await backups.deleteBackup({ appId: app.instance._id, backupId })
|
||||
await fetchBackups(app.instance._id, trigger, page)
|
||||
}
|
||||
async function restoreBackup(backupId) {
|
||||
console.log(backupId)
|
||||
//backups.restoreBackup(app.instance._id, backupId)
|
||||
backups.restoreBackup({ appId: app.instance._id, backupId })
|
||||
}
|
||||
|
||||
async function handleButtonClick({ detail }) {
|
||||
function handleButtonClick({ detail }) {
|
||||
if (detail.type === "backupDelete") {
|
||||
deleteBackup(detail.backupId)
|
||||
} else if (detail.type === "backupRestore") {
|
||||
|
@ -152,6 +160,7 @@
|
|||
placeholder="All"
|
||||
label="Trigger"
|
||||
options={Object.values(triggers)}
|
||||
bind:value={trigger}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
|
@ -167,7 +176,6 @@
|
|||
{#if backupData}
|
||||
<div>
|
||||
<Table
|
||||
on:click={selectBackup}
|
||||
{schema}
|
||||
allowSelectRows={false}
|
||||
allowEditColumns={false}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
import { Icon } from "@budibase/bbui"
|
||||
|
||||
export let value
|
||||
|
||||
let trigger = value.charAt(0).toUpperCase() + value.slice(1)
|
||||
$: console.log(value)
|
||||
let trigger = value?.charAt(0).toUpperCase() + value?.slice(1)
|
||||
</script>
|
||||
|
||||
<div class="cell">
|
||||
|
@ -16,6 +16,9 @@
|
|||
{:else if value === "scheduled"}
|
||||
<Icon name="Clock" />
|
||||
<div>{trigger}</div>
|
||||
{:else if value === "restore"}
|
||||
<Icon name="Refresh" />
|
||||
<div>{trigger}</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
|
|
|
@ -2,12 +2,17 @@ export const buildBackupsEndpoints = API => ({
|
|||
/**
|
||||
* Gets a list of users in the current tenant.
|
||||
*/
|
||||
searchBackups: async ({ appId, page }) => {
|
||||
searchBackups: async ({ appId, trigger, page }) => {
|
||||
const opts = {}
|
||||
if (page) {
|
||||
opts.page = page
|
||||
}
|
||||
if (trigger) {
|
||||
opts.trigger = trigger.toLowerCase()
|
||||
}
|
||||
return await API.post({
|
||||
url: `/api/apps/${appId}/backups/search`,
|
||||
body: {
|
||||
page,
|
||||
},
|
||||
body: opts,
|
||||
})
|
||||
},
|
||||
|
||||
|
@ -26,7 +31,13 @@ export const buildBackupsEndpoints = API => ({
|
|||
|
||||
updateBackup: async ({ appId, backupId }) => {
|
||||
return await API.patch({
|
||||
url: `/api/apps/${appId}/backups/${backupId}}`,
|
||||
url: `/api/apps/${appId}/backups/${backupId}`,
|
||||
})
|
||||
},
|
||||
|
||||
restoreBackup: async ({ appId, backupId }) => {
|
||||
return await API.post({
|
||||
url: `/api/apps/${appId}/backups/${backupId}/import`,
|
||||
})
|
||||
},
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue