Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: tweak project anomalies page (#14969)

boojack886a34b22b4e
diff --git a/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue b/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue
index 76066ca57f..7d18db39cb 100644
--- a/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue
+++ b/frontend/src/components/AnomalyCenter/AnomalyCenterDashboard.vue
@@ -19,15 +19,18 @@
</div>
<div class="space-y-4">
- <div v-for="(item, i) in anomalySummaryList" :key="i" class="space-y-2">
+ <div class="space-y-2">
<h3 class="text-lg leading-6 font-medium text-main">
- {{ i == 0 ? $t("common.database") : $t("common.instance") }}
+ {{ $t("common.database") }}
</h3>
<dl
class="grid grid-cols-1 gap-4 sm:grid-cols-2"
- :class="`lg:grid-cols-${item.length}`"
+ :class="`lg:grid-cols-${databaseAnomalySummaryList.length}`"
>
- <template v-for="(summary, index) in item" :key="index">
+ <template
+ v-for="(summary, index) in databaseAnomalySummaryList"
+ :key="index"
+ >
<NTooltip>
<template #trigger>
<div class="px-4 py-2 border">
@@ -74,75 +77,39 @@
</div>
</div>
- <div class="mt-4 py-2 flex justify-between items-center">
- <TabFilter v-model:value="state.selectedTab" :items="tabItemList" />
-
- <SearchBox
- ref="searchField"
- v-model:value="state.searchText"
- :placeholder="
- $t('anomaly.table-search-placeholder', {
- type:
- state.selectedTab === 'database'
- ? $t('common.database')
- : $t('common.instance'),
- })
- "
- />
+ <AnomalyTable
+ v-if="databaseAnomalySectionList.length > 0"
+ :anomaly-section-list="databaseAnomalySectionList"
+ :compact-section="false"
+ />
+ <div v-else class="text-left text-control-light my-4">
+ {{
+ $t("anomaly.table-placeholder", {
+ type: $t("common.database").toLocaleLowerCase(),
+ })
+ }}
</div>
- <template v-if="state.selectedTab === 'database'">
- <AnomalyTable
- v-if="databaseAnomalySectionList.length > 0"
- :anomaly-section-list="databaseAnomalySectionList"
- :compact-section="false"
- />
- <div v-else class="text-center text-control-light">
- {{
- $t("anomaly.table-placeholder", {
- type: $t("common.database").toLocaleLowerCase(),
- })
- }}
- </div>
- </template>
- <template v-else>
- <AnomalyTable
- v-if="instanceAnomalySectionList.length > 0"
- :anomaly-section-list="instanceAnomalySectionList"
- :compact-section="false"
- />
- <div v-else class="text-center text-control-light">
- {{
- $t("anomaly.table-placeholder", {
- type: $t("common.instance").toLocaleLowerCase(),
- })
- }}
- </div>
- </template>
</div>
</template>
<script lang="ts" setup>
import { NTooltip } from "naive-ui";
-import { computed, onMounted, reactive, ref } from "vue";
-import { useI18n } from "vue-i18n";
+import { computed, onMounted, ref } from "vue";
import type { BBTableSectionDataSource } from "@/bbkit/types";
import {
featureToRef,
useAnomalyV1Store,
useDatabaseV1Store,
useEnvironmentV1List,
- useEnvironmentV1Store,
- useInstanceResourceList,
} from "@/store";
import type { ComposedProject } from "@/types";
import type { Anomaly } from "@/types/proto/v1/anomaly_service";
import { Anomaly_AnomalySeverity } from "@/types/proto/v1/anomaly_service";
-import { databaseV1Url, sortDatabaseV1List, sortInstanceV1List } from "@/utils";
+import { databaseV1Url, sortDatabaseV1List } from "@/utils";
import {
FeatureAttention,
FeatureAttentionForInstanceLicense,
} from "../FeatureGuard";
-import { SearchBox, TabFilter } from "../v2";
import AnomalyTable from "./AnomalyTable.vue";
type Summary = {
@@ -152,30 +119,14 @@ type Summary = {
mediumCount: number;
};
-export type AnomalyTabId = "database" | "instance";
-
-interface LocalState {
- selectedTab: AnomalyTabId;
- searchText: string;
-}
-
const props = defineProps<{
project: ComposedProject;
- selectedTab?: AnomalyTabId;
}>();
-const { t } = useI18n();
const databaseStore = useDatabaseV1Store();
-const environmentStore = useEnvironmentV1Store();
-const instanceList = useInstanceResourceList();
const environmentList = useEnvironmentV1List(false /* !showDeleted */);
const allAnomalyList = ref<Anomaly[]>([]);
-const state = reactive<LocalState>({
- selectedTab: props.selectedTab ?? "database",
- searchText: "",
-});
-
onMounted(async () => {
// Prepare all anomaly list.
allAnomalyList.value = await useAnomalyV1Store().fetchAnomalyList(
@@ -184,43 +135,19 @@ onMounted(async () => {
);
});
-const databaseList = computed(() => {
- return databaseStore.databaseListByUser;
-});
-
const databaseListByProject = computed(() => {
- return databaseList.value.filter((db) => {
- if (!props.project) {
- return true;
- }
- return props.project.name === db.project;
- });
+ return sortDatabaseV1List(
+ databaseStore.databaseListByUser.filter((db) => {
+ return props.project.name === db.project;
+ })
+ );
});
const databaseAnomalySectionList = computed(
(): BBTableSectionDataSource<Anomaly>[] => {
const sectionList: BBTableSectionDataSource<Anomaly>[] = [];
- const dbList = sortDatabaseV1List(
- databaseListByProject.value.filter((database) => {
- if (!state.searchText) {
- return true;
- }
- if (
- database.databaseName
- .toLowerCase()
- .includes(state.searchText.toLowerCase()) ||
- database.effectiveEnvironmentEntity.title
- .toLowerCase()
- .includes(state.searchText.toLowerCase())
- ) {
- return true;
- }
- return false;
- })
- );
-
- for (const database of dbList) {
+ for (const database of databaseListByProject.value) {
const anomalyListOfDatabase = allAnomalyList.value.filter(
(anomaly) => anomaly.resource === database.name
);
@@ -238,49 +165,6 @@ const databaseAnomalySectionList = computed(
}
);
-const instanceAnomalySectionList = computed(
- (): BBTableSectionDataSource<Anomaly>[] => {
- const sectionList: BBTableSectionDataSource<Anomaly>[] = [];
-
- const insList = sortInstanceV1List(
- instanceList.value.filter((instance) => {
- if (!state.searchText) {
- return true;
- }
- if (
- instance.title
- .toLowerCase()
- .includes(state.searchText.toLowerCase()) ||
- environmentStore
- .getEnvironmentByName(instance.environment)
- .title.toLowerCase()
- .includes(state.searchText.toLowerCase())
- ) {
- return true;
- }
- return false;
- })
- );
-
- for (const instance of insList) {
- const anomalyListOfInstance = allAnomalyList.value.filter((anomaly) =>
- anomaly.resource.startsWith(instance.name)
- );
- if (anomalyListOfInstance.length > 0) {
- sectionList.push({
- title: `${instance.title} (${
- environmentStore.getEnvironmentByName(instance.environment).title
- })`,
- link: `/${instance.name}`,
- list: anomalyListOfInstance,
- });
- }
- }
-
- return sectionList;
- }
-);
-
const databaseAnomalySummaryList = computed((): Summary[] => {
const envMap: Map<string, Summary> = new Map();
for (const database of databaseListByProject.value) {
@@ -329,78 +213,5 @@ const databaseAnomalySummaryList = computed((): Summary[] => {
return list.reverse();
});
-const instanceAnomalySummaryList = computed((): Summary[] => {
- const envMap: Map<string, Summary> = new Map();
- for (const instance of instanceList.value) {
- let criticalCount = 0;
- let highCount = 0;
- let mediumCount = 0;
- const anomalyListOfInstance = allAnomalyList.value.filter(
- (anomaly) => anomaly.resource === instance.name
- );
- for (const anomaly of anomalyListOfInstance) {
- switch (anomaly.severity) {
- case Anomaly_AnomalySeverity.CRITICAL:
- criticalCount++;
- break;
- case Anomaly_AnomalySeverity.HIGH:
- highCount++;
- break;
- case Anomaly_AnomalySeverity.MEDIUM:
- mediumCount++;
- break;
- }
- }
- const summary = envMap.get(instance.environment);
- if (summary) {
- summary.criticalCount += criticalCount;
- summary.highCount += highCount;
- summary.mediumCount += mediumCount;
- } else {
- envMap.set(instance.environment, {
- environmentName: environmentStore.getEnvironmentByName(
- instance.environment
- ).title,
- criticalCount,
- highCount,
- mediumCount,
- });
- }
- }
-
- const list: Summary[] = [];
- for (const environment of environmentList.value) {
- const summary = envMap.get(environment.name);
- if (summary) {
- list.push(summary);
- }
- }
-
- return list.reverse();
-});
-
-const anomalySummaryList = computed(() => {
- const list = [databaseAnomalySummaryList.value];
- if (!props.project) {
- list.push(instanceAnomalySummaryList.value);
- }
- return list;
-});
-
-const tabItemList = computed(() => {
- return [
- {
- value: "database",
- label: t("common.database"),
- alert: databaseAnomalySectionList.value.length > 0,
- },
- {
- value: "instance",
- label: t("common.instance"),
- alert: instanceAnomalySectionList.value.length > 0,
- },
- ];
-});
-
const hasSchemaDriftFeature = featureToRef("bb.feature.schema-drift");
</script>