Skip to content

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

chore: simplify the advanced search (#15571)

ecmadao5053df5b673f
diff --git a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
index d48db59398..3ebcf73428 100644
--- a/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
+++ b/frontend/src/components/AdvancedSearch/useCommonSearchScopeOptions.ts
@@ -1,24 +1,21 @@
-import type { Ref, VNode } from "vue";
+import type { VNode } from "vue";
import { computed, h, unref } from "vue";
-import { useRoute } from "vue-router";
import {
InstanceV1Name,
ProjectV1Name,
- RichDatabaseName,
EnvironmentV1Name,
RichEngineName,
} from "@/components/v2";
import { t } from "@/plugins/i18n";
import {
- useDatabaseV1Store,
useEnvironmentV1List,
useEnvironmentV1Store,
useInstanceResourceList,
useProjectV1List,
} from "@/store";
-import { UNKNOWN_ID, isValidProjectName, type MaybeRef } from "@/types";
+import { type MaybeRef } from "@/types";
import { engineToJSON } from "@/types/proto/v1/common";
-import type { SearchParams, SearchScopeId } from "@/utils";
+import type { SearchScopeId } from "@/utils";
import {
environmentV1Name,
extractEnvironmentResourceName,
@@ -29,36 +26,12 @@ import {
import type { ScopeOption, ValueOption } from "./types";
export const useCommonSearchScopeOptions = (
- params: Ref<SearchParams>,
supportOptionIdList: MaybeRef<SearchScopeId[]>
) => {
- const route = useRoute();
- const databaseV1Store = useDatabaseV1Store();
const environmentStore = useEnvironmentV1Store();
const environmentList = useEnvironmentV1List();
const { projectList } = useProjectV1List();
- const project = computed(() => {
- const { projectId } = route?.params ?? {};
- if (projectId && typeof projectId === "string") {
- return `projects/${projectId}`;
- }
- const projectScope = params.value.scopes.find(
- (scope) => scope.id === "project"
- );
- if (projectScope) {
- return `projects/${projectScope.value}`;
- }
- return undefined;
- });
-
- const databaseList = computed(() => {
- if (!isValidProjectName(project.value)) {
- return [];
- }
- return databaseV1Store.databaseListByProject(project.value!);
- });
-
const instanceList = computed(() => useInstanceResourceList().value);
// fullScopeOptions provides full search scopes and options.
@@ -108,7 +81,9 @@ export const useCommonSearchScopeOptions = (
link: false,
tooltip: false,
}),
- renderSpan(
+ h(
+ "span",
+ {},
`(${environmentV1Name(environmentStore.getEnvironmentByName(ins.environment))})`
),
]);
@@ -116,34 +91,6 @@ export const useCommonSearchScopeOptions = (
};
}),
}),
- database: () => ({
- id: "database",
- title: t("issue.advanced-search.scope.database.title"),
- description: t("issue.advanced-search.scope.database.description"),
- options: databaseList.value.map((db) => {
- return {
- value: db.name,
- keywords: [
- db.databaseName,
- extractInstanceResourceName(db.instance),
- db.instanceResource.title,
- extractEnvironmentResourceName(db.effectiveEnvironment),
- db.effectiveEnvironmentEntity.title,
- extractProjectResourceName(db.project),
- db.projectEntity.title,
- ],
- custom: true,
- render: () => {
- return h("div", { class: "text-sm" }, [
- h(RichDatabaseName, {
- database: db,
- showProject: true,
- }),
- ]);
- },
- };
- }),
- }),
environment: () => ({
id: "environment",
title: t("issue.advanced-search.scope.environment.title"),
@@ -186,18 +133,6 @@ export const useCommonSearchScopeOptions = (
const scopes: ScopeOption[] = [];
unref(supportOptionIdList).forEach((id) => {
- // Do not show database scope if there are no databases.
- if (databaseList.value.length === 0) {
- if (id === "database") {
- return;
- }
- // Do not show instance scope if there are no instances.
- if (instanceList.value.length === 0) {
- if (id === "instance") {
- return;
- }
- }
- }
const create = scopeCreators[id];
if (create) {
scopes.push(create());
@@ -206,53 +141,5 @@ export const useCommonSearchScopeOptions = (
return scopes;
});
- // 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 existedScopes = new Map<SearchScopeId, string>(
- params.value.scopes.map((scope) => [scope.id, scope.value])
- );
-
- const clone = fullScopeOptions.value.map((scope) => ({
- ...scope,
- options: scope.options.map((option) => ({
- ...option,
- })),
- }));
- const index = clone.findIndex((scope) => scope.id === "database");
- if (index >= 0) {
- clone[index].options = clone[index].options.filter((option) => {
- if (!existedScopes.has("project") && !existedScopes.has("instance")) {
- return true;
- }
-
- const db = databaseV1Store.getDatabaseByName(option.value);
- const project = db.project;
- const instance = db.instance;
-
- const existedProject = `projects/${
- existedScopes.get("project") ?? UNKNOWN_ID
- }`;
- if (project === existedProject) {
- return true;
- }
- const existedInstance = `instances/${
- existedScopes.get("instance") ?? UNKNOWN_ID
- }`;
- if (instance === existedInstance) {
- return true;
- }
-
- return false;
- });
- }
-
- return clone;
- });
-
- return filteredScopeOptions;
-};
-
-const renderSpan = (content: string) => {
- return h("span", {}, content);
+ return fullScopeOptions;
};
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index 13ed1d2997..76ece2bac7 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -189,7 +189,6 @@ const state = reactive<LocalState>({
});
const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
computed(() => ["project", "instance", "environment", "database-label"])
);
diff --git a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
index c674679184..178f04d246 100644
--- a/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
+++ b/frontend/src/components/DataExportPrepForm/DataExportPrepForm.vue
@@ -100,10 +100,11 @@ const state = reactive<LocalState>({
},
});
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
- ["environment", "instance", "database-label"]
-);
+const scopeOptions = useCommonSearchScopeOptions([
+ "environment",
+ "instance",
+ "database-label",
+]);
const selectedInstance = computed(() => {
const instanceId = state.params.scopes.find(
diff --git a/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue b/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue
index 70ff38b169..467ebc40c1 100644
--- a/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue
+++ b/frontend/src/components/DatabaseAndGroupSelector/DatabaseAndGroupSelector.vue
@@ -117,10 +117,7 @@ const filter = computed(() => ({
query: searchParams.value.query,
}));
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => searchParams.value),
- [...CommonFilterScopeIdList]
-);
+const scopeOptions = useCommonSearchScopeOptions([...CommonFilterScopeIdList]);
watch(
() => databaseSelectState,
diff --git a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
index a3f01e3d04..9c36b10cc1 100644
--- a/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
+++ b/frontend/src/components/IssueV1/components/IssueSearch/useIssueSearchScopeOptions.ts
@@ -1,20 +1,33 @@
import { orderBy } from "lodash-es";
import type { Ref, RenderFunction } from "vue";
-import { computed, h } from "vue";
+import { computed, h, ref, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
+import { useRoute } from "vue-router";
import BBAvatar from "@/bbkit/BBAvatar.vue";
import { useCommonSearchScopeOptions } from "@/components/AdvancedSearch/useCommonSearchScopeOptions";
import SystemBotTag from "@/components/misc/SystemBotTag.vue";
import YouTag from "@/components/misc/YouTag.vue";
+import { RichDatabaseName } from "@/components/v2";
import {
useCurrentUserV1,
useDatabaseV1Store,
useProjectV1List,
} from "@/store";
-import { SYSTEM_BOT_USER_NAME, UNKNOWN_ID } from "@/types";
+import {
+ SYSTEM_BOT_USER_NAME,
+ UNKNOWN_ID,
+ isValidProjectName,
+ type ComposedDatabase,
+} from "@/types";
import { Label } from "@/types/proto/v1/project_service";
import { User } from "@/types/proto/v1/user_service";
import type { SearchParams, SearchScopeId } from "@/utils";
+import {
+ getDefaultPagination,
+ extractEnvironmentResourceName,
+ extractInstanceResourceName,
+ extractProjectResourceName,
+} from "@/utils";
export type ScopeOption = {
id: SearchScopeId;
@@ -56,13 +69,38 @@ export const useIssueSearchScopeOptions = (
activeUserList: Ref<User[]>
) => {
const { t } = useI18n();
+ const route = useRoute();
const me = useCurrentUserV1();
const databaseV1Store = useDatabaseV1Store();
- const commonScopeOptions = useCommonSearchScopeOptions(
- params,
- supportOptionIdList
- );
+ const project = computed(() => {
+ const { projectId } = route?.params ?? {};
+ if (projectId && typeof projectId === "string") {
+ return `projects/${projectId}`;
+ }
+ const projectScope = params.value.scopes.find(
+ (scope) => scope.id === "project"
+ );
+ if (projectScope) {
+ return `projects/${projectScope.value}`;
+ }
+ return undefined;
+ });
+
+ const databaseList = ref<ComposedDatabase[]>([]);
+
+ watchEffect(async () => {
+ if (!isValidProjectName(project.value)) {
+ return;
+ }
+ const { databases } = await databaseV1Store.fetchDatabases({
+ pageSize: getDefaultPagination(),
+ parent: project.value!,
+ });
+ databaseList.value = databases;
+ });
+
+ const commonScopeOptions = useCommonSearchScopeOptions(supportOptionIdList);
const principalSearchValueOptions = computed(() => {
// Put "you" to the top
@@ -98,6 +136,34 @@ export const useIssueSearchScopeOptions = (
const fullScopeOptions = computed((): ScopeOption[] => {
const scopes: ScopeOption[] = [
...commonScopeOptions.value,
+ {
+ id: "database",
+ title: t("issue.advanced-search.scope.database.title"),
+ description: t("issue.advanced-search.scope.database.description"),
+ options: databaseList.value.map((db) => {
+ return {
+ value: db.name,
+ keywords: [
+ db.databaseName,
+ extractInstanceResourceName(db.instance),
+ db.instanceResource.title,
+ extractEnvironmentResourceName(db.effectiveEnvironment),
+ db.effectiveEnvironmentEntity.title,
+ extractProjectResourceName(db.project),
+ db.projectEntity.title,
+ ],
+ custom: true,
+ render: () => {
+ return h("div", { class: "text-sm" }, [
+ h(RichDatabaseName, {
+ database: db,
+ showProject: true,
+ }),
+ ]);
+ },
+ };
+ }),
+ },
{
id: "status",
title: t("common.status"),
@@ -194,7 +260,9 @@ export const useIssueSearchScopeOptions = (
},
];
const supportOptionIdSet = new Set(supportOptionIdList.value);
- return scopes.filter((scope) => supportOptionIdSet.has(scope.id));
+ return scopes.filter(
+ (scope) => supportOptionIdSet.has(scope.id) && scope.options.length > 0
+ );
});
// filteredScopeOptions will filter search options by chosen scope.
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index 110c0dbbe8..e66a135e03 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -124,10 +124,11 @@ const allowToCreateDB = computed(() => {
);
});
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
- [...CommonFilterScopeIdList, "database-label", "engine"]
-);
+const scopeOptions = useCommonSearchScopeOptions([
+ ...CommonFilterScopeIdList,
+ "database-label",
+ "engine",
+]);
const selectedInstance = computed(() => {
const instanceId = state.params.scopes.find(
diff --git a/frontend/src/components/SyncDatabaseSchemaV1/TargetDatabasesSelectPanel.vue b/frontend/src/components/SyncDatabaseSchemaV1/TargetDatabasesSelectPanel.vue
index 8d81c2ca5c..33c9a10212 100644
--- a/frontend/src/components/SyncDatabaseSchemaV1/TargetDatabasesSelectPanel.vue
+++ b/frontend/src/components/SyncDatabaseSchemaV1/TargetDatabasesSelectPanel.vue
@@ -128,10 +128,7 @@ watch(
}
);
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
- [...CommonFilterScopeIdList]
-);
+const scopeOptions = useCommonSearchScopeOptions([...CommonFilterScopeIdList]);
const selectedDatabaseList = computed(() =>
state.selectedDatabaseNameList.map((name) =>
diff --git a/frontend/src/store/modules/v1/database.ts b/frontend/src/store/modules/v1/database.ts
index 984fc88f24..386be6bb81 100644
--- a/frontend/src/store/modules/v1/database.ts
+++ b/frontend/src/store/modules/v1/database.ts
@@ -140,10 +140,6 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
await fetchDatabaseByName(database);
}
};
- // TODO(ed): deprecate it.
- const databaseListByProject = (project: string) => {
- return databaseList.value.filter((db) => db.project === project);
- };
const getDatabaseByName = (name: string) => {
return databaseMapByName.get(name) ?? unknownDatabase();
};
@@ -202,7 +198,6 @@ export const useDatabaseV1Store = defineStore("database_v1", () => {
removeCacheByInstance,
upsertDatabaseMap,
syncDatabase,
- databaseListByProject,
getDatabaseByName,
fetchDatabaseByName,
getOrFetchDatabaseByName,
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 74e2d05bbb..d4877b95f3 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -128,10 +128,12 @@ const allowToCreateDB = computed(() => {
);
});
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
- [...CommonFilterScopeIdList, "project", "database-label", "engine"]
-);
+const scopeOptions = useCommonSearchScopeOptions([
+ ...CommonFilterScopeIdList,
+ "project",
+ "database-label",
+ "engine",
+]);
const selectedLabels = computed(() => {
return state.params.scopes
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 5eb4937dbc..71f9ecd458 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -197,10 +197,7 @@ const addressOptions = computed(() => {
const scopeOptions = computed((): ScopeOption[] => {
return [
- ...useCommonSearchScopeOptions(
- computed(() => state.params),
- ["environment"]
- ).value,
+ ...useCommonSearchScopeOptions(["environment"]).value,
{
id: "address",
title: t("instance.advanced-search.scope.address.title"),
@@ -258,18 +255,26 @@ const remainingInstanceCount = computed((): number => {
});
const instanceCountAttention = computed((): string => {
- const upgrade = t("dynamic.subscription.features.bb-feature-instance-count.upgrade");
+ const upgrade = t(
+ "dynamic.subscription.features.bb-feature-instance-count.upgrade"
+ );
let status = "";
if (remainingInstanceCount.value > 0) {
- status = t("dynamic.subscription.features.bb-feature-instance-count.remaining", {
- total: subscriptionStore.instanceCountLimit,
- count: remainingInstanceCount.value,
- });
+ status = t(
+ "dynamic.subscription.features.bb-feature-instance-count.remaining",
+ {
+ total: subscriptionStore.instanceCountLimit,
+ count: remainingInstanceCount.value,
+ }
+ );
} else {
- status = t("dynamic.subscription.features.bb-feature-instance-count.runoutof", {
- total: subscriptionStore.instanceCountLimit,
- });
+ status = t(
+ "dynamic.subscription.features.bb-feature-instance-count.runoutof",
+ {
+ total: subscriptionStore.instanceCountLimit,
+ }
+ );
}
return `${status} ${upgrade}`;
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index 2844ca9ab2..65b01211d0 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -182,10 +182,11 @@ const state = reactive<LocalState>({
const route = useRoute();
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
- [...CommonFilterScopeIdList, "project", "database-label"]
-);
+const scopeOptions = useCommonSearchScopeOptions([
+ ...CommonFilterScopeIdList,
+ "project",
+ "database-label",
+]);
watch(
() => route.hash,
diff --git a/frontend/src/views/ReviewCenter/index.vue b/frontend/src/views/ReviewCenter/index.vue
index 1581eec36e..ab3cfdd511 100644
--- a/frontend/src/views/ReviewCenter/index.vue
+++ b/frontend/src/views/ReviewCenter/index.vue
@@ -147,10 +147,7 @@ const supportedScopes = computed(() => {
return supportedScopes;
});
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
- supportedScopes.value
-);
+const scopeOptions = useCommonSearchScopeOptions(supportedScopes.value);
const planSearchParams = computed(() => {
// Default scopes with type and creator.
diff --git a/frontend/src/views/sql-editor/Setting/Instance/Instance.vue b/frontend/src/views/sql-editor/Setting/Instance/Instance.vue
index 8bd710bce9..95ec4f12b0 100644
--- a/frontend/src/views/sql-editor/Setting/Instance/Instance.vue
+++ b/frontend/src/views/sql-editor/Setting/Instance/Instance.vue
@@ -152,10 +152,7 @@ const state = reactive<LocalState>({
},
});
-const scopeOptions = useCommonSearchScopeOptions(
- computed(() => state.params),
- ["environment"]
-);
+const scopeOptions = useCommonSearchScopeOptions(["environment"]);
const selectedEnvironment = computed(() => {
return (
@@ -221,18 +218,26 @@ const remainingInstanceCount = computed((): number => {
});
const instanceCountAttention = computed((): string => {
- const upgrade = t("dynamic.subscription.features.bb-feature-instance-count.upgrade");
+ const upgrade = t(
+ "dynamic.subscription.features.bb-feature-instance-count.upgrade"
+ );
let status = "";
if (remainingInstanceCount.value > 0) {
- status = t("dynamic.subscription.features.bb-feature-instance-count.remaining", {
- total: subscriptionStore.instanceCountLimit,
- count: remainingInstanceCount.value,
- });
+ status = t(
+ "dynamic.subscription.features.bb-feature-instance-count.remaining",
+ {
+ total: subscriptionStore.instanceCountLimit,
+ count: remainingInstanceCount.value,
+ }
+ );
} else {
- status = t("dynamic.subscription.features.bb-feature-instance-count.runoutof", {
- total: subscriptionStore.instanceCountLimit,
- });
+ status = t(
+ "dynamic.subscription.features.bb-feature-instance-count.runoutof",
+ {
+ total: subscriptionStore.instanceCountLimit,
+ }
+ );
}
return `${status} ${upgrade}`;