Browse Source

feat: restore snapshots

pull/9879/head
DarkPhoenix2704 3 days ago
parent
commit
73f59e5d04
  1. 13
      packages/nc-gui/components/dlg/Snapshot/Restore.vue
  2. 11
      packages/nc-gui/composables/useBaseSettings.ts

13
packages/nc-gui/components/dlg/Snapshot/Restore.vue

@ -17,7 +17,18 @@ const { snapshot } = props
const vModel = useVModel(props, 'modelValue', emits)
const { restoreSnapshot, isRestoringSnapshot } = useBaseSettings()
const { restoreSnapshot: _restoreSnapshot, isRestoringSnapshot } = useBaseSettings()
const restoreSnapshot = async (snapshot: SnapshotExtendedType) => {
try {
await _restoreSnapshot(snapshot, () => {
vModel.value = false
emits('update:modelValue', false)
})
} catch (error) {
console.error(error)
}
}
</script>
<template>

11
packages/nc-gui/composables/useBaseSettings.ts

@ -126,14 +126,14 @@ export const useBaseSettings = createSharedComposable(() => {
}
}
const restoreSnapshot = async (snapshot: SnapshotExtendedType) => {
const restoreSnapshot = async (snapshot: SnapshotExtendedType, onRestoreSuccess?: () => void | Promise<void>) => {
if (!baseId.value) return
try {
isRestoringSnapshot.value = true
await $api.snapshot.restore(baseId.value, snapshot.id!)
const response = await $api.snapshot.restore(baseId.value, snapshot.id!)
$poller.subscribe(
{ id: snapshot.id! },
{ id: response.id! },
async (data: {
id: string
status?: string
@ -147,7 +147,8 @@ export const useBaseSettings = createSharedComposable(() => {
}) => {
if (data.status === JobStatus.COMPLETED) {
await loadProjects('workspace')
const base = bases.value.get(data.id)
const base = bases.value.get(data.data?.result.id)
isRestoringSnapshot.value = false
@ -161,6 +162,8 @@ export const useBaseSettings = createSharedComposable(() => {
}
message.info('Snapshot restored successfully')
onRestoreSuccess?.()
refreshCommandPalette()
} else if (data.status === JobStatus.FAILED) {
message.error('Failed to restore snapshot')

Loading…
Cancel
Save