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: add database filter store (#10669)
boojack87c2dfe45cbc
diff --git a/frontend/src/App.vue b/frontend/src/App.vueindex 4afa871752..1eec63de20 100644--- a/frontend/src/App.vue+++ b/frontend/src/App.vue@@ -45,9 +45,9 @@ interface LocalState {prevLoggedIn: boolean;}+const router = useRouter();const authStore = useAuthStore();const notificationStore = useNotificationStore();-const router = useRouter();const state = reactive<LocalState>({prevLoggedIn: authStore.isLoggedIn(),diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vueindex fe88c82610..b965a7079a 100644--- a/frontend/src/components/ProjectDatabasesPanel.vue+++ b/frontend/src/components/ProjectDatabasesPanel.vue@@ -83,7 +83,7 @@<script lang="ts" setup>import { NCheckbox } from "naive-ui";import { reactive, computed } from "vue";-import { usePageMode } from "@/store";+import { useFilterStore, usePageMode } from "@/store";import { ComposedDatabase, ComposedProject, UNKNOWN_ID } from "@/types";import {filterDatabaseV1ByKeyword,@@ -106,6 +106,7 @@ const props = defineProps<{}>();const pageMode = usePageMode();+const { filter } = useFilterStore();const state = reactive<LocalState>({selectedDatabaseIds: new Set(),@@ -164,6 +165,9 @@ const filteredDatabaseList = computed(() => {return labels.some((kv) => db.labels[kv.key] === kv.value);});}+ if (filter.database) {+ list = list.filter((db) => db.name === filter.database);+ }return list;});diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vueindex 83e11c19c2..ebed3e5501 100644--- a/frontend/src/components/ProvideDashboardContext.vue+++ b/frontend/src/components/ProvideDashboardContext.vue@@ -4,7 +4,7 @@<script lang="ts" setup>import { ref, onMounted } from "vue";-import { useRoute } from "vue-router";+import { useRoute, useRouter } from "vue-router";import {useEnvironmentV1Store,useInstanceV1Store,@@ -20,6 +20,7 @@ import { projectNamePrefix } from "@/store/modules/v1/common";import { PolicyResourceType } from "@/types/proto/v1/org_policy_service";const route = useRoute();+const router = useRouter();const isLoading = ref<boolean>(true);const policyStore = usePolicyV1Store();@@ -39,6 +40,8 @@ const prepareDatabases = async () => {};onMounted(async () => {+ await router.isReady();+// Prepare roles, workspace policies and settings first.await Promise.all([useRoleStore().fetchRoleList(),diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vueindex 05f77c5570..5e9d4d5562 100644--- a/frontend/src/components/ProvideSQLEditorContext.vue+++ b/frontend/src/components/ProvideSQLEditorContext.vue@@ -344,6 +344,8 @@ const syncURLWithConnection = () => {};onMounted(async () => {+ await router.isReady();+if (treeStore.state === "UNSET") {treeStore.state = "LOADING";diff --git a/frontend/src/store/modules/filter.ts b/frontend/src/store/modules/filter.tsnew file mode 100644index 0000000000..847100e586--- /dev/null+++ b/frontend/src/store/modules/filter.ts@@ -0,0 +1,34 @@+import { defineStore } from "pinia";+import { ref } from "vue";+import { useRouter } from "vue-router";++interface Filter {+ // project mainly using to filter databases in SQL Editor.+ // If specified, only databases in the project will be shown.+ // Format: "projects/{project}"+ project?: string;+ // database mainly using to specify the selected database.+ // Using in SQL Editor and other database related pages.+ // Format: "instances/{instance}/databases/{database}"+ database?: string;+}++export const useFilterStore = defineStore("filter", () => {+ const router = useRouter();+ const filter = ref<Filter>({});++ // Initial filter with route query immediately.+ // And it should not be updated when route changed later except the page is reloaded.+ const route = router.currentRoute.value;+ if (route.query.filter && typeof route.query.filter === "string") {+ try {+ filter.value = JSON.parse(route.query.filter);+ } catch (error) {+ console.error("Failed to parse filter", route.query.filter);+ }+ }++ return {+ filter,+ };+});diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.tsindex a5212a1d07..ffb131a8a3 100644--- a/frontend/src/store/modules/index.ts+++ b/frontend/src/store/modules/index.ts@@ -20,3 +20,4 @@ export * from "./dbGroup";export * from "./utils";export * from "./v1";export * from "./branch";+export * from "./filter";diff --git a/frontend/src/store/modules/sqlEditorTree.ts b/frontend/src/store/modules/sqlEditorTree.tsindex 9a59dbc3b1..dae2df1201 100644--- a/frontend/src/store/modules/sqlEditorTree.ts+++ b/frontend/src/store/modules/sqlEditorTree.ts@@ -33,6 +33,7 @@ import {import { Environment } from "@/types/proto/v1/environment_service";import { emptyConnection, getSemanticLabelValue, groupBy } from "@/utils";import { customTheme } from "@/utils/customTheme";+import { useFilterStore } from "./filter";import { useTabStore } from "./tab";import {useDBSchemaV1Store,@@ -63,6 +64,7 @@ const defaultFactorList = (): StatefulFactor[] => {};export const useSQLEditorTreeStore = defineStore("SQL-Editor-Tree", () => {+ const { filter } = useFilterStore();const factorListInLocalStorage = useLocalStorage<StatefulFactor[]>("bb.sql-editor.tree-factor-list",defaultFactorList(),@@ -102,9 +104,15 @@ export const useSQLEditorTreeStore = defineStore("SQL-Editor-Tree", () => {cloneDeep(factorListInLocalStorage.value));const filteredDatabaseList = computed(() => {- if (selectedProject.value) {+ if (filter.database) {return databaseList.value.filter((database) => {- return database.project === selectedProject.value?.name;+ return database.name === filter.database;+ });+ }+ if (filter.project || selectedProject.value) {+ const projectName = filter.project ?? selectedProject.value?.name;+ return databaseList.value.filter((database) => {+ return database.project === projectName;});}diff --git a/frontend/src/store/modules/tab.ts b/frontend/src/store/modules/tab.tsindex fbc1e8bd5c..37894af264 100644--- a/frontend/src/store/modules/tab.ts+++ b/frontend/src/store/modules/tab.ts@@ -11,6 +11,7 @@ import {WebStorageHelper,isDisconnectedTab,} from "@/utils";+import { useFilterStore } from "./filter";import { useWebTerminalV1Store } from "./v1";import { useWorkSheetStore } from "./v1/worksheet";@@ -38,6 +39,7 @@ type PersistentTabInfo = Pick<TabInfo, typeof PERSISTENT_TAB_FIELDS[number]>;export const useTabStore = defineStore("tab", () => {const storage = new WebStorageHelper("bb.sql-editor.tab-list", localStorage);+ const { filter } = useFilterStore();// states// We store the tabIdList and the tabs separately.@@ -176,18 +178,24 @@ export const useTabStore = defineStore("tab", () => {// Load session from local storage.// Reset if failed.const init = () => {- // Load tabIdList and currentTabId- tabIdList.value = storage.load(KEYS.tabIdList, []);- currentTabId.value = storage.load(KEYS.currentTabId, INITIAL_TAB.id);+ if (filter.project || filter.database) {+ // Don't load tabs from local storage if the filter is specified.+ } else {+ // Load tabIdList and currentTabId+ tabIdList.value = storage.load(KEYS.tabIdList, []);+ currentTabId.value = storage.load(KEYS.currentTabId, INITIAL_TAB.id);+ if (tabIdList.value.indexOf(currentTabId.value) < 0) {+ // currentTabId is not in tabIdList accidentally+ // fallback to the first tab+ currentTabId.value = tabIdList.value[0];+ }+ }++ // Fallback to the initial tab if tabIdList is empty.if (tabIdList.value.length === 0) {// tabIdList is empty accidentallytabIdList.value = [INITIAL_TAB.id];}- if (tabIdList.value.indexOf(currentTabId.value) < 0) {- // currentTabId is not in tabIdList accidentally- // fallback to the first tab- currentTabId.value = tabIdList.value[0];- }// Load tab detailstabIdList.value.forEach((id) => {