Skip to content

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

chore: retire filter store (#13813)

boojack7eba3d371eab
diff --git a/frontend/src/components/ProjectDatabasesPanel.vue b/frontend/src/components/ProjectDatabasesPanel.vue
index e3f18b8010..601970bd64 100644
--- a/frontend/src/components/ProjectDatabasesPanel.vue
+++ b/frontend/src/components/ProjectDatabasesPanel.vue
@@ -37,7 +37,6 @@
import { reactive, computed } from "vue";
import { useRouter } from "vue-router";
import DatabaseV1Table from "@/components/v2/Model/DatabaseV1Table";
-import { useFilterStore } from "@/store";
import type { ComposedDatabase, ComposedProject } from "@/types";
import { UNKNOWN_ID } from "@/types";
import type { SearchParams } from "@/utils";
@@ -64,7 +63,6 @@ const props = defineProps<{
}>();
const router = useRouter();
-const { filter } = useFilterStore();
const state = reactive<LocalState>({
selectedDatabaseNames: new Set(),
@@ -125,9 +123,6 @@ 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/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index fd28a375b9..c6e3e4e99b 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -43,7 +43,6 @@ import {
useWorkSheetStore,
useGroupStore,
pushNotification,
- useFilterStore,
useAppFeature,
useProjectV1List,
} from "@/store";
@@ -92,7 +91,6 @@ const tabStore = useSQLEditorTabStore();
const groupStore = useGroupStore();
const policyStore = usePolicyV1Store();
const { isFetching: isFetchingWorksheet } = useSheetContext();
-const { filter } = useFilterStore();
const {
asidePanelTab,
events: editorEvents,
@@ -376,8 +374,6 @@ const prepareConnectionParams = async () => {
connect({
instance: database.instance,
database: database.name,
- schema: filter.schema,
- table: filter.table,
});
return true;
}
@@ -402,23 +398,6 @@ const initializeConnectionFromQuery = async () => {
return;
}
- if (filter.database) {
- const database = await databaseStore.getOrFetchDatabaseByName(
- filter.database,
- /* silent */ true
- );
- if (isValidDatabaseName(database.name)) {
- await maybeSwitchProject(database.project);
- connect({
- instance: database.instance,
- database: database.name,
- schema: filter.schema,
- table: filter.table,
- });
- return;
- }
- }
-
// Keep disconnected otherwise
// We don't need to `selectOrAddTempTab` here since we already have the
// default tab.
diff --git a/frontend/src/store/modules/filter.ts b/frontend/src/store/modules/filter.ts
deleted file mode 100644
index cfbc741c3a..0000000000
--- a/frontend/src/store/modules/filter.ts
+++ /dev/null
@@ -1,45 +0,0 @@
-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;
- // the schema name.
- schema?: string;
- // the table name.
- table?: 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 { query } = router.currentRoute.value;
- if (query.filter && typeof query.filter === "string") {
- try {
- filter.value = JSON.parse(query.filter);
- } catch (error) {
- console.error("Failed to parse filter", query.filter);
- }
- } else {
- if (typeof query.schema === "string" && query.schema) {
- filter.value.schema = query.schema;
- }
- if (typeof query.table === "string" && query.table) {
- filter.value.table = query.table;
- }
- }
-
- return {
- filter,
- };
-});
diff --git a/frontend/src/store/modules/index.ts b/frontend/src/store/modules/index.ts
index b72f5b865a..17bec3f80e 100644
--- a/frontend/src/store/modules/index.ts
+++ b/frontend/src/store/modules/index.ts
@@ -18,4 +18,3 @@ export * from "./dbGroup";
export * from "./utils";
export * from "./v1";
export * from "./branch";
-export * from "./filter";
diff --git a/frontend/src/store/modules/sqlEditor/editor.ts b/frontend/src/store/modules/sqlEditor/editor.ts
index fd6f9165f2..d3e8bc12a9 100644
--- a/frontend/src/store/modules/sqlEditor/editor.ts
+++ b/frontend/src/store/modules/sqlEditor/editor.ts
@@ -3,7 +3,6 @@ import { defineStore } from "pinia";
import { computed, ref, watch } from "vue";
import type { ComposedDatabase } from "@/types";
import { hasWorkspacePermissionV2 } from "@/utils";
-import { useProjectV1Store } from "../v1";
export const useSQLEditorStore = defineStore("sqlEditor", () => {
const resultRowsLimit = useLocalStorage(
@@ -23,12 +22,6 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {
""
);
- const currentProject = computed(() => {
- if (project.value) {
- return useProjectV1Store().getProjectByName(project.value);
- }
- return undefined;
- });
const allowViewALLProjects = computed(() => {
return hasWorkspacePermissionV2("bb.projects.list");
});
@@ -48,7 +41,6 @@ export const useSQLEditorStore = defineStore("sqlEditor", () => {
strictProject,
projectContextReady,
storedLastViewedProject,
- currentProject,
allowViewALLProjects,
databaseList,
isShowExecutingHint,
diff --git a/frontend/src/store/modules/sqlEditor/tree.ts b/frontend/src/store/modules/sqlEditor/tree.ts
index 7f7e0a45b1..cb5b856c24 100644
--- a/frontend/src/store/modules/sqlEditor/tree.ts
+++ b/frontend/src/store/modules/sqlEditor/tree.ts
@@ -21,7 +21,6 @@ import {
import type { Environment } from "@/types/proto/v1/environment_service";
import type { InstanceResource } from "@/types/proto/v1/instance_service";
import { getSemanticLabelValue, groupBy, isDatabaseV1Queryable } from "@/utils";
-import { useFilterStore } from "../filter";
import {
useAppFeature,
useEnvironmentV1Store,
@@ -41,7 +40,6 @@ const defaultInstanceFactor: StatefulFactor = {
};
export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
- const { filter } = useFilterStore();
const hideEnvironments = useAppFeature(
"bb.feature.sql-editor.hide-environments"
);
@@ -88,7 +86,7 @@ export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
const nodeListMapById = reactive(new Map<string, TreeNode[]>());
// states
// re-expose `databaseList`, `project`, `currentProject` from sqlEditor store for shortcuts
- const { databaseList, project, currentProject } =
+ const { databaseList, project } =
storeToRefs(useSQLEditorStore());
const factorList = ref<StatefulFactor[]>(
cloneDeep(factorListInLocalStorage.value)
@@ -108,22 +106,6 @@ export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
);
});
- const filteredDatabaseList = computed(() => {
- if (filter.database) {
- return sortedDatabaseList.value.filter((database) => {
- return database.name === filter.database;
- });
- }
- if (filter.project || currentProject.value) {
- const projectName = filter.project ?? currentProject.value?.name;
- return sortedDatabaseList.value.filter((database) => {
- return database.project === projectName;
- });
- }
-
- return sortedDatabaseList.value;
- });
-
const filteredFactorList = computed(() => {
return factorList.value.filter((sf) => !sf.disabled).map((sf) => sf.factor);
});
@@ -190,7 +172,7 @@ export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
nodeListMapById.clear();
expandedKeys.value = [];
tree.value = buildTreeImpl(
- filteredDatabaseList.value,
+ sortedDatabaseList.value,
filteredFactorList.value
);
};
@@ -208,7 +190,7 @@ export const useSQLEditorTreeStore = defineStore("sqlEditorTree", () => {
() => showMissingQueryDatabases.value,
() => {
tree.value = buildTreeImpl(
- filteredDatabaseList.value,
+ sortedDatabaseList.value,
filteredFactorList.value
);
}
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index f6b155cdde..170f006443 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -11,25 +11,27 @@
<NTabs>
<template #suffix>
- <NButton
- v-if="allowSyncInstance"
- :loading="state.syncingSchema"
- @click.prevent="syncSchema"
- >
- <template v-if="state.syncingSchema">
- {{ $t("instance.syncing") }}
- </template>
- <template v-else>
- {{ $t("common.sync-now") }}
- </template>
- </NButton>
- <NButton
- v-if="allowCreateDatabase"
- type="primary"
- @click.prevent="createDatabase"
- >
- {{ $t("instance.new-database") }}
- </NButton>
+ <div class="space-x-2">
+ <NButton
+ v-if="allowSyncInstance"
+ :loading="state.syncingSchema"
+ @click.prevent="syncSchema"
+ >
+ <template v-if="state.syncingSchema">
+ {{ $t("instance.syncing") }}
+ </template>
+ <template v-else>
+ {{ $t("common.sync-now") }}
+ </template>
+ </NButton>
+ <NButton
+ v-if="allowCreateDatabase"
+ type="primary"
+ @click.prevent="createDatabase"
+ >
+ {{ $t("instance.new-database") }}
+ </NButton>
+ </div>
</template>
<NTabPane name="OVERVIEW" :tab="$t('common.overview')">
<InstanceForm class="-mt-2" :instance="instance">
diff --git a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
index b1552478c7..345a9fdcee 100644
--- a/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/AsidePanel.vue
@@ -86,7 +86,7 @@ const { width: containerWidth } = useElementSize(containerRef);
const hideProjects = useAppFeature("bb.feature.sql-editor.hide-projects");
const projectName = computed(() => {
- return editorStore.currentProject?.name ?? null;
+ return editorStore.project ?? null;
});
const allowAccessDefaultProject = computed(() => {
diff --git a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetList.vue b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetList.vue
index 4eac21d48f..bdeb93955f 100644
--- a/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetList.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/WorksheetPane/SheetList/SheetList.vue
@@ -25,7 +25,7 @@
import { orderBy } from "lodash-es";
import { computed, nextTick, watch } from "vue";
import { BBSpin } from "@/bbkit";
-import { useDatabaseV1Store, useFilterStore } from "@/store";
+import { useDatabaseV1Store } from "@/store";
import { isValidDatabaseName } from "@/types";
import {
useSheetContextByView,
@@ -42,21 +42,12 @@ const emit = defineEmits<{
(event: "ready"): void;
}>();
-const { filter } = useFilterStore();
const { isInitialized, isLoading, sheetList, fetchSheetList } =
useSheetContextByView(props.view);
const filteredWorksheetList = computed(() => {
let sheets = sheetList.value;
- // Only show those sheets that match the filtered database or are unconnected.
- if (filter.database) {
- sheets = sheets.filter(
- (worksheet) =>
- !worksheet.database || worksheet.database === filter.database
- );
- }
-
// Filter by keyword.
const keyword = (props.keyword ?? "").trim().toLowerCase();
if (keyword) {
diff --git a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseHoverPanel/DatabaseHoverPanel.vue b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseHoverPanel/DatabaseHoverPanel.vue
index 1a7743ce67..5dcab84400 100644
--- a/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseHoverPanel/DatabaseHoverPanel.vue
+++ b/frontend/src/views/sql-editor/ConnectionPanel/ConnectionPane/DatabaseHoverPanel/DatabaseHoverPanel.vue
@@ -31,7 +31,10 @@
{{ $t("common.instance") }}
</div>
<div class="text-main text-right">
- <InstanceV1Name :instance="database.instanceResource" :link="false" />
+ <InstanceV1Name
+ :instance="database.instanceResource"
+ :link="false"
+ />
</div>
</div>
<div v-if="!hasProjectContext" class="contents">
@@ -112,7 +115,7 @@ const database = computed(() => {
});
const hasProjectContext = computed(() => {
- return !!editorStore.currentProject;
+ return !!editorStore.project;
});
const displayPosition = computed(() => {
diff --git a/frontend/src/views/sql-editor/Sheet/context.ts b/frontend/src/views/sql-editor/Sheet/context.ts
index e96c53c2ff..7962a260ab 100644
--- a/frontend/src/views/sql-editor/Sheet/context.ts
+++ b/frontend/src/views/sql-editor/Sheet/context.ts
@@ -30,7 +30,7 @@ type SheetEvents = Emittery<{
const useSheetListByView = (viewMode: SheetViewMode) => {
const sheetStore = useWorkSheetStore();
- const { currentProject } = storeToRefs(useSQLEditorStore());
+ const { project } = storeToRefs(useSQLEditorStore());
const isInitialized = ref(false);
const isLoading = ref(false);
@@ -48,9 +48,7 @@ const useSheetListByView = (viewMode: SheetViewMode) => {
break;
}
return list.filter((worksheet) => {
- return (
- !currentProject.value || worksheet.project === currentProject.value.name
- );
+ return !project.value || worksheet.project === project.value;
});
});
diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vue
index a6d4d07276..93af377416 100644
--- a/frontend/src/views/sql-editor/TabList/TabList.vue
+++ b/frontend/src/views/sql-editor/TabList/TabList.vue
@@ -8,7 +8,7 @@
<Draggable
id="tab-list"
ref="tabListRef"
- v-model="filteredTabIdList"
+ v-model="tabStore.tabIdList"
item-key="id"
animation="300"
class="tab-list hide-scrollbar"
@@ -69,7 +69,6 @@ import ProfileDropdown from "@/components/ProfileDropdown.vue";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import {
useAppFeature,
- useFilterStore,
useSQLEditorStore,
useSQLEditorTabStore,
} from "@/store";
@@ -94,7 +93,6 @@ type LocalState = {
const tabStore = useSQLEditorTabStore();
const { t } = useI18n();
-const { filter } = useFilterStore();
const dialog = useDialog();
const state = reactive<LocalState>({
@@ -125,25 +123,6 @@ const hideSettingButton = computed(() => {
return false;
});
-const filteredTabIdList = computed(() => {
- // If a database is selected, only show tabs that are associated with the database.
- if (filter.database) {
- return tabStore.tabIdList.filter((id) => {
- const tab = tabStore.tabById(id);
- if (
- !tab?.connection.database ||
- tab.connection.database === filter.database
- ) {
- return true;
- } else {
- return false;
- }
- });
- }
-
- return tabStore.tabIdList;
-});
-
const handleSelectTab = async (tab: SQLEditorTab | undefined) => {
tabStore.setCurrentTabId(tab?.id ?? "");
};