Skip to content

Commit

Permalink
fix bug when filtering snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
cars10 committed Jul 23, 2023
1 parent 699412f commit a938556
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
10 changes: 3 additions & 7 deletions src/components/snapshots/RestoreSnapshot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
<script setup lang="ts">
import IndexSelect from '../shared/IndexFilter/IndexSelect.vue'
import { useTranslation } from '../../composables/i18n'
import { useRestoreSnapshot } from '../../composables/components/snapshots/RestoreSnapshot'
import { RestoreSnapshotProps, useRestoreSnapshot } from '../../composables/components/snapshots/RestoreSnapshot'
const props = defineProps<{ repository: string, snapshot: string }>()
const props = defineProps<RestoreSnapshotProps>()
const emit = defineEmits(['reload'])
const t = useTranslation()
Expand All @@ -70,9 +70,5 @@
restoreSnapshot,
restoreOptions,
resetForm
} = useRestoreSnapshot({
emit,
repository: props.repository,
snapshot: props.snapshot
})
} = useRestoreSnapshot(props, emit)
</script>
33 changes: 22 additions & 11 deletions src/composables/components/snapshots/RestoreSnapshot.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { useTranslation } from '../../i18n'
import { computed, ref } from 'vue'
import { defineElasticsearchRequest, useElasticsearchRequest } from '../../CallElasticsearch'
import { computed, Ref, ref, watch } from 'vue'
import { defineElasticsearchRequest, useElasticsearchAdapter } from '../../CallElasticsearch'

export const useRestoreSnapshot = ({ emit, repository, snapshot }: {
emit: any,
repository: string,
export type RestoreSnapshotProps = {
repository: string
snapshot: string
}) => {
}

export const useRestoreSnapshot = (props: RestoreSnapshotProps, emit: any) => {
const t = useTranslation()

const dialog = ref(false)
Expand All @@ -20,8 +21,18 @@ export const useRestoreSnapshot = ({ emit, repository, snapshot }: {
})
const formValid = computed(() => (restoreOptions.value.indices.length > 0))

const { data, load } = useElasticsearchRequest<any>('getSnapshot', { repository, snapshot })
load().then(() => (indexNames.value = data.value.snapshots[0].indices.sort()))
const { callElasticsearch } = useElasticsearchAdapter()
const data: Ref<any> = ref(null)

const load = () => {
return callElasticsearch('getSnapshot', { repository: props.repository, snapshot: props.snapshot })
.then(body => (data.value = body))
.catch(() => (data.value = null))
}

watch(dialog, newValue => {
if (newValue) load().then(() => (indexNames.value = data.value.snapshots[0].indices.sort()))
})

const resetForm = () => {
restoreOptions.value = {
Expand All @@ -38,8 +49,8 @@ export const useRestoreSnapshot = ({ emit, repository, snapshot }: {
const restoreSnapshot = async () => {
const success = await run({
params: {
repository,
snapshot,
repository: props.repository,
snapshot: props.snapshot,
body: {
indices: restoreOptions.value.indices,
ignore_unavailable: restoreOptions.value.ignoreUnavailable,
Expand All @@ -49,7 +60,7 @@ export const useRestoreSnapshot = ({ emit, repository, snapshot }: {
}
},
snackbarOptions: {
body: t('snapshots.restore_snapshot.restore_snapshot.growl', { snapshot }),
body: t('snapshots.restore_snapshot.restore_snapshot.growl', { snapshot: props.snapshot }),
}
})
if (success) dialog.value = false
Expand Down

0 comments on commit a938556

Please sign in to comment.