| 1 | <template> |
| 2 | <n-popover v-model:show="show" trigger="manual" to="body" content-class="px-0" @clickoutside="closePopup()"> |
| 3 | <template #trigger> |
| 4 | <slot :loading :toggle-popup /> |
| 5 | </template> |
| 6 | |
| 7 | <div class="flex flex-col gap-4 py-1"> |
| 8 | <div> |
| 9 | Are you sure you want to delete the Query |
| 10 | <strong>#{{ query.id }}</strong> |
| 11 | ? |
| 12 | </div> |
| 13 | |
| 14 | <div class="flex justify-between gap-2"> |
| 15 | <n-button quaternary size="small" @click="closePopup()">Close</n-button> |
| 16 | <n-button :loading type="error" size="small" @click="deleteQuery()"> |
| 17 | <template #icon> |
| 18 | <Icon :name="TrashIcon" /> |
| 19 | </template> |
| 20 | Delete Query |
| 21 | </n-button> |
| 22 | </div> |
| 23 | </div> |
| 24 | </n-popover> |
| 25 | </template> |
| 26 | |
| 27 | <script setup lang="ts"> |
| 28 | import type { SigmaQuery } from "@/types/sigma.d" |
| 29 | import { NButton, NPopover, useMessage } from "naive-ui" |
| 30 | import { ref, toRefs } from "vue" |
| 31 | import Api from "@/api" |
| 32 | import Icon from "@/components/common/Icon.vue" |
| 33 | |
| 34 | const props = defineProps<{ |
| 35 | query: SigmaQuery |
| 36 | }>() |
| 37 | |
| 38 | const emit = defineEmits<{ |
| 39 | (e: "deleted", value: SigmaQuery): void |
| 40 | }>() |
| 41 | |
| 42 | const { query } = toRefs(props) |
| 43 | |
| 44 | const loading = defineModel<boolean | undefined>("loading", { default: false }) |
| 45 | |
| 46 | const TrashIcon = "carbon:trash-can" |
| 47 | const show = ref(false) |
| 48 | const lastShow = ref(Date.now()) |
| 49 | const message = useMessage() |
| 50 | |
| 51 | function togglePopup() { |
| 52 | if (Date.now() - lastShow.value > 500) { |
| 53 | show.value = !show.value |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | function closePopup() { |
| 58 | lastShow.value = Date.now() |
| 59 | show.value = false |
| 60 | } |
| 61 | |
| 62 | function deleteQuery() { |
| 63 | if (query.value.rule_name) { |
| 64 | loading.value = true |
| 65 | |
| 66 | Api.sigma |
| 67 | .deleteRule(query.value.rule_name) |
| 68 | .then(res => { |
| 69 | if (res.data.success) { |
| 70 | emit("deleted", query.value) |
| 71 | message.success(res.data?.message || "Sigma query deleted successfully") |
| 72 | } else { |
| 73 | message.warning(res.data?.message || "An error occurred. Please try again later.") |
| 74 | } |
| 75 | }) |
| 76 | .catch(err => { |
| 77 | message.error(err.response?.data?.message || "An error occurred. Please try again later.") |
| 78 | }) |
| 79 | .finally(() => { |
| 80 | loading.value = false |
| 81 | }) |
| 82 | } |
| 83 | } |
| 84 | </script> |