From 97ff6e253191d3a96f66499f5a778e6cc2c5f7c5 Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sun, 14 Jan 2024 10:06:30 +0900 Subject: [PATCH 1/5] refactor: unify tags behavior --- frontend/src/components/alert/Alert.vue | 2 +- frontend/src/components/alert/AlertDetail.vue | 2 +- .../src/components/alert/AlertsWrapper.vue | 8 +++++ frontend/src/components/artifact/Artifact.vue | 9 ++++- .../components/artifact/ArtifactDetail.vue | 8 ++--- .../components/artifact/ArtifactsWrapper.vue | 7 ++++ frontend/src/components/artifact/Tags.vue | 35 ------------------- .../src/components/rule/ActionButtons.vue | 7 ++-- frontend/src/components/rule/Rule.vue | 2 +- frontend/src/components/rule/RulesWrapper.vue | 7 ++++ frontend/src/components/tag/Tag.vue | 19 ++++++++-- frontend/src/components/tag/Tags.vue | 7 +++- frontend/src/types.ts | 4 +-- lib/mihari/entities/artifact.rb | 4 +-- 14 files changed, 68 insertions(+), 53 deletions(-) delete mode 100644 frontend/src/components/artifact/Tags.vue diff --git a/frontend/src/components/alert/Alert.vue b/frontend/src/components/alert/Alert.vue index 5e0ae1de6..eff098662 100644 --- a/frontend/src/components/alert/Alert.vue +++ b/frontend/src/components/alert/Alert.vue @@ -31,7 +31,7 @@ Tags - + diff --git a/frontend/src/components/alert/AlertDetail.vue b/frontend/src/components/alert/AlertDetail.vue index d2f67fd40..6e5d5065c 100644 --- a/frontend/src/components/alert/AlertDetail.vue +++ b/frontend/src/components/alert/AlertDetail.vue @@ -29,7 +29,7 @@ Tags - + diff --git a/frontend/src/components/alert/AlertsWrapper.vue b/frontend/src/components/alert/AlertsWrapper.vue index ac91cf0c5..ffbbb82d8 100644 --- a/frontend/src/components/alert/AlertsWrapper.vue +++ b/frontend/src/components/alert/AlertsWrapper.vue @@ -67,6 +67,7 @@ diff --git a/frontend/src/components/rule/ActionButtons.vue b/frontend/src/components/rule/ActionButtons.vue index 621eb0e24..bc1436661 100644 --- a/frontend/src/components/rule/ActionButtons.vue +++ b/frontend/src/components/rule/ActionButtons.vue @@ -7,10 +7,13 @@ Alerts: {{ getAlertsTask.last?.value?.total }} - + Artifacts: {{ getArtifactsTask.last?.value?.total }} - + JSON diff --git a/frontend/src/components/rule/Rule.vue b/frontend/src/components/rule/Rule.vue index 2ddb0a720..d77c4a1b2 100644 --- a/frontend/src/components/rule/Rule.vue +++ b/frontend/src/components/rule/Rule.vue @@ -43,7 +43,7 @@ Tags - + diff --git a/frontend/src/components/rule/RulesWrapper.vue b/frontend/src/components/rule/RulesWrapper.vue index f3882b9ce..3e79294e1 100644 --- a/frontend/src/components/rule/RulesWrapper.vue +++ b/frontend/src/components/rule/RulesWrapper.vue @@ -109,6 +109,13 @@ export default defineComponent({ await getRules() }) + watch(q, async () => { + window.scrollTo({ + top: 0, + behavior: "smooth" + }) + }) + return { getRulesTask, page, diff --git a/frontend/src/components/tag/Tag.vue b/frontend/src/components/tag/Tag.vue index 680769d1e..0431d5af7 100644 --- a/frontend/src/components/tag/Tag.vue +++ b/frontend/src/components/tag/Tag.vue @@ -5,7 +5,11 @@ v-on:mouseover="showDeleteButton" v-on:mouseleave="hideDeleteButton" > - {{ tag.name }} + {{ tag.name }} @@ -15,7 +19,7 @@ import { defineComponent, type PropType, ref } from "vue" import { generateDeleteTagTask } from "@/api-helper" -import type { Tag } from "@/types" +import type { NavigateTo, Tag } from "@/types" export default defineComponent({ name: "TagItem", @@ -27,6 +31,10 @@ export default defineComponent({ deletable: { type: Boolean, default: false + }, + navigateTo: { + type: String as PropType, + required: true } }, setup(props) { @@ -54,12 +62,17 @@ export default defineComponent({ isDeleteButtonEnabled.value = false } + const getQuery = (name: string) => { + return `tag:"${name}"` + } + return { isDeleted, deleteTag, showDeleteButton, hideDeleteButton, - isDeleteButtonEnabled + isDeleteButtonEnabled, + getQuery } } }) diff --git a/frontend/src/components/tag/Tags.vue b/frontend/src/components/tag/Tags.vue index 9c36a9c97..56415b815 100644 --- a/frontend/src/components/tag/Tags.vue +++ b/frontend/src/components/tag/Tags.vue @@ -5,6 +5,7 @@ :tag="tag" :key="tag.name" :deletable="deletable" + :navigate-to="navigateTo" > @@ -13,7 +14,7 @@ import { defineComponent, type PropType } from "vue" import TagComponent from "@/components/tag/Tag.vue" -import type { Tag } from "@/types" +import type { NavigateTo, Tag } from "@/types" export default defineComponent({ name: "TagsItem", @@ -28,6 +29,10 @@ export default defineComponent({ deletable: { type: Boolean, default: false + }, + navigateTo: { + type: String as PropType, + required: true } }, setup() {} diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 801e18f66..57ae509f1 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -91,9 +91,7 @@ export interface Artifact { cpes?: CPE[] ports?: Port[] vulnerabilities?: Vulnerability[] -} -export interface ArtifactWithTags extends Artifact { tags: Tag[] } @@ -187,3 +185,5 @@ export interface ErrorMessage extends Message { export interface QueueMessage extends Message { queued: boolean } + +export type NavigateTo = "Alerts" | "Rules" | "Artifacts" diff --git a/lib/mihari/entities/artifact.rb b/lib/mihari/entities/artifact.rb index d2507eb62..6e8d8c2fb 100644 --- a/lib/mihari/entities/artifact.rb +++ b/lib/mihari/entities/artifact.rb @@ -8,12 +8,12 @@ class BaseArtifact < Grape::Entity expose :data_type, documentation: { type: String, required: true }, as: :dataType expose :source, documentation: { type: String, required: true } expose :query, documentation: { type: String, required: false } - expose :metadata, documentation: { type: Hash } expose :created_at, documentation: { type: DateTime, required: true }, as: :createdAt + expose :tags, using: Entities::Tag, documentation: { type: Entities::Tag, is_array: true, required: true } end class Artifact < BaseArtifact - expose :tags, using: Entities::Tag, documentation: { type: Entities::Tag, is_array: true, required: true } + expose :metadata, documentation: { type: Hash } expose :autonomous_system, using: Entities::AutonomousSystem, documentation: { type: Entities::AutonomousSystem, required: false }, as: :autonomousSystem expose :geolocation, using: Entities::Geolocation, documentation: { type: Entities::Geolocation, required: false } From fbed3f3dedeb202c808043d5bd2651965208c757 Mon Sep 17 00:00:00 2001 From: Manabu Niseki Date: Sun, 14 Jan 2024 10:10:48 +0900 Subject: [PATCH 2/5] fix: remove unused func --- frontend/src/components/alert/AlertsWrapper.vue | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/components/alert/AlertsWrapper.vue b/frontend/src/components/alert/AlertsWrapper.vue index ffbbb82d8..1b16c48fc 100644 --- a/frontend/src/components/alert/AlertsWrapper.vue +++ b/frontend/src/components/alert/AlertsWrapper.vue @@ -67,7 +67,6 @@