Skip to content

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

refactor: extract sidebar component (#8931)

ecmadao2fd5f398cdf7
diff --git a/frontend/src/components/CommonSidebar.vue b/frontend/src/components/CommonSidebar.vue
new file mode 100644
index 0000000000..4ed0e58505
--- /dev/null
+++ b/frontend/src/components/CommonSidebar.vue
@@ -0,0 +1,109 @@
+<template>
+ <nav class="flex-1 flex flex-col overflow-y-hidden">
+ <BytebaseLogo class="w-full px-4 shrink-0" />
+ <div class="space-y-1 flex-1 overflow-y-auto px-2 pb-4">
+ <button
+ v-if="showGoBack"
+ class="group shrink-0 flex items-center px-2 py-2 text-base leading-5 font-normal rounded-md text-gray-700 hover:opacity-80 focus:outline-none"
+ @click.prevent="goBack"
+ >
+ <heroicons-outline:chevron-left
+ class="mr-1 w-5 h-auto text-gray-500 group-hover:text-gray-500 group-focus:text-gray-600"
+ />
+ {{ $t("common.back") }}
+ </button>
+
+ <div v-for="(item, i) in filteredSidebarList" :key="i">
+ <router-link
+ v-if="type === 'route' && item.path"
+ :to="item.path"
+ class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
+ :class="getItemClass(item.path)"
+ >
+ <component :is="item.icon" class="mr-2 w-5 h-5 text-gray-500" />
+ {{ item.title }}
+ </router-link>
+ <div
+ v-else
+ class="group flex items-center px-2 py-2 text-sm leading-5 font-medium rounded-md text-gray-700"
+ :class="getItemClass(item.path)"
+ @click="$emit('select', item.path)"
+ >
+ <component :is="item.icon" class="mr-2 w-5 h-5 text-gray-500" />
+ {{ item.title }}
+ </div>
+ <div v-if="item.children" class="space-y-1">
+ <template v-for="(child, j) in item.children" :key="`${i}-${j}`">
+ <div
+ v-if="type === 'div'"
+ class="group w-full flex items-center pl-11 pr-2 py-1.5 rounded-md"
+ :class="getItemClass(child.path)"
+ @click="$emit('select', child.path)"
+ >
+ {{ child.title }}
+ </div>
+ <router-link
+ v-else
+ :to="child.path"
+ class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
+ :class="getItemClass(child.path)"
+ >
+ {{ child.title }}
+ </router-link>
+ </template>
+ </div>
+ </div>
+ </div>
+ </nav>
+</template>
+
+<script setup lang="ts">
+import { computed, VNode } from "vue";
+import { useRouter } from "vue-router";
+import { useRouterStore } from "@/store";
+
+export interface SidebarItem {
+ title: string;
+ path?: string;
+ icon: VNode;
+ hide?: boolean;
+ children?: {
+ title: string;
+ path: string;
+ hide?: boolean;
+ }[];
+}
+
+const props = withDefaults(
+ defineProps<{
+ itemList: SidebarItem[];
+ type: "route" | "div";
+ showGoBack?: boolean;
+ getItemClass: (path: string | undefined) => string[];
+ }>(),
+ {
+ showGoBack: false,
+ getItemClass: (_: string | undefined) => [],
+ }
+);
+
+defineEmits<{
+ (event: "select", path: string | undefined): void;
+}>();
+
+const routerStore = useRouterStore();
+const router = useRouter();
+
+const goBack = () => {
+ router.push(routerStore.backPath());
+};
+
+const filteredSidebarList = computed(() => {
+ return props.itemList
+ .map((item) => ({
+ ...item,
+ children: (item.children ?? []).filter((child) => !child.hide),
+ }))
+ .filter((item) => !item.hide && (!!item.path || item.children.length > 0));
+});
+</script>
diff --git a/frontend/src/components/Project/ProjectSidebar.vue b/frontend/src/components/Project/ProjectSidebar.vue
index 537dc179c8..30acf3a300 100644
--- a/frontend/src/components/Project/ProjectSidebar.vue
+++ b/frontend/src/components/Project/ProjectSidebar.vue
@@ -1,30 +1,10 @@
<template>
- <nav class="flex-1 flex flex-col overflow-y-hidden">
- <BytebaseLogo class="w-full px-4 shrink-0" />
- <div class="space-y-1 flex-1 overflow-y-auto px-2 pb-4">
- <div v-for="(item, index) in projectSidebarItemList" :key="index">
- <div
- class="group flex items-center px-2 py-2 text-sm leading-5 font-medium rounded-md text-gray-700"
- :class="getItemClass(item.hash)"
- @click="onSelect(item.hash)"
- >
- <component :is="item.icon" class="mr-2 w-5 h-5 text-gray-500" />
- {{ item.title }}
- </div>
- <div v-if="item.children" class="space-y-1">
- <div
- v-for="child in item.children"
- :key="child.hash"
- class="group w-full flex items-center pl-11 pr-2 py-1.5 rounded-md"
- :class="getItemClass(child.hash)"
- @click="onSelect(child.hash)"
- >
- {{ child.title }}
- </div>
- </div>
- </div>
- </div>
- </nav>
+ <CommonSidebar
+ type="div"
+ :item-list="projectSidebarItemList"
+ :get-item-class="getItemClass"
+ @select="(val: string | undefined) => onSelect(val as ProjectHash)"
+ />
</template>
<script setup lang="ts">
@@ -42,7 +22,7 @@ import {
import { computed, VNode, h, reactive, watch, nextTick } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute, useRouter } from "vue-router";
-import BytebaseLogo from "@/components/BytebaseLogo.vue";
+import { SidebarItem } from "@/components/CommonSidebar.vue";
import { useCurrentUserIamPolicy, useProjectV1Store } from "@/store";
import { DEFAULT_PROJECT_V1_NAME } from "@/types";
import { TenantMode } from "@/types/proto/v1/project_service";
@@ -53,7 +33,7 @@ const projectHashList = [
"database-groups",
"change-history",
"slow-query",
- "anomaly-center",
+ "anomalies",
"issues",
"branches",
"changelists",
@@ -69,16 +49,18 @@ const isProjectHash = (x: any): x is ProjectHash => projectHashList.includes(x);
interface ProjectSidebarItem {
title: string;
- hash?: ProjectHash;
+ path?: ProjectHash;
icon: VNode;
hide?: boolean;
children?: {
title: string;
- hash: ProjectHash;
+ path: ProjectHash;
hide?: boolean;
}[];
}
+const defaultHash: ProjectHash = "databases";
+
interface LocalState {
selectedHash: ProjectHash;
}
@@ -89,7 +71,7 @@ const router = useRouter();
const projectV1Store = useProjectV1Store();
const state = reactive<LocalState>({
- selectedHash: "databases",
+ selectedHash: defaultHash,
});
const projectSlug = computed(() => route.params.projectSlug as string);
@@ -106,7 +88,7 @@ const isTenantProject = computed((): boolean => {
return project.value.tenantMode === TenantMode.TENANT_MODE_ENABLED;
});
-const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
+const projectSidebarItemList = computed((): SidebarItem[] => {
const fullList: ProjectSidebarItem[] = [
{
title: t("common.database"),
@@ -114,37 +96,37 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
children: [
{
title: t("common.databases"),
- hash: "databases",
+ path: "databases",
},
{
title: t("common.groups"),
- hash: "database-groups",
+ path: "database-groups",
hide:
isTenantProject.value ||
!currentUserIamPolicy.isMemberOfProject(project.value.name),
},
{
title: t("common.change-history"),
- hash: "change-history",
+ path: "change-history",
hide:
isTenantProject.value ||
!currentUserIamPolicy.isMemberOfProject(project.value.name),
},
{
title: startCase(t("slow-query.slow-queries")),
- hash: "slow-query",
+ path: "slow-query",
hide: !currentUserIamPolicy.isMemberOfProject(project.value.name),
},
{
title: t("common.anomalies"),
- hash: "anomaly-center",
+ path: "anomalies",
hide: !currentUserIamPolicy.isMemberOfProject(project.value.name),
},
],
},
{
title: t("common.issues"),
- hash: "issues",
+ path: "issues",
icon: h(CircleDot),
hide:
isDefaultProject.value ||
@@ -154,7 +136,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
},
{
title: t("common.branches"),
- hash: "branches",
+ path: "branches",
icon: h(GitBranch),
hide:
isDefaultProject.value ||
@@ -164,7 +146,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
},
{
title: t("changelist.changelists"),
- hash: "changelists",
+ path: "changelists",
icon: h(PencilRuler),
hide:
isDefaultProject.value ||
@@ -174,7 +156,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
},
{
title: t("database.sync-schema.title"),
- hash: "sync-schema",
+ path: "sync-schema",
icon: h(RefreshCcw),
hide:
isDefaultProject.value ||
@@ -193,11 +175,11 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
children: [
{
title: t("common.gitops"),
- hash: "gitops",
+ path: "gitops",
},
{
title: t("common.webhooks"),
- hash: "webhook",
+ path: "webhook",
},
],
},
@@ -210,30 +192,25 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
children: [
{
title: t("common.members"),
- hash: "members",
+ path: "members",
},
{
title: t("common.activities"),
- hash: "activities",
+ path: "activities",
},
],
},
{
title: t("common.setting"),
icon: h(Settings),
- hash: "setting",
+ path: "setting",
hide:
isDefaultProject.value ||
!currentUserIamPolicy.isMemberOfProject(project.value.name),
},
];
- return fullList
- .map((item) => ({
- ...item,
- children: (item.children ?? []).filter((child) => !child.hide),
- }))
- .filter((item) => !item.hide && (!!item.hash || item.children.length > 0));
+ return fullList as SidebarItem[];
});
const getItemClass = (hash: string | undefined) => {
@@ -248,7 +225,7 @@ const getItemClass = (hash: string | undefined) => {
};
const onSelect = (hash: ProjectHash | undefined) => {
- if (!hash) {
+ if (!hash || !isProjectHash(hash)) {
return;
}
state.selectedHash = hash;
@@ -261,9 +238,9 @@ const onSelect = (hash: ProjectHash | undefined) => {
const selectProjectTabOnHash = () => {
const { name, hash } = router.currentRoute.value;
if (name == "workspace.project.detail") {
- let targetHash = (hash || "databases").replace(/^#?/g, "");
+ let targetHash = hash.replace(/^#?/g, "");
if (!isProjectHash(targetHash)) {
- targetHash = "databases";
+ targetHash = defaultHash;
}
onSelect(targetHash as ProjectHash);
} else if (
diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vue
index 59d744c2a9..f0f7a9bff4 100644
--- a/frontend/src/views/ProjectDetail.vue
+++ b/frontend/src/views/ProjectDetail.vue
@@ -26,7 +26,7 @@
<template v-if="hash === 'slow-query'">
<ProjectSlowQueryPanel :project="project" />
</template>
- <template v-if="hash === 'anomaly-center'">
+ <template v-if="hash === 'anomalies'">
<AnomalyCenterDashboard :project="project" :selected-tab="'database'" />
</template>
<template v-if="hash === 'activities'">
diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vue
index 41f5db4b93..aba88d7584 100644
--- a/frontend/src/views/SettingSidebar.vue
+++ b/frontend/src/views/SettingSidebar.vue
@@ -1,182 +1,35 @@
<template>
- <!-- Navigation -->
- <nav class="flex-1 flex flex-col overflow-y-hidden">
- <BytebaseLogo class="w-full px-4 shrink-0" />
- <div class="space-y-1 flex-1 overflow-y-auto px-2 pb-4">
- <button
- class="group shrink-0 flex items-center px-2 py-2 text-base leading-5 font-normal rounded-md text-gray-700 hover:opacity-80 focus:outline-none"
- @click.prevent="goBack"
- >
- <heroicons-outline:chevron-left
- class="mr-1 w-5 h-auto text-gray-500 group-hover:text-gray-500 group-focus:text-gray-600"
- />
- {{ $t("common.back") }}
- </button>
- <div>
- <div
- class="group flex items-center px-2 py-2 text-sm leading-5 font-medium rounded-md text-gray-700"
- >
- <heroicons-solid:user-circle class="mr-3 w-5 h-5" />
- {{ $t("settings.sidebar.account") }}
- </div>
- <div class="space-y-1">
- <router-link
- to="/setting/profile"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("settings.sidebar.profile") }}</router-link
- >
- </div>
- </div>
- <div>
- <div
- class="group flex items-center px-2 py-2 text-sm leading-5 font-medium rounded-md text-gray-700"
- >
- <heroicons-solid:office-building class="mr-3 w-5 h-5" />
- {{ $t("settings.sidebar.workspace") }}
- </div>
- <div class="space-y-1">
- <router-link
- to="/setting/general"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >
- {{ $t("settings.sidebar.general") }}
- </router-link>
- <router-link
- to="/setting/member"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-2"
- :class="[
- route.name === 'workspace.profile' &&
- 'router-link-active bg-link-hover',
- ]"
- >{{ $t("settings.sidebar.members") }}</router-link
- >
- <router-link
- to="/setting/role"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("settings.sidebar.custom-roles") }}</router-link
- >
- <router-link
- v-if="showProjectItem"
- to="/setting/project"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("common.projects") }}</router-link
- >
- <router-link
- to="/setting/subscription"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("settings.sidebar.subscription") }}</router-link
- >
- <router-link
- v-if="showDebugLogItem"
- to="/setting/debug-log"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("settings.sidebar.debug-log") }}</router-link
- >
- </div>
- </div>
- <div>
- <div
- class="group flex items-center px-2 py-2 text-sm leading-5 font-medium rounded-md text-gray-700"
- >
- <heroicons-solid:shield-check class="mr-3 w-5 h-5" />
- {{ $t("settings.sidebar.security-and-policy") }}
- </div>
- <div class="space-y-1">
- <router-link
- to="/setting/sql-review"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("sql-review.title") }}</router-link
- >
- <router-link
- to="/setting/slow-query"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5 capitalize"
- >{{ $t("slow-query.self") }}</router-link
- >
- <router-link
- to="/setting/schema-template"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5 capitalize"
- >{{ $t("schema-template.self") }}</router-link
- >
- <router-link
- to="/setting/risk-center"
- class="outline-item group w-full flex items-center truncate pl-11 pr-2 py-1.5"
- >
- {{ $t("custom-approval.risk.risk-center") }}
- </router-link>
- <router-link
- to="/setting/custom-approval"
- class="outline-item group w-full flex items-center truncate pl-11 pr-2 py-1.5"
- >
- {{ $t("custom-approval.self") }}
- </router-link>
- <router-link
- v-if="showSensitiveDataItem"
- to="/setting/sensitive-data"
- class="outline-item group w-full flex items-center truncate pl-11 pr-2 py-1.5"
- >
- {{ $t("settings.sidebar.sensitive-data") }}
- </router-link>
- <router-link
- v-if="showAccessControlItem"
- to="/setting/access-control"
- class="outline-item group w-full flex items-center truncate pl-11 pr-2 py-1.5"
- >
- {{ $t("settings.sidebar.access-control") }}
- </router-link>
- <router-link
- v-if="showAuditLogItem"
- to="/setting/audit-log"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("settings.sidebar.audit-log") }}</router-link
- >
- </div>
- </div>
- <div v-if="showIntegrationSection">
- <div
- class="group flex items-center px-2 py-2 text-sm leading-5 font-medium rounded-md text-gray-700"
- >
- <heroicons-solid:link class="mr-3 w-5 h-5" />
- {{ $t("settings.sidebar.integration") }}
- </div>
- <div class="space-y-1">
- <router-link
- v-if="showVCSItem"
- to="/setting/gitops"
- class="outline-item group w-full flex items-center pl-11 pr-2 py-1.5"
- >{{ $t("settings.sidebar.gitops") }}</router-link
- >
- <router-link
- v-if="showSSOItem"
- to="/setting/sso"
- class="outline-item group w-full flex items-center truncate pl-11 pr-2 py-1.5"
- >
- {{ $t("settings.sidebar.sso") }}
- </router-link>
- <router-link
- v-if="showMailDeliveryItem"
- to="/setting/mail-delivery"
- class="outline-item group w-full flex items-center truncate pl-11 pr-2 py-1.5"
- >
- {{ $t("settings.sidebar.mail-delivery") }}
- </router-link>
- </div>
- </div>
- </div>
- </nav>
+ <CommonSidebar
+ type="route"
+ :show-go-back="true"
+ :item-list="(settingSidebarItemList as SidebarItem[])"
+ :get-item-class="getItemClass"
+ />
</template>
<script lang="ts" setup>
-import { computed } from "vue";
-import { useRoute, useRouter } from "vue-router";
-import BytebaseLogo from "@/components/BytebaseLogo.vue";
-import { useCurrentUserV1, useRouterStore } from "@/store";
+import { UserCircle, Building, ShieldCheck, Link } from "lucide-vue-next";
+import { computed, h } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRoute } from "vue-router";
+import { SidebarItem } from "@/components/CommonSidebar.vue";
+import { useCurrentUserV1 } from "@/store";
import { hasWorkspacePermissionV1 } from "../utils";
-const routerStore = useRouterStore();
+const { t } = useI18n();
const route = useRoute();
-const router = useRouter();
const currentUserV1 = useCurrentUserV1();
+const getItemClass = (path: string | undefined) => {
+ const list = [];
+ if (route.name === "workspace.profile") {
+ if (path === "/setting/member") {
+ list.push("router-link-active", "bg-link-hover");
+ }
+ }
+ return list;
+};
+
const showProjectItem = computed((): boolean => {
return hasWorkspacePermissionV1(
"bb.permission.workspace.manage-project",
@@ -237,7 +90,112 @@ const showMailDeliveryItem = computed((): boolean => {
);
});
-const goBack = () => {
- router.push(routerStore.backPath());
-};
+const settingSidebarItemList = computed((): SidebarItem[] => {
+ return [
+ {
+ title: t("settings.sidebar.account"),
+ icon: h(UserCircle),
+ children: [
+ {
+ title: t("settings.sidebar.profile"),
+ path: "/setting/profile",
+ },
+ ],
+ },
+ {
+ title: t("settings.sidebar.workspace"),
+ icon: h(Building),
+ children: [
+ {
+ title: t("settings.sidebar.general"),
+ path: "/setting/general",
+ },
+ {
+ title: t("settings.sidebar.members"),
+ path: "/setting/member",
+ },
+ {
+ title: t("settings.sidebar.custom-roles"),
+ path: "/setting/role",
+ },
+ {
+ title: t("common.projects"),
+ path: "/setting/project",
+ hide: !showProjectItem.value,
+ },
+ {
+ title: t("settings.sidebar.subscription"),
+ path: "/setting/subscription",
+ },
+ {
+ title: t("settings.sidebar.debug-log"),
+ path: "/setting/debug-log",
+ hide: !showDebugLogItem.value,
+ },
+ ],
+ },
+ {
+ title: t("settings.sidebar.security-and-policy"),
+ icon: h(ShieldCheck),
+ children: [
+ {
+ title: t("sql-review.title"),
+ path: "/setting/sql-review",
+ },
+ {
+ title: t("slow-query.self"),
+ path: "/setting/slow-query",
+ },
+ {
+ title: t("schema-template.self"),
+ path: "/setting/schema-template",
+ },
+ {
+ title: t("custom-approval.risk.risk-center"),
+ path: "/setting/risk-center",
+ },
+ {
+ title: t("custom-approval.self"),
+ path: "/setting/custom-approval",
+ },
+ {
+ title: t("settings.sidebar.sensitive-data"),
+ path: "/setting/sensitive-data",
+ hide: !showSensitiveDataItem.value,
+ },
+ {
+ title: t("settings.sidebar.access-control"),
+ path: "/setting/access-control",
+ hide: !showAccessControlItem.value,
+ },
+ {
+ title: t("settings.sidebar.audit-log"),
+ path: "/setting/audit-log",
+ hide: !showAuditLogItem.value,
+ },
+ ],
+ },
+ {
+ title: t("settings.sidebar.integration"),
+ icon: h(Link),
+ hide: !showIntegrationSection.value,
+ children: [
+ {
+ title: t("settings.sidebar.gitops"),
+ path: "/setting/gitops",
+ },
+ {
+ title: t("settings.sidebar.sso"),
+ hide: !showSSOItem.value,
+ path: "/setting/sso",
+ },
+ {
+ title: t("settings.sidebar.mail-delivery"),
+ hide: !showMailDeliveryItem.value,
+ path: "/setting/mail-delivery",
+ },
+ ],
+ },
+ ];
+});
</script>