Skip to content

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

feat(frontend): better database search boxes (#3871)

Liu Ji0523345d1baf
diff --git a/frontend/src/components/AccessControl/AddRuleForm.vue b/frontend/src/components/AccessControl/AddRuleForm.vue
index 7546c90e78..4c7dec5b12 100644
--- a/frontend/src/components/AccessControl/AddRuleForm.vue
+++ b/frontend/src/components/AccessControl/AddRuleForm.vue
@@ -3,7 +3,7 @@
<div>
<BBTableSearch
class="w-60"
- :placeholder="$t('database.search-database-name')"
+ :placeholder="$t('database.search-database')"
@change-text="(text: string) => (state.searchText = text)"
/>
</div>
@@ -87,6 +87,7 @@ import { computed, PropType, reactive } from "vue";
import type { Database, DatabaseId, Policy } from "@/types";
import { DEFAULT_PROJECT_ID } from "@/types";
import { useDatabaseStore } from "@/store";
+import { filterDatabaseByKeyword } from "@/utils";
type LocalState = {
isLoading: boolean;
@@ -140,9 +141,14 @@ const databaseList = computed(() => {
);
const keyword = state.searchText.trim();
- if (keyword) {
- list = list.filter((db) => db.name.toLowerCase().includes(keyword));
- }
+ list = list.filter((db) =>
+ filterDatabaseByKeyword(db, keyword, [
+ "name",
+ "project",
+ "instance",
+ "environment",
+ ])
+ );
return list;
});
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index d1346b7967..bf11c06508 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -43,7 +43,7 @@
<BBTableSearch
v-if="state.alterType === 'MULTI_DB'"
class="m-px"
- :placeholder="$t('database.search-database-name')"
+ :placeholder="$t('database.search-database')"
@change-text="(text: string) => (state.searchText = text)"
/>
</template>
@@ -62,7 +62,7 @@
<div class="flex items-center justify-end my-2">
<BBTableSearch
class="m-px"
- :placeholder="$t('database.search-database-name')"
+ :placeholder="$t('database.search-database')"
@change-text="(text: string) => (state.searchText = text)"
/>
</div>
@@ -74,7 +74,7 @@
<aside class="flex justify-end mb-4">
<BBTableSearch
class="m-px"
- :placeholder="$t('database.search-database-name')"
+ :placeholder="$t('database.search-database')"
@change-text="(text: string) => (state.searchText = text)"
/>
</aside>
@@ -171,6 +171,7 @@ import {
import {
allowGhostMigration,
allowUsingSchemaEditor,
+ filterDatabaseByKeyword,
sortDatabaseList,
} from "@/utils";
import {
@@ -272,9 +273,14 @@ const databaseList = computed(() => {
}
const keyword = state.searchText.trim();
- if (keyword) {
- list = list.filter((db) => db.name.toLowerCase().includes(keyword));
- }
+ list = list.filter((db) =>
+ filterDatabaseByKeyword(db, keyword, [
+ "name",
+ "environment",
+ "instance",
+ "project",
+ ])
+ );
return sortDatabaseList(cloneDeep(list), environmentList.value);
});
diff --git a/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue b/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue
index 712bbda64d..9e668b6c21 100644
--- a/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/ProjectTenantView.vue
@@ -38,7 +38,7 @@
</i18n-t>
</div>
<template v-else>
- <div class="flex justify-end items-center py-0.5">
+ <div class="flex justify-end items-center pb-2">
<YAxisRadioGroup v-model:label="label" class="text-sm" />
</div>
diff --git a/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue
index cf3a5a8262..3d1ad7b843 100644
--- a/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue
+++ b/frontend/src/components/DeploymentConfigTool/DeploymentMatrix.vue
@@ -16,10 +16,16 @@
<template v-else>
<div class="flex justify-end items-center py-0.5 space-x-2">
<YAxisRadioGroup v-model:label="state.label" class="text-sm" />
+ <BBTableSearch
+ v-if="showSearchBox"
+ class="w-60"
+ :placeholder="$t('database.search-database')"
+ @change-text="(text: string) => (state.keyword = text)"
+ />
</div>
<DeployDatabaseTable
- :database-list="databaseList"
+ :database-list="filteredDatabaseList"
:label="state.label"
:environment-list="environmentList"
:deployment="deployment"
@@ -29,7 +35,7 @@
</template>
<script lang="ts" setup>
-import { reactive } from "vue";
+import { computed, reactive } from "vue";
import {
Project,
DeploymentConfig,
@@ -38,15 +44,34 @@ import {
LabelKeyType,
} from "@/types";
import { DeployDatabaseTable } from "../TenantDatabaseTable";
+import { filterDatabaseByKeyword } from "@/utils";
-defineProps<{
- project: Project;
- deployment: DeploymentConfig;
- environmentList: Environment[];
- databaseList: Database[];
-}>();
+const props = withDefaults(
+ defineProps<{
+ project: Project;
+ deployment: DeploymentConfig;
+ environmentList: Environment[];
+ databaseList: Database[];
+ showSearchBox: boolean;
+ }>(),
+ {
+ showSearchBox: false,
+ }
+);
const state = reactive({
label: "bb.environment" as LabelKeyType,
+ keyword: "",
+});
+
+const filteredDatabaseList = computed(() => {
+ return props.databaseList.filter((db) => {
+ return filterDatabaseByKeyword(db, state.keyword, [
+ "name",
+ "environment",
+ "instance",
+ "tenant",
+ ]);
+ });
});
</script>
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index 525d95b839..b9b6471927 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -3,10 +3,17 @@
<div
class="text-lg font-medium leading-7 text-main flex items-center justify-between"
>
- {{ $t("common.database") }}
+ <h3>{{ $t("common.database") }}</h3>
+ <div>
+ <BBTableSearch
+ class="w-60"
+ :placeholder="$t('database.search-database')"
+ @change-text="(text: string) => (state.keyword = text)"
+ />
+ </div>
</div>
- <template v-if="filteredDatabaseList.length > 0">
+ <template v-if="databaseList.length > 0">
<DatabaseTable mode="PROJECT" :database-list="filteredDatabaseList" />
</template>
<div v-else class="text-center textinfolabel">
diff --git a/frontend/src/components/ProjectDeploymentConfigPanel.vue b/frontend/src/components/ProjectDeploymentConfigPanel.vue
index d3ba5deef9..3d26d5c60f 100644
--- a/frontend/src/components/ProjectDeploymentConfigPanel.vue
+++ b/frontend/src/components/ProjectDeploymentConfigPanel.vue
@@ -10,6 +10,7 @@
:deployment="state.deployment"
:database-list="databaseList"
:environment-list="environmentList"
+ show-search-box
/>
</div>
diff --git a/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue b/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue
index f8f09a5464..fd28df4a24 100644
--- a/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue
+++ b/frontend/src/components/TenantDatabaseTable/YAxisRadioGroup.vue
@@ -4,7 +4,7 @@
<span class="textlabel mr-1">Group by</span>
</slot>
- <select class="btn-select py-[0.3rem]" :value="label" @change="onChange">
+ <select class="btn-select py-[0.5rem]" :value="label" @change="onChange">
<option
v-for="key in labelKeyList"
:key="key"
diff --git a/frontend/src/utils/database.ts b/frontend/src/utils/database.ts
index 2129022241..9eeb300a9d 100644
--- a/frontend/src/utils/database.ts
+++ b/frontend/src/utils/database.ts
@@ -82,7 +82,12 @@ export function allowGhostMigration(databaseList: Database[]): boolean {
});
}
-type DatabaseFilterFields = "name" | "project" | "instance" | "environment";
+type DatabaseFilterFields =
+ | "name"
+ | "project"
+ | "instance"
+ | "environment"
+ | "tenant";
export function filterDatabaseByKeyword(
db: Database,
keyword: string,
@@ -119,6 +124,16 @@ export function filterDatabaseByKeyword(
return true;
}
+ if (
+ columns.includes("tenant") &&
+ db.labels
+ .find((label) => label.key === "bb.tenant")
+ ?.value.toLowerCase()
+ .includes(keyword)
+ ) {
+ return true;
+ }
+
return false;
}
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 9bc65a6e03..9ac3203517 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -29,8 +29,8 @@
</NTooltip>
<BBTableSearch
ref="searchField"
- :placeholder="$t('database.search-database-name')"
- @change-text="(text) => changeSearchText(text)"
+ :placeholder="$t('database.search-database')"
+ @change-text="(text: string) => changeSearchText(text)"
/>
</div>
</div>
@@ -65,7 +65,7 @@ import {
UNKNOWN_ID,
DEFAULT_PROJECT_ID,
} from "../types";
-import { sortDatabaseList } from "../utils";
+import { filterDatabaseByKeyword, sortDatabaseList } from "../utils";
import { cloneDeep } from "lodash-es";
import {
useCurrentUser,
@@ -159,20 +159,22 @@ export default defineComponent({
};
const filteredList = computed(() => {
- if (!state.selectedEnvironment && !state.searchText) {
- // Select "All"
- return state.databaseList;
- }
- return state.databaseList.filter((database) => {
- return (
- (!state.selectedEnvironment ||
- database.instance.environment.id == state.selectedEnvironment.id) &&
- (!state.searchText ||
- database.name
- .toLowerCase()
- .includes(state.searchText.toLowerCase()))
+ const { databaseList, selectedEnvironment, searchText } = state;
+ let list = [...databaseList];
+ if (selectedEnvironment) {
+ list = list.filter(
+ (db) => db.instance.environment.id === selectedEnvironment.id
);
- });
+ }
+ list = list.filter((db) =>
+ filterDatabaseByKeyword(db, searchText, [
+ "name",
+ "environment",
+ "instance",
+ "project",
+ ])
+ );
+ return list;
});
return {