Skip to content

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

fix: databases list display in sidebar and dashboard (#7433)

boojack3f4f12e86f6c
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index c77b0ffa99..7bf5e3ff56 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -9,8 +9,8 @@
</template>
<script lang="ts" setup>
-import { computed, h, ref, watchEffect } from "vue";
-import { cloneDeep, uniqBy } from "lodash-es";
+import { computed, h, watchEffect } from "vue";
+import { cloneDeep } from "lodash-es";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
@@ -29,11 +29,11 @@ import {
useCurrentUserV1,
usePolicyV1Store,
useDBGroupStore,
+ useProjectV1ListByCurrentUser,
} from "@/store";
import { State } from "@/types/proto/v1/common";
import { TenantMode } from "@/types/proto/v1/project_service";
import {
- Policy,
PolicyResourceType,
PolicyType,
} from "@/types/proto/v1/org_policy_service";
@@ -45,26 +45,25 @@ const dbGroupStore = useDBGroupStore();
const router = useRouter();
const currentUserV1 = useCurrentUserV1();
const rawEnvironmentList = useEnvironmentV1List();
+const { projectList } = useProjectV1ListByCurrentUser();
-const policyList = ref<Policy[]>([]);
+// Reserve the environment list, put "Prod" to the top.
+const environmentList = computed(() =>
+ cloneDeep(rawEnvironmentList.value).reverse()
+);
+// Prepare policy list for checking if user has access to the database.
const preparePolicyList = () => {
- usePolicyV1Store()
- .fetchPolicies({
- policyType: PolicyType.WORKSPACE_IAM,
- resourceType: PolicyResourceType.WORKSPACE,
- })
- .then((list) => (policyList.value = list));
+ usePolicyV1Store().fetchPolicies({
+ policyType: PolicyType.WORKSPACE_IAM,
+ resourceType: PolicyResourceType.WORKSPACE,
+ });
};
watchEffect(preparePolicyList);
-// Reserve the environment list, put "Prod" to the top.
-const environmentList = computed(() =>
- cloneDeep(rawEnvironmentList.value).reverse()
-);
-
-const prepareList = () => {
+// Prepare database and database group list.
+const prepareDataList = () => {
// It will also be called when user logout
if (currentUserV1.value.name !== UNKNOWN_USER_NAME) {
databaseV1Store.searchDatabaseList({
@@ -74,7 +73,7 @@ const prepareList = () => {
}
};
-watchEffect(prepareList);
+watchEffect(prepareDataList);
// Use this to make the list reactive when project is transferred.
const databaseList = computed(() => {
@@ -136,28 +135,17 @@ const tenantDatabaseListByProject = computed((): BBOutlineItem[] => {
db.projectEntity.tenantMode === TenantMode.TENANT_MODE_ENABLED &&
db.project !== DEFAULT_PROJECT_V1_NAME
);
- // In case that each `db.project` is not reference equal
- // we run a uniq() on the list by project.id
- const projectList = uniqBy(
- [
- ...dbList.map((db) => db.projectEntity),
- ...dbGroupStore
- .getAllDatabaseGroupList()
- .map((dbGroup) => dbGroup.project),
- ],
- (project) => project.name
- );
- // Sort the list as what <ProjectListSidePanel /> does
- projectList.sort((a, b) => a.name.localeCompare(b.name));
- // Then group databaseList by project
- const databaseListGroupByProject = projectList.map((project) => {
+ const sortedProjectList = projectList.value
+ .map((p) => p)
+ .sort((a, b) => a.name.localeCompare(b.name));
+ const databaseListByProject = sortedProjectList.map((project) => {
const databaseList = dbList.filter((db) => db.project === project.name);
return {
project,
databaseList,
};
});
- const databaseGroupListByProject = projectList.map((project) => {
+ const databaseGroupListByProject = sortedProjectList.map((project) => {
const databaseGroupList = dbGroupStore.getDBGroupListByProjectName(
project.name
);
@@ -167,9 +155,9 @@ const tenantDatabaseListByProject = computed((): BBOutlineItem[] => {
};
});
- const outlineItemList: BBOutlineItem[] = projectList.map((project) => {
+ const outlineItemList: BBOutlineItem[] = sortedProjectList.map((project) => {
const databaseList =
- databaseListGroupByProject.find((item) => item.project === project)
+ databaseListByProject.find((item) => item.project === project)
?.databaseList || [];
const databaseGroupList =
databaseGroupListByProject.find((item) => item.project === project)
@@ -198,7 +186,9 @@ const tenantDatabaseListByProject = computed((): BBOutlineItem[] => {
} as BBOutlineItem;
});
- return outlineItemList;
+ return outlineItemList.filter(
+ (item) => item.childList && item.childList.length > 0
+ );
});
const mixedDatabaseList = computed(() => {
diff --git a/frontend/src/components/ProjectListSidePanel.vue b/frontend/src/components/ProjectListSidePanel.vue
index 0d26512074..c1c9977948 100644
--- a/frontend/src/components/ProjectListSidePanel.vue
+++ b/frontend/src/components/ProjectListSidePanel.vue
@@ -13,23 +13,16 @@ import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
-import { isMemberOfProjectV1, projectV1Slug } from "../utils";
+import { useProjectV1ListByCurrentUser } from "@/store";
+import { projectV1Slug } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
-import { useCurrentUserV1, useProjectV1ListByCurrentUser } from "@/store";
-import { DEFAULT_PROJECT_ID } from "@/types";
const { t } = useI18n();
const router = useRouter();
-const currentUserV1 = useCurrentUserV1();
const { projectList } = useProjectV1ListByCurrentUser();
const outlineItemList = computed((): BBOutlineItem[] => {
return projectList.value
- .filter(
- (project) =>
- project.uid != String(DEFAULT_PROJECT_ID) &&
- isMemberOfProjectV1(project.iamPolicy, currentUserV1.value)
- )
.map((project): BBOutlineItem => {
return {
id: project.uid,
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index f8b9602ef7..a1a80ca410 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -95,6 +95,7 @@ import {
useDatabaseV1Store,
useEnvironmentV1Store,
usePolicyV1Store,
+ useProjectV1ListByCurrentUser,
useUIStateStore,
} from "@/store";
import {
@@ -111,10 +112,11 @@ interface LocalState {
loading: boolean;
}
+const route = useRoute();
+const router = useRouter();
const uiStateStore = useUIStateStore();
const environmentV1Store = useEnvironmentV1Store();
-const router = useRouter();
-const route = useRoute();
+const { projectList } = useProjectV1ListByCurrentUser();
const state = reactive<LocalState>({
instanceFilter: String(UNKNOWN_ID),
@@ -170,14 +172,22 @@ const prepareDatabaseList = async () => {
const databaseV1List = await databaseV1Store.searchDatabaseList({
parent: "instances/-",
});
- state.databaseV1List = sortDatabaseV1List(databaseV1List);
+ state.databaseV1List = sortDatabaseV1List(databaseV1List).filter((db) =>
+ projectList.value.map((project) => project.name).includes(db.project)
+ );
state.loading = false;
}
};
const prepareDatabaseGroupList = async () => {
if (currentUserV1.value.name !== UNKNOWN_USER_NAME) {
- state.databaseGroupList = await dbGroupStore.fetchAllDatabaseGroupList();
+ state.databaseGroupList = (
+ await dbGroupStore.fetchAllDatabaseGroupList()
+ ).filter((dbGroup) =>
+ projectList.value
+ .map((project) => project.name)
+ .includes(dbGroup.project.name)
+ );
}
};