main
vue 97 lines 2.71 KB
Raw
1 <template>
2 <div>
3 <n-collapse-transition :show="!showForm">
4 <n-button v-if="iocs.length" :loading="submitting" type="primary" @click="openForm()">
5 <template #icon>
6 <Icon :name="AddIcon" />
7 </template>
8 Create IoC
9 </n-button>
10 </n-collapse-transition>
11
12 <CollapseKeepAlive :show="showForm">
13 <div class="flex flex-col gap-2">
14 <AlertIoCsForm
15 v-model:loading="submitting"
16 :alert-id
17 @mounted="formCTX = $event"
18 @submitted="addIoc($event)"
19 >
20 <template #additionalActions>
21 <n-button secondary :disabled="submitting" @click="closeForm()">Close</n-button>
22 </template>
23 </AlertIoCsForm>
24 </div>
25 </CollapseKeepAlive>
26
27 <CollapseKeepAlive :show="!showForm">
28 <div class="mt-3 flex flex-col gap-2">
29 <template v-if="iocs.length">
30 <AlertIoCItem v-for="ioc of iocs" :key="ioc.id" :ioc :alert-id embedded @deleted="delIoc(ioc)" />
31 </template>
32 <template v-else>
33 <n-collapse-transition :show="!showForm">
34 <n-empty v-if="!loading" class="min-h-48">
35 <div class="flex flex-col items-center gap-4">
36 <p>No IoCs found</p>
37 <n-button type="primary" :loading="submitting" @click="openForm()">
38 <template #icon>
39 <Icon :name="AddIcon" />
40 </template>
41 Create an IoCs
42 </n-button>
43 </div>
44 </n-empty>
45 </n-collapse-transition>
46 </template>
47 </div>
48 </CollapseKeepAlive>
49 </div>
50 </template>
51
52 <script setup lang="ts">
53 import type { AlertIOC } from "@/types/incidentManagement/alerts.d"
54 import { NButton, NCollapseTransition, NEmpty } from "naive-ui"
55 import { computed, ref, toRefs } from "vue"
56 import CollapseKeepAlive from "@/components/common/CollapseKeepAlive.vue"
57 import Icon from "@/components/common/Icon.vue"
58 import AlertIoCItem from "./AlertIoCItem.vue"
59 import AlertIoCsForm from "./AlertIoCsForm.vue"
60
61 const props = defineProps<{ iocs: AlertIOC[]; alertId: number }>()
62 const emit = defineEmits<{
63 (e: "updated", value: AlertIOC[]): void
64 }>()
65
66 const { iocs, alertId } = toRefs(props)
67
68 const AddIcon = "carbon:add-alt"
69 const iocsList = ref<AlertIOC[]>(iocs.value)
70 const showForm = ref(false)
71 const submitting = ref(false)
72 const deleting = ref(false)
73 const loading = computed(() => submitting.value || deleting.value)
74 const formCTX = ref<{ reset: (force?: boolean) => void } | null>(null)
75
76 function openForm() {
77 showForm.value = true
78 }
79
80 function closeForm(doReset?: boolean) {
81 showForm.value = false
82 if (doReset) {
83 formCTX.value?.reset(true)
84 }
85 }
86
87 function delIoc(ioc: AlertIOC) {
88 iocsList.value = iocsList.value.filter(o => o.id !== ioc.id)
89 emit("updated", iocsList.value)
90 }
91
92 function addIoc(ioc: AlertIOC) {
93 iocsList.value.push(ioc)
94 closeForm(true)
95 emit("updated", iocsList.value)
96 }
97 </script>