| 1 | <template> |
| 2 | <div class="flex flex-col gap-4"> |
| 3 | <n-alert type="info" show-icon> |
| 4 | <template #header>Repository Registration Required</template> |
| 5 | Snapshot repositories must be manually registered in your Wazuh Indexer cluster. |
| 6 | <n-a |
| 7 | href="https://docs.opensearch.org/2.19/tuning-your-cluster/availability-and-recovery/snapshots/snapshot-restore/" |
| 8 | target="_blank" |
| 9 | > |
| 10 | View the documentation |
| 11 | </n-a> |
| 12 | for instructions on how to register a snapshot repository. |
| 13 | </n-alert> |
| 14 | |
| 15 | <div class="flex items-center justify-between"> |
| 16 | <h2 class="text-lg font-semibold">Snapshot Repositories</h2> |
| 17 | <n-button type="primary" :loading @click="fetchRepositories"> |
| 18 | <template #icon> |
| 19 | <Icon :name="RefreshIcon" :size="16" /> |
| 20 | </template> |
| 21 | Refresh |
| 22 | </n-button> |
| 23 | </div> |
| 24 | |
| 25 | <n-spin :show="loading"> |
| 26 | <n-card> |
| 27 | <n-data-table :columns :data="repositories" :bordered="false" :single-line="false" size="small" /> |
| 28 | </n-card> |
| 29 | </n-spin> |
| 30 | |
| 31 | <n-empty v-if="!loading && repositories.length === 0" description="No snapshot repositories found" /> |
| 32 | </div> |
| 33 | </template> |
| 34 | |
| 35 | <script setup lang="ts"> |
| 36 | // TODO-FE: refactor |
| 37 | import type { DataTableColumns } from "naive-ui" |
| 38 | import type { SnapshotRepository } from "@/types/snapshots.d" |
| 39 | import { NA, NAlert, NButton, NCard, NDataTable, NEmpty, NSpin, useMessage } from "naive-ui" |
| 40 | import { h, onBeforeMount, ref } from "vue" |
| 41 | import Api from "@/api" |
| 42 | import Icon from "@/components/common/Icon.vue" |
| 43 | |
| 44 | const RefreshIcon = "carbon:renew" |
| 45 | |
| 46 | const message = useMessage() |
| 47 | const loading = ref(false) |
| 48 | const repositories = ref<SnapshotRepository[]>([]) |
| 49 | |
| 50 | const columns: DataTableColumns<SnapshotRepository> = [ |
| 51 | { |
| 52 | title: "Name", |
| 53 | key: "name", |
| 54 | sorter: "default" |
| 55 | }, |
| 56 | { |
| 57 | title: "Type", |
| 58 | key: "type", |
| 59 | sorter: "default" |
| 60 | }, |
| 61 | { |
| 62 | title: "Settings", |
| 63 | key: "settings", |
| 64 | render(row) { |
| 65 | return h("code", { class: "text-xs" }, JSON.stringify(row.settings, null, 2)) |
| 66 | } |
| 67 | } |
| 68 | ] |
| 69 | |
| 70 | async function fetchRepositories() { |
| 71 | loading.value = true |
| 72 | try { |
| 73 | const response = await Api.snapshots.getRepositories() |
| 74 | if (response.data.success) { |
| 75 | repositories.value = response.data.repositories |
| 76 | } else { |
| 77 | message.error(response.data.message) |
| 78 | } |
| 79 | } catch (error: any) { |
| 80 | message.error(error.message || "Failed to fetch repositories") |
| 81 | } finally { |
| 82 | loading.value = false |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | onBeforeMount(() => { |
| 87 | fetchRepositories() |
| 88 | }) |
| 89 | </script> |