Browse Source

feat: restore snapshots

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

Loading…
Cancel
Save