main
vue 61 lines 1.76 KB
Raw
1 <template>
2 <n-spin :show="loading" class="min-h-48">
3 <n-timeline class="mt-4">
4 <n-timeline-item
5 v-for="(item, $index) of timeline"
6 :key="item._id"
7 :type="$index === 0 ? 'success' : undefined"
8 :line-type="$index === timeline.length - 2 ? 'dashed' : undefined"
9 :time="formatDateTime(item._source.timestamp)"
10 class="pb-4"
11 >
12 <AlertDetailTimelineItem :timeline-data="item" embedded class="-mt-3" />
13 </n-timeline-item>
14 </n-timeline>
15 </n-spin>
16 </template>
17
18 <script setup lang="ts">
19 import type { AlertAsset, AlertTimeline } from "@/types/incidentManagement/alerts.d"
20 import { NSpin, NTimeline, NTimelineItem, useMessage } from "naive-ui"
21 import { onBeforeMount, ref } from "vue"
22 import Api from "@/api"
23 import { useSettingsStore } from "@/stores/settings"
24 import { formatDate } from "@/utils/format"
25 import AlertDetailTimelineItem from "./AlertDetailTimelineItem.vue"
26
27 const { asset } = defineProps<{ asset: AlertAsset }>()
28
29 const dFormats = useSettingsStore().dateFormat
30 const loading = ref(false)
31 const message = useMessage()
32 const timeline = ref<AlertTimeline[]>([])
33
34 function formatDateTime(timestamp: Date | string): string {
35 return formatDate(timestamp, dFormats.datetimesec).toString()
36 }
37
38 function getAlertTimeline() {
39 loading.value = true
40
41 Api.incidentManagement.alerts
42 .getAlertTimeline(asset.index_id, asset.index_name)
43 .then(res => {
44 if (res.data.success) {
45 timeline.value = res.data?.alert_timeline || []
46 } else {
47 message.warning(res.data?.message || "An error occurred. Please try again later.")
48 }
49 })
50 .catch(err => {
51 message.error(err.response?.data?.message || "An error occurred. Please try again later.")
52 })
53 .finally(() => {
54 loading.value = false
55 })
56 }
57
58 onBeforeMount(() => {
59 getAlertTimeline()
60 })
61 </script>