| 1 | <template> |
| 2 | <div class="flex flex-col gap-2"> |
| 3 | <div class="flex items-center gap-2"> |
| 4 | <PlatformBadge :platform /> |
| 5 | <SeverityBadge :severity /> |
| 6 | </div> |
| 7 | <h3 class="font-semibold">{{ name }}</h3> |
| 8 | <p class="text-sm opacity-70">{{ description }}</p> |
| 9 | </div> |
| 10 | </template> |
| 11 | |
| 12 | <script setup lang="ts"> |
| 13 | import type { RuleDetail, RuleSummary } from "@/types/copilotSearches.d" |
| 14 | import { useMessage } from "naive-ui" |
| 15 | import { computed, onBeforeMount, ref } from "vue" |
| 16 | import Api from "@/api" |
| 17 | import PlatformBadge from "@/components/common/PlatformBadge.vue" |
| 18 | import SeverityBadge from "./SeverityBadge.vue" |
| 19 | |
| 20 | const props = defineProps<{ |
| 21 | ruleId?: string |
| 22 | ruleDetail?: RuleDetail |
| 23 | ruleSummary?: RuleSummary |
| 24 | }>() |
| 25 | |
| 26 | const message = useMessage() |
| 27 | const loading = ref(false) |
| 28 | const ruleDetail = ref<RuleDetail | null>(null) |
| 29 | const ruleSummary = ref<RuleSummary | null>(null) |
| 30 | |
| 31 | const platform = computed(() => ruleDetail.value?.tags?.asset_type || ruleSummary.value?.platform || "unknown") |
| 32 | const severity = computed(() => ruleDetail.value?.response?.severity || ruleSummary.value?.severity || "medium") |
| 33 | const name = computed(() => ruleDetail.value?.name || ruleSummary.value?.name || "") |
| 34 | const description = computed(() => ruleDetail.value?.description || ruleSummary.value?.description || "") |
| 35 | |
| 36 | async function loadRule(ruleId: string) { |
| 37 | loading.value = true |
| 38 | |
| 39 | try { |
| 40 | const res = await Api.copilotSearches.getRuleById(ruleId) |
| 41 | if (res.data.success) { |
| 42 | ruleDetail.value = res.data.rule |
| 43 | } else { |
| 44 | message.error(res.data?.message || "Failed to load rule details") |
| 45 | } |
| 46 | } catch (err: any) { |
| 47 | message.error(err.response?.data?.message || "Failed to load rule details") |
| 48 | } finally { |
| 49 | loading.value = false |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | onBeforeMount(() => { |
| 54 | if (props.ruleDetail) { |
| 55 | ruleDetail.value = props.ruleDetail |
| 56 | } else if (props.ruleSummary) { |
| 57 | ruleSummary.value = props.ruleSummary |
| 58 | } else if (props.ruleId) { |
| 59 | loadRule(props.ruleId) |
| 60 | } else { |
| 61 | message.error("No rule data or rule ID provided") |
| 62 | } |
| 63 | }) |
| 64 | </script> |