Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: implement advanced search for audit logs (#11943)
boojack3f8c037fce2d
diff --git a/backend/api/v1/audit_log_service.go b/backend/api/v1/audit_log_service.goindex fa10f0bd13..9c2147b655 100644--- a/backend/api/v1/audit_log_service.go+++ b/backend/api/v1/audit_log_service.go@@ -247,7 +247,7 @@ func getSearchAuditLogsFilter(filter string) (*store.AuditLogFilter, *status.Sta}}switch variable {- case "resource", "parent", "method", "user":+ case "resource", "parent", "method", "user", "severity":default:return "", errors.Errorf("unknown variable %s", variable)}diff --git a/frontend/src/components/AuditLog/AuditLogSearch/AdvancedSearchBox.vue b/frontend/src/components/AuditLog/AuditLogSearch/AdvancedSearchBox.vuenew file mode 100644index 0000000000..cb202ce591--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/AdvancedSearchBox.vue@@ -0,0 +1,554 @@+<template>+ <div+ ref="containerRef"+ class="bb-advanced-audit-log-search-box w-full relative"+ >+ <NInput+ ref="inputRef"+ v-model:value="inputText"+ :placeholder="placeholder ?? $t('issue.advanced-search.self')"+ class="bb-advanced-audit-log-search-box__input"+ style="--n-padding-left: 8px; --n-padding-right: 4px"+ @click="handleInputClick"+ @blur="hideMenu"+ @keyup="handleKeyUp"+ @keydown="handleKeyDown"+ >+ <template #prefix>+ <div+ class="flex flex-row items-center justify-start gap-x-2"+ :style="{+ 'max-width': `calc(${containerWidth}px - 14rem)`,+ }"+ >+ <div class="flex items-center space-x-2">+ <FilterIcon class="w-4 h-4 text-control-placeholder" />+ <span class="textinfolabel">+ {{ $t("issue.advanced-search.filter") }}+ </span>+ </div>+ <div+ ref="tagsContainerRef"+ class="flex-1 flex flex-row items-center flex-nowrap gap-1 overflow-auto hide-scrollbar"+ >+ <ScopeTags+ :params="params"+ :focused-tag-id="focusedTagId"+ :readonly-scopes="readonlyScopes"+ @select-scope="selectScopeFromTag"+ @remove-scope="removeScope"+ />+ </div>+ </div>+ </template>+ <template #suffix>+ <NButton+ v-show="clearable"+ quaternary+ circle+ size="tiny"+ @click.stop.prevent="handleClear"+ >+ <template #icon>+ <XIcon class="w-3 h-3" />+ </template>+ </NButton>+ </template>+ </NInput>++ <Transition name="fade-slide-up" :appear="true">+ <div+ v-show="showMenu"+ v-zindexable="{ enabled: true }"+ class="absolute top-[36px] w-full bg-gray-100 shadow-xl origin-top-left rounded-[3px] overflow-clip"+ >+ <ScopeMenu+ :show="menuView === 'scope'"+ :params="params"+ :options="visibleScopeOptions"+ :menu-index="menuIndex"+ @select-scope="selectScope"+ @hover-item="menuIndex = $event"+ />+ <ValueMenu+ :show="menuView === 'value'"+ :params="params"+ :scope-option="currentScopeOption"+ :value-options="visibleValueOptions"+ :menu-index="menuIndex"+ @select-value="selectValue"+ @hover-item="menuIndex = $event"+ />+ </div>+ </Transition>+ </div>+</template>++<script lang="ts" setup>+import { useElementSize } from "@vueuse/core";+import { cloneDeep, last } from "lodash-es";+import { FilterIcon } from "lucide-vue-next";+import { XIcon } from "lucide-vue-next";+import { matchSorter } from "match-sorter";+import type { InputInst } from "naive-ui";+import { NInput } from "naive-ui";+import scrollIntoView from "scroll-into-view-if-needed";+import { zindexable as vZindexable } from "vdirs";+import {+ reactive,+ watch,+ onMounted,+ ref,+ toRef,+ computed,+ nextTick,+} from "vue";+import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";+import {+ emptySearchParams,+ getValueFromSearchParams,+ minmax,+ upsertScope,+} from "@/utils";+import ScopeMenu from "./ScopeMenu.vue";+import ScopeTags from "./ScopeTags.vue";+import ValueMenu from "./ValueMenu.vue";+import { useSearchScopeOptions } from "./useSearchScopeOptions";++const props = withDefaults(+ defineProps<{+ placeholder?: string | undefined;+ params: SearchParams;+ readonlyScopes?: SearchScope[];+ autofocus?: boolean;+ supportOptionIdList?: SearchScopeId[];+ }>(),+ {+ readonlyScopes: () => [],+ supportOptionIdList: () => [],+ autofocus: false,+ placeholder: undefined,+ }+);++const emit = defineEmits<{+ (event: "update:params", params: SearchParams): void;+ (event: "select-unsupported-scope", id: SearchScopeId): void;+}>();++interface LocalState {+ searchText: string;+ showSearchScopes: boolean;+ currentScope?: SearchScopeId;+}++const defaultSearchParams = () => {+ const params = emptySearchParams();+ props.readonlyScopes.forEach((s) => {+ params.scopes.push({ ...s });+ });+ return params;+};++const buildSearchTextByParams = (params: SearchParams | undefined): string => {+ const prefix = (params?.scopes ?? [])+ .map((scope) => `${scope.id}:${scope.value}`)+ .join(" ");+ const query = params?.query ?? "";+ if (!prefix && !query) {+ return "";+ }+ return `${prefix} ${query}`;+};++const state = reactive<LocalState>({+ searchText: buildSearchTextByParams(props.params),+ showSearchScopes: props.autofocus,+});+const containerRef = ref<HTMLElement>();+const tagsContainerRef = ref<HTMLElement>();+const inputText = ref(props.params.query);+const inputRef = ref<InputInst>();+const menuIndex = ref(0);+const { width: containerWidth } = useElementSize(containerRef);+const focusedTagId = ref<SearchScopeId>();+const readonlyScopeIds = computed(() => {+ return new Set(props.readonlyScopes.map((s) => s.id));+});+const editableScopes = computed(() => {+ return props.params.scopes.filter((s) => !readonlyScopeIds.value.has(s.id));+});++watch(+ () => state.showSearchScopes,+ (show) => {+ if (show) state.currentScope = undefined;+ }+);++watch(+ () => props.params,+ (params) => {+ state.searchText = buildSearchTextByParams(params);+ }+);++const {+ menuView,+ fullScopeOptions,+ availableScopeOptions,+ currentScope,+ currentScopeOption,+ valueOptions,+} = useSearchScopeOptions(+ toRef(props, "params"),+ toRef(props, "supportOptionIdList")+);++const visibleScopeOptions = computed(() => {+ if (currentScopeOption.value) {+ return [currentScopeOption.value];+ }++ const keyword = inputText.value.trim().replace(/:.*$/, "").toLowerCase();+ if (!keyword) return availableScopeOptions.value;++ const filtered = matchSorter(availableScopeOptions.value, keyword, {+ keys: ["id", "title", "description"],+ });++ return filtered;+});++const visibleValueOptions = computed(() => {+ if (!currentScope.value) return [];+ const scopePrefix = `${currentScope.value}:`;+ const keyword = inputText.value+ .trim()+ .toLowerCase()+ .substring(scopePrefix.length);++ if (!keyword) return valueOptions.value;++ // Apply multiple segments of keyword splitted by whitespace+ const terms = keyword.split(/\s+/g);+ const filtered = terms.reduceRight((options, term) => {+ return matchSorter(options, term, { keys: ["value", "keywords"] });+ }, valueOptions.value);++ const currentValue = getValueFromSearchParams(+ props.params,+ currentScope.value+ );+ const option = valueOptions.value.find((opt) => opt.value === currentValue);+ if (currentValue && option) {+ // If we have current value, put it to the first if it doesn't match the keyword+ const index = filtered.findIndex((opt) => opt.value === currentValue);+ if (index < 0) {+ filtered.unshift(option);+ }+ }+ return filtered;+});++const visibleOptions = computed(() => {+ return menuView.value === "scope"+ ? visibleScopeOptions.value+ : menuView.value === "value"+ ? visibleValueOptions.value+ : ([] as unknown[]);+});++const showMenu = computed(() => {+ if (menuView.value === "scope") {+ return visibleScopeOptions.value.length > 0;+ }+ if (menuView.value === "value") {+ return true;+ }+ return false;+});++const clearable = computed(() => {+ return (+ props.params.query.trim().length > 0 || editableScopes.value.length > 0+ );+});++const hideMenu = () => {+ nextTick(() => {+ menuView.value = undefined;+ currentScope.value = undefined;+ focusedTagId.value = undefined;+ });+};++const moveMenuIndex = (delta: -1 | 1) => {+ const options = visibleOptions.value;+ if (options.length === 0) return;++ const target = minmax(menuIndex.value + delta, 0, options.length - 1);+ menuIndex.value = target;+};++const removeScope = (id: SearchScopeId) => {+ const updated = upsertScope(props.params, {+ id,+ value: "",+ });+ emit("update:params", updated);+};+const selectScope = (+ id: SearchScopeId | undefined,+ value: string | undefined = undefined+) => {+ currentScope.value = id;+ if (id) {+ menuView.value = "value";+ // Fill-in the scope prefix if needed+ if (!inputText.value.startsWith(`${id}:`)) {+ inputText.value = `${id}:${value ?? ""}`;+ }+ scrollScopeTagIntoViewIfNeeded(id);+ } else {+ menuView.value = "scope";+ }+};+const selectValue = (value: string) => {+ const id = currentScope.value;+ if (!id) {+ menuView.value = undefined;+ return;+ }+ const updated = upsertScope(props.params, {+ id,+ value,+ });+ updated.query = "";+ inputText.value = "";+ selectScope(undefined);+ emit("update:params", updated);++ scrollScopeTagIntoViewIfNeeded(id);+ hideMenu();+};+const selectScopeFromTag = (id: SearchScopeId) => {+ if (fullScopeOptions.value.find((opt) => opt.id === id)) {+ // For AdvancedSearchBox supported scopes+ selectScope(id);+ return;+ }++ // Unsupported scope for AdvancedSearchBox+ // emit an event and wish the parent UI can handle this+ emit("select-unsupported-scope", id);+ hideMenu();+};++const maybeSelectMatchedScope = () => {+ if (!menuView.value || menuView.value === "scope") {+ const matchedScope = visibleScopeOptions.value.find((opt) =>+ inputText.value.startsWith(`${opt.id}:`)+ );+ if (matchedScope) {+ // select the scope if the inputText matches its prefix+ selectScope(matchedScope.id);+ return true;+ }+ if (!menuView.value) {+ // Show scope menu if none of the menus are shown+ menuView.value = "scope";+ return true;+ }+ }+ return false;+};+const maybeDeselectMismatchedScope = () => {+ if (menuView.value === "value" && currentScope.value) {+ if (!inputText.value.startsWith(`${currentScope.value}:`)) {+ // de-select current scope since the inputText doesn't match its prefix.+ menuView.value = "scope";+ selectScope(undefined);+ return true;+ }+ }+ return false;+};++const maybeEmitIncompleteValue = () => {+ const updated = cloneDeep(props.params);+ updated.query = inputText.value;+ emit("update:params", updated);+};++const handleInputClick = () => {+ maybeSelectMatchedScope();+ maybeDeselectMismatchedScope();+ maybeEmitIncompleteValue();+};++const handleKeyDown = (e: KeyboardEvent) => {+ if (e.isComposing) return;+ if (e.defaultPrevented) return;+ const { key } = e;+ if (key === "Backspace" && inputText.value === "") {+ // Pressing "backspace" when the input box is empty+ if (focusedTagId.value) {+ e.stopPropagation();+ e.preventDefault();+ // Delete the focusedTag if it exists+ const id = focusedTagId.value;+ focusedTagId.value = undefined;+ removeScope(id);+ return;+ } else {+ e.stopPropagation();+ e.preventDefault();+ // Otherwise mark the last tag as 'focusedTag'+ const id = last(props.params.scopes)?.id;+ if (id) {+ focusedTagId.value = id;+ scrollScopeTagIntoViewIfNeeded(id);+ }+ return;+ }+ }+ focusedTagId.value = undefined;++ if (key === "ArrowUp") {+ moveMenuIndex(-1);+ e.preventDefault();+ return;+ }+ if (key === "ArrowDown") {+ moveMenuIndex(1);+ e.preventDefault();+ return;+ }+};++const handleKeyUp = (e: KeyboardEvent) => {+ if (e.isComposing) return;+ if (e.defaultPrevented) return;+ const { key } = e;+ if (key === "Escape") {+ maybeEmitIncompleteValue();+ menuView.value = undefined;+ return;+ }+ if (key === "Backspace" && inputText.value === "") {+ // backspace key might be processed by KeyDown+ if (focusedTagId.value) {+ return;+ }+ }+ if (maybeSelectMatchedScope()) {+ maybeEmitIncompleteValue();+ return;+ }+ if (maybeDeselectMismatchedScope()) {+ maybeEmitIncompleteValue();+ return;+ }+ if (key === "Enter") {+ // Press enter to select scope (dive into the next step)+ // or select value+ const index = menuIndex.value;+ if (menuView.value === "scope") {+ const option = visibleScopeOptions.value[index];+ if (option) {+ selectScope(option.id);+ maybeEmitIncompleteValue();+ return;+ }+ }+ if (menuView.value === "value") {+ const option = visibleValueOptions.value[index];+ if (option) {+ selectValue(option.value);+ return;+ }+ }+ }++ maybeEmitIncompleteValue();+};++const handleClear = () => {+ const params = defaultSearchParams();+ emit("update:params", params);+ hideMenu();+};++const scrollScopeTagIntoViewIfNeeded = (id: SearchScopeId) => {+ nextTick(() => {+ const tagsContainerEl = tagsContainerRef.value;+ if (!tagsContainerEl) return;+ const tagEl = tagsContainerEl.querySelector(+ `[data-search-scope-id="${id}"]`+ );+ if (tagEl) {+ scrollIntoView(tagEl, {+ scrollMode: "if-needed",+ });+ }+ });+};++onMounted(() => {+ if (props.autofocus) {+ inputRef.value?.inputElRef?.focus();+ }+});+watch(menuView, () => {+ focusedTagId.value = undefined;+ menuIndex.value = 0;+ if (menuView.value === "value" && currentScope.value) {+ const value = getValueFromSearchParams(props.params, currentScope.value);+ if (value) {+ const index = valueOptions.value.findIndex(+ (option) => option.value === value+ );+ if (index >= 0) menuIndex.value = index;+ }+ }+});+watch(visibleScopeOptions, (newOptions, oldOptions) => {+ if (menuView.value !== "scope") return;+ const highlightedScope = oldOptions[menuIndex.value]?.id;+ if (highlightedScope) {+ const index = newOptions.findIndex((opt) => opt.id === highlightedScope);+ if (index >= 0) {+ menuIndex.value = index;+ return;+ }+ }+ menuIndex.value = minmax(menuIndex.value, 0, newOptions.length - 1);+});+watch(visibleValueOptions, (newOptions, oldOptions) => {+ if (menuView.value !== "value") return;+ const highlightedValue = oldOptions[menuIndex.value]?.value;+ if (highlightedValue) {+ const index = newOptions.findIndex((opt) => opt.value === highlightedValue);+ if (index >= 0) {+ menuIndex.value = index;+ return;+ }+ }+ menuIndex.value = minmax(menuIndex.value, 0, newOptions.length - 1);+});+watch(+ () => props.params,+ (params) => {+ inputText.value = params.query;+ }+);+</script>++<style lang="postcss" scoped>+.bb-advanced-audit-log-search-box+ .bb-advanced-audit-log-search-box__input+ :deep(.n-input__input) {+ @apply flex flex-row items-center;+}+</style>diff --git a/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vuenew file mode 100644index 0000000000..1d76179151--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/AuditLogSearch.vue@@ -0,0 +1,46 @@+<template>+ <div class="flex flex-row items-center gap-x-2">+ <AdvancedSearchBox+ :params="params"+ :autofocus="autofocus"+ :readonly-scopes="readonlyScopes"+ :support-option-id-list="supportOptionIdList"+ class="flex-1"+ @update:params="$emit('update:params', $event)"+ />+ <TimeRange+ v-model:show="showTimeRange"+ :params="params"+ @update:params="$emit('update:params', $event)"+ />+ <slot name="searchbox-suffix" />+ </div>+</template>++<script lang="ts" setup>+import { ref, computed } from "vue";+import type { SearchParams, SearchScope } from "@/utils";+import { SearchScopeIdList } from "@/utils";+import AdvancedSearchBox from "./AdvancedSearchBox.vue";+import TimeRange from "./TimeRange.vue";++withDefaults(+ defineProps<{+ params: SearchParams;+ readonlyScopes?: SearchScope[];+ autofocus?: boolean;+ }>(),+ {+ readonlyScopes: () => [],+ components: () => ["searchbox", "time-range"],+ componentProps: undefined,+ }+);+defineEmits<{+ (event: "update:params", params: SearchParams): void;+}>();++const showTimeRange = ref(false);++const supportOptionIdList = computed(() => [...SearchScopeIdList]);+</script>diff --git a/frontend/src/components/AuditLog/AuditLogSearch/ScopeMenu.vue b/frontend/src/components/AuditLog/AuditLogSearch/ScopeMenu.vuenew file mode 100644index 0000000000..811294bbff--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/ScopeMenu.vue@@ -0,0 +1,100 @@+<template>+ <div+ v-if="options.length > 0"+ v-show="show"+ class="overflow-hidden"+ :style="{+ 'max-height': `${maxListHeight}px`,+ }"+ >+ <VirtualList+ ref="virtualListRef"+ :items="options"+ :key-field="`id`"+ :item-resizable="false"+ :item-size="38"+ >+ <template #default="{ item: option, index }: ListItem">+ <div+ class="h-[38px] flex gap-x-1 px-3 items-center cursor-pointer border-t text-sm"+ :class="[+ index === menuIndex && 'bg-gray-200/75',+ index === 0 ? 'border-transparent' : 'border-block-border',+ ]"+ :data-index="index"+ :data-id="option.id"+ @mouseenter.prevent.stop="$emit('hover-item', index)"+ @mousedown.prevent.stop="$emit('select-scope', option.id)"+ >+ <span class="text-accent">{{ option.id }}:</span>+ <span class="text-control-light">{{ option.description }}</span>+ </div>+ </template>+ </VirtualList>+ </div>+</template>++<script setup lang="ts">+import { useElementBounding, useWindowSize } from "@vueuse/core";+import { computed, nextTick, ref, watch } from "vue";+import { VirtualList } from "vueuc";+import type { SearchParams, SearchScopeId } from "@/utils";+import type { ScopeOption } from "./useSearchScopeOptions";++type ListItem = {+ item: ScopeOption;+ index: number;+};++const props = defineProps<{+ show: boolean;+ params: SearchParams;+ options: ScopeOption[];+ menuIndex: number;+}>();+defineEmits<{+ (event: "select-scope", id: SearchScopeId): void;+ (event: "hover-item", index: number): void;+}>();++const containerRef = ref<HTMLElement>();+const virtualListRef = ref<InstanceType<typeof VirtualList>>();+const { top: containerTop } = useElementBounding(containerRef);+const { height: windowHeight } = useWindowSize();++const maxListHeight = computed(() => {+ const MAX_HEIGHT = 480;+ const PADDING_BOTTOM = 16;++ return Math.min(+ MAX_HEIGHT,+ windowHeight.value - containerTop.value - PADDING_BOTTOM+ );+});++const highlightedItem = computed((): ListItem | undefined => {+ if (!props.show) return undefined;+ const { options, menuIndex: index } = props;+ const item = options[index];+ if (item) {+ return { item, index };+ }+ return undefined;+});++watch(+ [highlightedItem, () => props.show],+ ([item, show]) => {+ if (!show) return;+ if (!item) return;+ nextTick(() => {+ const virtualList = virtualListRef.value;+ if (!virtualList) return;+ virtualList.scrollTo({+ index: item.index,+ });+ });+ },+ { immediate: true }+);+</script>diff --git a/frontend/src/components/AuditLog/AuditLogSearch/ScopeTags.vue b/frontend/src/components/AuditLog/AuditLogSearch/ScopeTags.vuenew file mode 100644index 0000000000..c48fc3e2a0--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/ScopeTags.vue@@ -0,0 +1,73 @@+<template>+ <NTag+ v-for="(scope, i) in params.scopes"+ :key="scope.id"+ :closable="!isReadonlyScope(scope)"+ :disabled="isReadonlyScope(scope)"+ :data-search-scope-id="scope.id"+ :bordered="false"+ size="small"+ style="--n-icon-size: 12px"+ v-bind="tagProps(scope)"+ @close="$emit('remove-scope', scope.id, scope.value)"+ @click.stop.prevent="$emit('select-scope', scope.id, scope.value)"+ >+ <span>{{ scope.id }}</span>+ <span>:</span>+ <component :is="() => renderValue(scope, i)" />+ </NTag>+</template>+<script setup lang="ts">+import dayjs from "dayjs";+import type { TagProps } from "naive-ui";+import { NTag } from "naive-ui";+import { computed, h } from "vue";+import { useI18n } from "vue-i18n";+import { UNKNOWN_ID } from "@/types";+import type { SearchParams, SearchScope, SearchScopeId } from "@/utils";+import { callCssVariable } from "@/utils";++const props = defineProps<{+ params: SearchParams;+ focusedTagId?: SearchScopeId;+ readonlyScopes?: SearchScope[];+}>();++defineEmits<{+ (event: "remove-scope", id: SearchScopeId, value: string): void;+ (event: "select-scope", id: SearchScopeId, value: string): void;+}>();++const { t } = useI18n();++const readonlyScopeIds = computed(() => {+ return new Set((props.readonlyScopes ?? []).map((s) => s.id));+});++const isReadonlyScope = (scope: SearchScope) => {+ return readonlyScopeIds.value.has(scope.id);+};++const tagProps = (scope: SearchScope): TagProps => {+ if (props.focusedTagId !== scope.id) {+ return {};+ }+ return {+ bordered: true,+ color: {+ borderColor: callCssVariable("--color-accent"),+ },+ };+};++const renderValue = (scope: SearchScope, index: number) => {+ if (scope.id === "created") {+ const [begin, end] = scope.value.split(",").map((ts) => parseInt(ts, 10));+ return [dayjs(begin).format("L"), dayjs(end).format("L")].join("-");+ }+ if (scope.value === `${UNKNOWN_ID}`) {+ return h("span", {}, t("common.all").toLocaleLowerCase());+ }+ return h("span", {}, scope.value);+};+</script>diff --git a/frontend/src/components/AuditLog/AuditLogSearch/TimeRange.vue b/frontend/src/components/AuditLog/AuditLogSearch/TimeRange.vuenew file mode 100644index 0000000000..9679362670--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/TimeRange.vue@@ -0,0 +1,56 @@+<template>+ <NDatePicker+ :key="timeRange ? 'filled' : 'empty'"+ :value="timeRange"+ :is-date-disabled="isDateDisabled"+ type="daterange"+ clearable+ style="width: 14rem"+ class="time-range-picker"+ @update:value="handleUpdate"+ >+ </NDatePicker>+</template>++<script setup lang="ts">+import dayjs from "dayjs";+import { NDatePicker } from "naive-ui";+import { computed } from "vue";+import type { SearchParams } from "@/utils";+import { getTsRangeFromSearchParams, upsertScope } from "@/utils";++const props = defineProps<{+ params: SearchParams;+}>();++const emit = defineEmits<{+ (event: "update:params", params: SearchParams): void;+}>();++const timeRange = computed(() => {+ return getTsRangeFromSearchParams(props.params, "created");+});++const isDateDisabled = (ts: number) => {+ const today = dayjs().add(1, "day").endOf("day").valueOf();+ if (ts > today) {+ return true;+ }+ return false;+};++const handleUpdate = (values: [number, number] | null) => {+ const updated = upsertScope(props.params, {+ id: "created",+ value: values ? values.join(",") : "",+ });+ emit("update:params", updated);+};+</script>++<style lang="postcss" scoped>+.time-range-picker :deep(.n-input) {+ --n-padding-left: 6px !important;+ --n-padding-right: 6px !important;+}+</style>diff --git a/frontend/src/components/AuditLog/AuditLogSearch/ValueMenu.vue b/frontend/src/components/AuditLog/AuditLogSearch/ValueMenu.vuenew file mode 100644index 0000000000..94b83c32ec--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/ValueMenu.vue@@ -0,0 +1,128 @@+<template>+ <div+ v-if="scopeOption"+ v-show="show"+ ref="containerRef"+ class="flex flex-col overflow-hidden"+ :data-top="containerTop"+ >+ <div+ v-if="scopeOption.title"+ ref="titleRef"+ class="px-3 py-2 text-sm text-control font-semibold"+ :data-height="titleHeight"+ >+ {{ scopeOption.title }}+ </div>+ <div+ v-if="valueOptions.length > 0"+ class="flex-1 overflow-hidden"+ :style="{+ 'max-height': `${maxListHeight}px`,+ }"+ >+ <VirtualList+ ref="virtualListRef"+ :items="valueOptions"+ :key-field="`value`"+ :item-resizable="false"+ :item-size="38"+ >+ <template #default="{ item: option, index }: ListItem">+ <div+ class="h-[38px] flex gap-x-2 px-3 items-center cursor-pointer border-t border-block-border overflow-hidden"+ :class="[index === menuIndex && 'bg-gray-200/75']"+ :data-index="index"+ :data-value="option.value"+ @mouseenter.prevent.stop="$emit('hover-item', index)"+ @mousedown.prevent.stop="$emit('select-value', option.value)"+ >+ <component :is="option.render" class="text-control text-sm" />+ <span v-if="!option.custom" class="text-control-light text-sm">+ {{ option.value }}+ </span>+ </div>+ </template>+ </VirtualList>+ </div>+ <div v-if="valueOptions.length === 0" class="pb-2">+ <NEmpty />+ </div>+ </div>+</template>++<script setup lang="ts">+import {+ useElementBounding,+ useElementSize,+ useWindowSize,+} from "@vueuse/core";+import { NEmpty } from "naive-ui";+import { computed, nextTick, ref, watch } from "vue";+import { VirtualList } from "vueuc";+import type { SearchParams } from "@/utils";+import type { ScopeOption, ValueOption } from "./useSearchScopeOptions";++type ListItem = {+ item: ValueOption;+ index: number;+};++const props = defineProps<{+ show: boolean;+ params: SearchParams;+ scopeOption?: ScopeOption;+ valueOptions: ValueOption[];+ menuIndex: number;+}>();+defineEmits<{+ (event: "select-value", value: string): void;+ (event: "hover-item", index: number): void;+}>();++const containerRef = ref<HTMLElement>();+const titleRef = ref<HTMLElement>();+const virtualListRef = ref<InstanceType<typeof VirtualList>>();+const { height: titleHeight } = useElementSize(titleRef, undefined, {+ box: "border-box",+});+const { top: containerTop } = useElementBounding(containerRef);+const { height: windowHeight } = useWindowSize();++const maxListHeight = computed(() => {+ const MAX_HEIGHT = 240;+ const PADDING_BOTTOM = 16;++ return Math.min(+ MAX_HEIGHT,+ windowHeight.value - titleHeight.value - containerTop.value - PADDING_BOTTOM+ );+});++const highlightedItem = computed((): ListItem | undefined => {+ if (!props.show) return undefined;+ const options = props.valueOptions;+ const index = props.menuIndex;+ const item = options[index];+ if (item) {+ return { item, index };+ }+ return undefined;+});++watch(+ [highlightedItem, () => props.show],+ ([item, show]) => {+ if (!show) return;+ if (!item) return;+ nextTick(() => {+ const virtualList = virtualListRef.value;+ if (!virtualList) return;+ virtualList.scrollTo({+ index: item.index,+ });+ });+ },+ { immediate: true }+);+</script>diff --git a/frontend/src/components/AuditLog/AuditLogSearch/index.ts b/frontend/src/components/AuditLog/AuditLogSearch/index.tsnew file mode 100644index 0000000000..7eeca1ff27--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/index.ts@@ -0,0 +1,5 @@+import AdvancedSearchBox from "./AdvancedSearchBox.vue";+import AuditLogSearch from "./AuditLogSearch.vue";++export default AuditLogSearch;+export { AuditLogSearch, AdvancedSearchBox };diff --git a/frontend/src/components/AuditLog/AuditLogSearch/useSearchScopeOptions.ts b/frontend/src/components/AuditLog/AuditLogSearch/useSearchScopeOptions.tsnew file mode 100644index 0000000000..c87350a9ea--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/useSearchScopeOptions.ts@@ -0,0 +1,192 @@+import { orderBy } from "lodash-es";+import type { Ref, RenderFunction, VNode } from "vue";+import { computed, h, ref } from "vue";+import { useI18n } from "vue-i18n";+import BBAvatar from "@/bbkit/BBAvatar.vue";+import GitIcon from "@/components/GitIcon.vue";+import SystemBotTag from "@/components/misc/SystemBotTag.vue";+import YouTag from "@/components/misc/YouTag.vue";+import { ProjectV1Name } from "@/components/v2";+import ALL_METHODS from "@/grpcweb/methods";+import { useCurrentUserV1, useUserStore, useProjectV1List } from "@/store";+import { SYSTEM_BOT_EMAIL } from "@/types";+import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";+import { Workflow } from "@/types/proto/v1/project_service";+import type { SearchParams, SearchScopeId } from "@/utils";+import { extractProjectResourceName } from "@/utils";++export type ScopeOption = {+ id: SearchScopeId;+ title: string;+ description: string;+ options: ValueOption[];+};++export type ValueOption = {+ value: string;+ keywords: string[];+ custom?: boolean;+ render: RenderFunction;+};++export const useSearchScopeOptions = (+ params: Ref<SearchParams>,+ supportOptionIdList: Ref<SearchScopeId[]>+) => {+ const { t } = useI18n();+ const me = useCurrentUserV1();+ const userStore = useUserStore();+ const { projectList } = useProjectV1List();++ const principalSearchValueOptions = computed(() => {+ // Put "you" to the top+ const sortedUsers = orderBy(+ userStore.activeUserList,+ (user) => (user.name === me.value.name ? -1 : 1),+ "asc"+ );+ return sortedUsers.map<ValueOption>((user) => {+ return {+ value: user.email,+ keywords: [user.email, user.title],+ render: () => {+ const children = [+ h(BBAvatar, { size: "TINY", username: user.title }),+ renderSpan(user.title),+ ];+ if (user.name === me.value.name) {+ children.push(h(YouTag));+ }+ if (user.email === SYSTEM_BOT_EMAIL) {+ children.push(h(SystemBotTag));+ }+ return h("div", { class: "flex items-center gap-x-1" }, children);+ },+ };+ });+ });++ // fullScopeOptions provides full search scopes and options.+ // we need this as the source of truth.+ const fullScopeOptions = computed((): ScopeOption[] => {+ const scopes: ScopeOption[] = [+ {+ id: "project",+ title: t("issue.advanced-search.scope.project.title"),+ description: t("issue.advanced-search.scope.project.description"),+ options: projectList.value.map<ValueOption>((proj) => {+ const name = extractProjectResourceName(proj.name);+ return {+ value: name,+ keywords: [name, proj.title, proj.key],+ render: () => {+ const children: VNode[] = [+ h(ProjectV1Name, { project: proj, link: false }),+ ];+ if (proj.workflow === Workflow.VCS) {+ children.push(h(GitIcon, { class: "h-4" }));+ }+ return h("div", { class: "flex items-center gap-x-2" }, children);+ },+ };+ }),+ },+ {+ id: "actor",+ title: t("audit-log.advanced-search.scope.actor.title"),+ description: t("audit-log.advanced-search.scope.actor.description"),+ options: principalSearchValueOptions.value,+ },+ {+ id: "method",+ title: t("audit-log.advanced-search.scope.method.title"),+ description: t("audit-log.advanced-search.scope.method.description"),+ options: ALL_METHODS.map((method) => {+ return {+ value: method,+ keywords: [method],+ render: () => "",+ };+ }),+ },+ {+ id: "level",+ title: t("audit-log.advanced-search.scope.level.title"),+ description: t("audit-log.advanced-search.scope.level.description"),+ options: Object.values(AuditLog_Severity).map((severity) => {+ return {+ value: severity,+ keywords: [severity],+ render: () => "",+ };+ }),+ },+ ];+ const supportOptionIdSet = new Set(supportOptionIdList.value);+ return scopes.filter((scope) => supportOptionIdSet.has(scope.id));+ });++ // filteredScopeOptions will filter search options by chosen scope.+ // For example, if users select a specific project, we should only allow them select instances related with this project.+ const filteredScopeOptions = computed((): ScopeOption[] => {+ const clone = fullScopeOptions.value.map((scope) => ({+ ...scope,+ options: scope.options.map((option) => ({+ ...option,+ })),+ }));++ return clone;+ });++ // availableScopeOptions will hide chosen search scope.+ // For example, if uses already select the instance, we should NOT show the instance scope in the dropdown.+ const availableScopeOptions = computed((): ScopeOption[] => {+ const existedScopes = new Set<SearchScopeId>(+ params.value.scopes.map((scope) => scope.id)+ );++ return filteredScopeOptions.value.filter((scope) => {+ if (existedScopes.has(scope.id)) {+ return false;+ }+ return true;+ });+ });++ const menuView = ref<"scope" | "value">();+ const currentScope = ref<SearchScopeId>();+ const currentScopeOption = computed(() => {+ if (currentScope.value) {+ return filteredScopeOptions.value.find(+ (opt) => opt.id === currentScope.value+ );+ }+ return undefined;+ });+ const scopeOptions = computed(() => {+ if (menuView.value === "scope") return availableScopeOptions.value;+ return [];+ });+ const valueOptions = computed(() => {+ if (menuView.value === "value" && currentScopeOption.value) {+ return currentScopeOption.value.options;+ }+ return [];+ });++ return {+ fullScopeOptions,+ filteredScopeOptions,+ availableScopeOptions,+ menuView,+ currentScope,+ currentScopeOption,+ scopeOptions,+ valueOptions,+ };+};++const renderSpan = (content: string) => {+ return h("span", {}, content);+};diff --git a/frontend/src/components/AuditLog/AuditLogSearch/utils.ts b/frontend/src/components/AuditLog/AuditLogSearch/utils.tsnew file mode 100644index 0000000000..a701216b10--- /dev/null+++ b/frontend/src/components/AuditLog/AuditLogSearch/utils.ts@@ -0,0 +1,35 @@+import { projectNamePrefix } from "@/store/modules/v1/common";+import type { SearchAuditLogsParams } from "@/types";+import { AuditLog_Severity } from "@/types/proto/v1/audit_log_service";+import { getTsRangeFromSearchParams, type SearchParams } from "@/utils";++export const buildSearchAuditLogParams = (+ searchParams: SearchParams+): SearchAuditLogsParams => {+ const { scopes } = searchParams;+ const projectScope = scopes.find((s) => s.id === "project");+ const levelScope = scopes.find((s) => s.id === "level");+ const methodScope = scopes.find((s) => s.id === "method");+ const actorScope = scopes.find((s) => s.id === "actor");+ const createdTsRange = getTsRangeFromSearchParams(searchParams, "created");++ const params: SearchAuditLogsParams = {};+ if (projectScope) {+ params.parent = `${projectNamePrefix}${projectScope.value}`;+ }+ if (levelScope) {+ params.level =+ AuditLog_Severity[levelScope.value as keyof typeof AuditLog_Severity];+ }+ if (methodScope) {+ params.method = methodScope.value;+ }+ if (actorScope) {+ params.userEmail = actorScope.value;+ }+ if (createdTsRange) {+ params.createdTsAfter = createdTsRange[0];+ params.createdTsBefore = createdTsRange[1];+ }+ return params;+};diff --git a/frontend/src/grpcweb/methods.ts b/frontend/src/grpcweb/methods.tsnew file mode 100644index 0000000000..987a49aa19--- /dev/null+++ b/frontend/src/grpcweb/methods.ts@@ -0,0 +1,64 @@+import { ActuatorServiceDefinition } from "@/types/proto/v1/actuator_service";+import { AnomalyServiceDefinition } from "@/types/proto/v1/anomaly_service";+import { AuditLogServiceDefinition } from "@/types/proto/v1/audit_log_service";+import { AuthServiceDefinition } from "@/types/proto/v1/auth_service";+import { BranchServiceDefinition } from "@/types/proto/v1/branch_service";+import { CelServiceDefinition } from "@/types/proto/v1/cel_service";+import { ChangelistServiceDefinition } from "@/types/proto/v1/changelist_service";+import { DatabaseServiceDefinition } from "@/types/proto/v1/database_service";+import { EnvironmentServiceDefinition } from "@/types/proto/v1/environment_service";+import { IdentityProviderServiceDefinition } from "@/types/proto/v1/idp_service";+import { InstanceRoleServiceDefinition } from "@/types/proto/v1/instance_role_service";+import { InstanceServiceDefinition } from "@/types/proto/v1/instance_service";+import { IssueServiceDefinition } from "@/types/proto/v1/issue_service";+import { OrgPolicyServiceDefinition } from "@/types/proto/v1/org_policy_service";+import { ProjectServiceDefinition } from "@/types/proto/v1/project_service";+import { RiskServiceDefinition } from "@/types/proto/v1/risk_service";+import { RoleServiceDefinition } from "@/types/proto/v1/role_service";+import { RolloutServiceDefinition } from "@/types/proto/v1/rollout_service";+import { SettingServiceDefinition } from "@/types/proto/v1/setting_service";+import { SheetServiceDefinition } from "@/types/proto/v1/sheet_service";+import { SQLServiceDefinition } from "@/types/proto/v1/sql_service";+import { SubscriptionServiceDefinition } from "@/types/proto/v1/subscription_service";+import { VCSConnectorServiceDefinition } from "@/types/proto/v1/vcs_connector_service";+import { VCSProviderServiceDefinition } from "@/types/proto/v1/vcs_provider_service";+import { WorksheetServiceDefinition } from "@/types/proto/v1/worksheet_service";++const ALL_METHODS = [+ ActuatorServiceDefinition,+ AnomalyServiceDefinition,+ AuditLogServiceDefinition,+ AuthServiceDefinition,+ BranchServiceDefinition,+ CelServiceDefinition,+ ChangelistServiceDefinition,+ DatabaseServiceDefinition,+ EnvironmentServiceDefinition,+ IdentityProviderServiceDefinition,+ InstanceRoleServiceDefinition,+ InstanceServiceDefinition,+ IssueServiceDefinition,+ OrgPolicyServiceDefinition,+ ProjectServiceDefinition,+ RiskServiceDefinition,+ RoleServiceDefinition,+ RolloutServiceDefinition,+ SettingServiceDefinition,+ SheetServiceDefinition,+ SQLServiceDefinition,+ SubscriptionServiceDefinition,+ VCSConnectorServiceDefinition,+ VCSProviderServiceDefinition,+ WorksheetServiceDefinition,+]+ .map((serviceDefinition) => {+ const methods: string[] = [];+ for (const method of Object.values(serviceDefinition.methods)) {+ const fullName = serviceDefinition.fullName;+ methods.push(`/${fullName}/${method.name}`);+ }+ return methods;+ })+ .flat();++export default ALL_METHODS;diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex e480f93698..1d0412d5fb 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -2793,6 +2793,22 @@},"sql-editor-query": "SQL Editor Query","sql-export": "SQL Export"+ },+ "advanced-search": {+ "scope": {+ "actor": {+ "title": "Actor",+ "description": "Search by the audit log actor"+ },+ "method": {+ "title": "Method",+ "description": "Search by the method of audit log"+ },+ "level": {+ "title": "Level",+ "description": "Search by the level of audit log"+ }+ }}},"onboarding-guide": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex bcfc0e4818..3f0c216111 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -2793,6 +2793,22 @@},"sql-editor-query": "Consulta del editor de SQL","sql-export": "Exportar SQL"+ },+ "advanced-search": {+ "scope": {+ "actor": {+ "title": "Actor",+ "description": "Búsqueda por actor del registro de auditoría"+ },+ "method": {+ "title": "Método",+ "description": "Buscar por el método de registro de auditoría"+ },+ "level": {+ "title": "Nivel",+ "description": "Buscar por nivel de registro de auditoría"+ }+ }}},"onboarding-guide": {diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 6b83675347..f66134f2fc 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -2793,6 +2793,22 @@},"sql-editor-query": "SQLエディタのクエリ","sql-export": "SQL エクスポート"+ },+ "advanced-search": {+ "scope": {+ "actor": {+ "title": "俳優",+ "description": "監査ログアクターによる検索"+ },+ "method": {+ "title": "方法",+ "description": "監査ログの方法での検索"+ },+ "level": {+ "title": "レベル",+ "description": "監査ログのレベルによる検索"+ }+ }}},"onboarding-guide": {diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 069d14361e..8a7364f18a 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -2793,6 +2793,22 @@},"sql-editor-query": "Truy vấn trình soạn thảo SQL","sql-export": "Xuất SQL"+ },+ "advanced-search": {+ "scope": {+ "actor": {+ "title": "Diễn viên",+ "description": "Tìm kiếm theo tác nhân nhật ký kiểm tra"+ },+ "method": {+ "title": "Phương pháp",+ "description": "Tìm kiếm theo phương pháp nhật ký kiểm tra"+ },+ "level": {+ "title": "Mức độ",+ "description": "Tìm kiếm theo cấp độ của nhật ký kiểm tra"+ }+ }}},"onboarding-guide": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 841cac9df6..656ae49d5e 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -2793,6 +2793,22 @@},"sql-editor-query": "SQL 编辑器查询","sql-export": "SQL 导出"+ },+ "advanced-search": {+ "scope": {+ "actor": {+ "title": "操作者",+ "description": "按审计日志操作者搜索"+ },+ "method": {+ "title": "操作",+ "description": "按审计日志操作搜索"+ },+ "level": {+ "title": "事件等级",+ "description": "按审计日志事件等级搜索"+ }+ }}},"onboarding-guide": {diff --git a/frontend/src/store/modules/v1/auditLog.ts b/frontend/src/store/modules/v1/auditLog.tsindex 8c159b822a..046bab978b 100644--- a/frontend/src/store/modules/v1/auditLog.ts+++ b/frontend/src/store/modules/v1/auditLog.ts@@ -15,8 +15,24 @@ const buildFilter = (search: SearchAuditLogsParams): string => {if (search.parent) {filter.push(`parent == "${search.parent}"`);}- if (search.creatorEmail) {- filter.push(`user == "${userNamePrefix}${search.creatorEmail}"`);+ if (search.method) {+ filter.push(`method == "${search.method}"`);+ }+ if (search.level) {+ filter.push(`severity == "${search.level}"`);+ }+ if (search.userEmail) {+ filter.push(`user == "${userNamePrefix}${search.userEmail}"`);+ }+ if (search.createdTsAfter) {+ filter.push(+ `create_time >= "${dayjs(search.createdTsAfter).utc().format()}"`+ );+ }+ if (search.createdTsBefore) {+ filter.push(+ `create_time <= "${dayjs(search.createdTsBefore).utc().format()}"`+ );}return filter.join(" && ");};diff --git a/frontend/src/types/auditLog.ts b/frontend/src/types/auditLog.tsindex cfb018cada..f494a74671 100644--- a/frontend/src/types/auditLog.ts+++ b/frontend/src/types/auditLog.ts@@ -1,54 +1,12 @@-import { LogEntity_Action } from "@/types/proto/v1/logging_service";--export const AuditActivityTypeList = [- // Workspace level.- //- // Member related- LogEntity_Action.ACTION_MEMBER_CREATE,- LogEntity_Action.ACTION_MEMBER_ROLE_UPDATE,- LogEntity_Action.ACTION_MEMBER_ACTIVATE,- LogEntity_Action.ACTION_MEMBER_DEACTIVE,- // Project level.- //- // Project related- LogEntity_Action.ACTION_PROJECT_DATABASE_TRANSFER,- // SQL Editor related.- LogEntity_Action.ACTION_DATABASE_SQL_EDITOR_QUERY,- LogEntity_Action.ACTION_DATABASE_SQL_EXPORT,-];--export const AuditActivityTypeI18nNameMap: Map<LogEntity_Action, string> =- new Map([- [- LogEntity_Action.ACTION_MEMBER_CREATE,- "audit-log.type.workspace.member-create",- ],- [- LogEntity_Action.ACTION_MEMBER_ROLE_UPDATE,- "audit-log.type.workspace.member-role-update",- ],- [- LogEntity_Action.ACTION_MEMBER_ACTIVATE,- "audit-log.type.workspace.member-activate",- ],- [- LogEntity_Action.ACTION_MEMBER_DEACTIVE,- "audit-log.type.workspace.member-deactivate",- ],- [- LogEntity_Action.ACTION_PROJECT_DATABASE_TRANSFER,- "audit-log.type.project.database-transfer",- ],- [- LogEntity_Action.ACTION_DATABASE_SQL_EDITOR_QUERY,- "audit-log.type.sql-editor-query",- ],- [LogEntity_Action.ACTION_DATABASE_SQL_EXPORT, "audit-log.type.sql-export"],- ]);+import { AuditLog_Severity } from "./proto/v1/audit_log_service";export interface SearchAuditLogsParams {parent?: string;- creatorEmail?: string;+ method?: string;+ level?: AuditLog_Severity;+ userEmail?: string;+ createdTsAfter?: number;+ createdTsBefore?: number;order?: "asc" | "desc";pageSize?: number;pageToken?: string;diff --git a/frontend/src/utils/v1/advanced-search/common.ts b/frontend/src/utils/v1/advanced-search/common.tsindex da94967138..3c2ec3ec4d 100644--- a/frontend/src/utils/v1/advanced-search/common.ts+++ b/frontend/src/utils/v1/advanced-search/common.ts@@ -27,6 +27,10 @@ export const SearchScopeIdList = ["assignee","subscriber","label",+ // auditLog related search scopes.+ "method",+ "level",+ "actor",] as const;export type SearchScopeId =diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vueindex 2deccb4eb1..f2b08705eb 100644--- a/frontend/src/views/SettingWorkspaceAuditLog.vue+++ b/frontend/src/views/SettingWorkspaceAuditLog.vue@@ -1,17 +1,8 @@<template><div class="w-full space-y-4"><FeatureAttention feature="bb.feature.audit-log" />- <div class="flex justify-between items-center space-x-2">- <div>- <div class="w-72">- <UserSelect- v-model:user="state.userUid"- :multiple="false"- :include-all="true"- />- </div>- </div>- <div>+ <AuditLogSearch v-model:params="state.params">+ <template #searchbox-suffix><DataExportButtonsize="medium":file-type="'raw'"@@ -23,8 +14,8 @@:disabled="!hasAuditLogFeature"@export="handleExport"/>- </div>- </div>+ </template>+ </AuditLogSearch><PagedAuditLogTablev-if="hasAuditLogFeature":search-audit-logs="searchAuditLogs"@@ -45,31 +36,39 @@import type { BinaryLike } from "node:crypto";import { reactive, computed } from "vue";import AuditLogDataTable from "@/components/AuditLog/AuditLogDataTable.vue";+import AuditLogSearch from "@/components/AuditLog/AuditLogSearch";+import { buildSearchAuditLogParams } from "@/components/AuditLog/AuditLogSearch/utils";import type { ExportOption } from "@/components/DataExportButton.vue";import DataExportButton from "@/components/DataExportButton.vue";import PagedAuditLogTable from "@/components/PagedAuditLogTable.vue";-import { featureToRef, useAuditLogStore, useUserStore } from "@/store";+import { featureToRef, useAuditLogStore } from "@/store";import type { SearchAuditLogsParams } from "@/types";-import { UNKNOWN_ID } from "@/types";import { ExportFormat } from "@/types/proto/v1/common";+import { type SearchParams } from "@/utils";++interface LocalState {+ params: SearchParams;+}-const state = reactive({- userUid: String(UNKNOWN_ID),+const defaultSearchParams = () => {+ const params: SearchParams = {+ query: "",+ scopes: [],+ };+ return params;+};++const state = reactive<LocalState>({+ params: defaultSearchParams(),});-const userStore = useUserStore();const auditLogStore = useAuditLogStore();const hasAuditLogFeature = featureToRef("bb.feature.audit-log");-const selectedUserEmail = computed((): string => {- const selected = userStore.getUserById(state.userUid);- return selected?.email ?? "";-});-const searchAuditLogs = computed((): SearchAuditLogsParams => {return {- creatorEmail: selectedUserEmail.value,+ ...buildSearchAuditLogParams(state.params),order: "desc",};});diff --git a/frontend/src/views/project/ProjectAuditLogDashboard.vue b/frontend/src/views/project/ProjectAuditLogDashboard.vueindex ed58758e06..9400ee9d26 100644--- a/frontend/src/views/project/ProjectAuditLogDashboard.vue+++ b/frontend/src/views/project/ProjectAuditLogDashboard.vue@@ -1,17 +1,11 @@<template><div class="w-full space-y-4"><FeatureAttention feature="bb.feature.audit-log" />- <div class="flex justify-between items-center space-x-2">- <div>- <div class="w-72">- <UserSelect- v-model:user="state.userUid"- :multiple="false"- :include-all="true"- />- </div>- </div>- <div>+ <AuditLogSearch+ v-model:params="state.params"+ :readonly-scopes="readonlyScopes"+ >+ <template #searchbox-suffix><DataExportButtonsize="medium":file-type="'raw'"@@ -23,8 +17,8 @@:disabled="!hasAuditLogFeature"@export="handleExport"/>- </div>- </div>+ </template>+ </AuditLogSearch><PagedAuditLogTablev-if="hasAuditLogFeature"@@ -46,47 +40,47 @@import type { BinaryLike } from "node:crypto";import { computed, reactive } from "vue";import AuditLogDataTable from "@/components/AuditLog/AuditLogDataTable.vue";+import AuditLogSearch from "@/components/AuditLog/AuditLogSearch";+import { buildSearchAuditLogParams } from "@/components/AuditLog/AuditLogSearch/utils";import type { ExportOption } from "@/components/DataExportButton.vue";+import DataExportButton from "@/components/DataExportButton.vue";import PagedAuditLogTable from "@/components/PagedAuditLogTable.vue";-import {- featureToRef,- useAuditLogStore,- useProjectV1Store,- useUserStore,-} from "@/store";-import { projectNamePrefix } from "@/store/modules/v1/common";-import { UNKNOWN_ID, type SearchAuditLogsParams } from "@/types";+import { featureToRef, useAuditLogStore } from "@/store";+import { type SearchAuditLogsParams } from "@/types";import { ExportFormat } from "@/types/proto/v1/common";+import type { SearchParams, SearchScope } from "@/utils";++interface LocalState {+ params: SearchParams;+}const props = defineProps<{projectId: string;}>();-const state = reactive({- userUid: String(UNKNOWN_ID),+const readonlyScopes = computed((): SearchScope[] => {+ return [{ id: "project", value: props.projectId }];});-const hasAuditLogFeature = featureToRef("bb.feature.audit-log");--const userStore = useUserStore();-const projectV1Store = useProjectV1Store();-const auditLogStore = useAuditLogStore();+const defaultSearchParams = () => {+ const params: SearchParams = {+ query: "",+ scopes: [...readonlyScopes.value],+ };+ return params;+};-const project = computed(() => {- return projectV1Store.getProjectByName(- `${projectNamePrefix}${props.projectId}`- );+const state = reactive<LocalState>({+ params: defaultSearchParams(),});-const selectedUserEmail = computed((): string => {- const selected = userStore.getUserById(state.userUid);- return selected?.email ?? "";-});+const hasAuditLogFeature = featureToRef("bb.feature.audit-log");++const auditLogStore = useAuditLogStore();const searchAuditLogs = computed((): SearchAuditLogsParams => {return {- parent: project.value.name,- creatorEmail: selectedUserEmail.value,+ ...buildSearchAuditLogParams(state.params),order: "desc",};});