Skip to content

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

chore: resolve project ui issues (#9619)

ecmadao0c9d5152685f
diff --git a/frontend/src/components/CommonSidebar.vue b/frontend/src/components/CommonSidebar.vue
index d1945d76d8..d499679144 100644
--- a/frontend/src/components/CommonSidebar.vue
+++ b/frontend/src/components/CommonSidebar.vue
@@ -4,8 +4,8 @@
<div class="flex-1 overflow-y-auto px-2">
<div v-for="(item, i) in filteredSidebarList" :key="i">
<router-link
- v-if="item.type === 'route' && item.path"
- :to="item.path"
+ v-if="item.type === 'route'"
+ :to="item.path ?? ''"
class="outline-item group w-full font-medium flex items-center px-2 py-1.5 !text-base"
:class="getItemClass(item.path)"
>
@@ -28,6 +28,16 @@
<ChevronDown v-else class="w-4 h-4" />
</div>
</div>
+ <a
+ v-if="item.type === 'link'"
+ class="group flex items-center px-2 py-1.5 leading-5 font-medium rounded-md text-gray-700 outline-item !text-base"
+ :class="getItemClass(item.path)"
+ :href="`#${item.path}`"
+ @click="$emit('select', item.path)"
+ >
+ <component :is="item.icon" class="mr-2 w-5 h-5 text-gray-500" />
+ {{ item.title }}
+ </a>
<div
v-else-if="item.type === 'divider'"
class="border-t border-gray-300 my-2"
@@ -37,14 +47,15 @@
class=""
>
<template v-for="(child, j) in item.children" :key="`${i}-${j}`">
- <div
- v-if="child.type === 'div'"
+ <a
+ v-if="child.type === 'link'"
class="group w-full flex items-center pl-11 pr-2 py-1.5 rounded-md outline-item"
:class="getItemClass(child.path)"
+ :href="`#${child.path}`"
@click="$emit('select', child.path)"
>
{{ child.title }}
- </div>
+ </a>
<router-link
v-else-if="child.type === 'route'"
:to="child.path"
@@ -69,12 +80,12 @@ export interface SidebarItem {
path?: string;
icon?: VNode;
hide?: boolean;
- type: "route" | "div" | "divider";
+ type: "route" | "div" | "divider" | "link";
children?: {
title: string;
path: string;
hide?: boolean;
- type: "route" | "div" | "divider";
+ type: "route" | "link" | "divider";
}[];
}
diff --git a/frontend/src/components/Project/ProjectSidebar.vue b/frontend/src/components/Project/ProjectSidebar.vue
index 00f27464d4..c3c3fd1532 100644
--- a/frontend/src/components/Project/ProjectSidebar.vue
+++ b/frontend/src/components/Project/ProjectSidebar.vue
@@ -3,13 +3,11 @@
:key="'project'"
:item-list="projectSidebarItemList"
:get-item-class="getItemClass"
- @select="(val: string | undefined) => onSelect(val as ProjectHash)"
/>
</template>
<script setup lang="ts">
import { defineAction, useRegisterActions } from "@bytebase/vue-kbar";
-import { useLocalStorage } from "@vueuse/core";
import { startCase } from "lodash-es";
import {
Database,
@@ -54,12 +52,12 @@ const isProjectHash = (x: any): x is ProjectHash => projectHashList.includes(x);
interface ProjectSidebarItem extends SidebarItem {
title: string;
path?: ProjectHash;
- type: "div";
+ type: "div" | "link";
children?: {
title: string;
path: ProjectHash;
hide?: boolean;
- type: "div";
+ type: "link";
}[];
}
@@ -94,28 +92,10 @@ const params = computed(() => {
const { project } = useCurrentProject(params);
-const cachedLastPage = computed(() => {
- const cache = useLocalStorage<ProjectHash>(
- `bb.project.${projectSlugV1(project.value)}.page`,
- "databases"
- );
- return cache;
-});
-
const defaultHash = computed((): ProjectHash => {
- return cachedLastPage.value.value;
+ return "databases";
});
-watch(
- () => state.selectedHash,
- (hash) => (cachedLastPage.value.value = hash)
-);
-
-watch(
- () => cachedLastPage.value,
- (cache) => (state.selectedHash = cache.value)
-);
-
const currentUserIamPolicy = useCurrentUserIamPolicy();
const isDefaultProject = computed((): boolean => {
@@ -136,12 +116,12 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
{
title: t("common.databases"),
path: "databases",
- type: "div",
+ type: "link",
},
{
title: t("common.groups"),
path: "database-groups",
- type: "div",
+ type: "link",
hide:
!isTenantProject.value ||
!currentUserIamPolicy.isMemberOfProject(project.value.name),
@@ -149,7 +129,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
{
title: t("common.change-history"),
path: "change-history",
- type: "div",
+ type: "link",
hide:
isTenantProject.value ||
!currentUserIamPolicy.isMemberOfProject(project.value.name),
@@ -157,13 +137,13 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
{
title: startCase(t("slow-query.slow-queries")),
path: "slow-query",
- type: "div",
+ type: "link",
hide: !currentUserIamPolicy.isMemberOfProject(project.value.name),
},
{
title: t("common.anomalies"),
path: "anomalies",
- type: "div",
+ type: "link",
hide: !currentUserIamPolicy.isMemberOfProject(project.value.name),
},
],
@@ -172,7 +152,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
title: t("common.issues"),
path: "issues",
icon: h(CircleDot),
- type: "div",
+ type: "link",
hide:
isDefaultProject.value ||
!currentUserIamPolicy.allowToChangeDatabaseOfProject(
@@ -183,7 +163,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
title: t("common.branches"),
path: "branches",
icon: h(GitBranch),
- type: "div",
+ type: "link",
hide:
isDefaultProject.value ||
!currentUserIamPolicy.allowToChangeDatabaseOfProject(
@@ -194,7 +174,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
title: t("changelist.changelists"),
path: "changelists",
icon: h(PencilRuler),
- type: "div",
+ type: "link",
hide:
isDefaultProject.value ||
!currentUserIamPolicy.allowToChangeDatabaseOfProject(
@@ -205,7 +185,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
title: t("database.sync-schema.title"),
path: "sync-schema",
icon: h(RefreshCcw),
- type: "div",
+ type: "link",
hide:
isDefaultProject.value ||
!currentUserIamPolicy.allowToChangeDatabaseOfProject(
@@ -225,12 +205,12 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
{
title: t("common.gitops"),
path: "gitops",
- type: "div",
+ type: "link",
},
{
title: t("common.webhooks"),
path: "webhook",
- type: "div",
+ type: "link",
},
],
},
@@ -245,12 +225,12 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
{
title: t("common.members"),
path: "members",
- type: "div",
+ type: "link",
},
{
title: t("common.activities"),
path: "activities",
- type: "div",
+ type: "link",
},
],
},
@@ -258,7 +238,7 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
title: t("common.setting"),
icon: h(Settings),
path: "setting",
- type: "div",
+ type: "link",
hide:
isDefaultProject.value ||
!currentUserIamPolicy.isMemberOfProject(project.value.name),
@@ -285,10 +265,15 @@ const onSelect = (hash: ProjectHash | undefined) => {
if (!hash || !isProjectHash(hash)) {
return;
}
- state.selectedHash = hash;
+ let validHash = hash || defaultHash.value;
+ const tab = flattenNavigationItems.value.find((item) => item.path === hash);
+ if (!tab || tab.hide) {
+ validHash = defaultHash.value;
+ }
+ state.selectedHash = validHash;
router.replace({
name: "workspace.project.detail",
- hash: `#${hash}`,
+ hash: `#${validHash}`,
query: route.query,
params: {
projectSlug: props.projectSlug || projectSlugV1(project.value),
@@ -344,8 +329,8 @@ watch(
}
);
-const navigationKbarActions = computed(() => {
- const navigationItems = projectSidebarItemList.value.flatMap<{
+const flattenNavigationItems = computed(() => {
+ return projectSidebarItemList.value.flatMap<{
path: ProjectHash;
title: string;
hide?: boolean;
@@ -365,8 +350,10 @@ const navigationKbarActions = computed(() => {
},
];
});
+});
- const actions = navigationItems.map((item) =>
+const navigationKbarActions = computed(() => {
+ const actions = flattenNavigationItems.value.map((item) =>
defineAction({
id: `bb.navigation.project.${project.value.uid}.${item.path}`,
name: item.title,
diff --git a/frontend/src/components/Project/ProjectSwitchModal.vue b/frontend/src/components/Project/ProjectSwitchModal.vue
index 88acfaea29..f0720d03cd 100644
--- a/frontend/src/components/Project/ProjectSwitchModal.vue
+++ b/frontend/src/components/Project/ProjectSwitchModal.vue
@@ -23,6 +23,7 @@
</div>
<ProjectV1Table
:project-list="filteredProjectList"
+ :current-project="currentProject"
class="border"
@click="$emit('dismiss')"
/>
@@ -43,7 +44,12 @@ import { computed, reactive } from "vue";
import { SearchBox, ProjectV1Table } from "@/components/v2";
import { Drawer } from "@/components/v2";
import { useProjectV1ListByCurrentUser } from "@/store";
-import { DEFAULT_PROJECT_ID } from "@/types";
+import {
+ DEFAULT_PROJECT_ID,
+ UNKNOWN_PROJECT_NAME,
+ EMPTY_PROJECT_NAME,
+ ComposedProject,
+} from "@/types";
import { filterProjectV1ListByKeyword } from "@/utils";
interface LocalState {
@@ -51,6 +57,10 @@ interface LocalState {
showCreateDrawer: boolean;
}
+const props = defineProps<{
+ project?: ComposedProject;
+}>();
+
const emit = defineEmits<{
(event: "dismiss"): void;
}>();
@@ -68,6 +78,16 @@ const filteredProjectList = computed(() => {
return filterProjectV1ListByKeyword(list, state.searchText);
});
+const currentProject = computed(() => {
+ if (
+ props.project?.name === UNKNOWN_PROJECT_NAME ||
+ props.project?.name === EMPTY_PROJECT_NAME
+ ) {
+ return undefined;
+ }
+ return props.project;
+});
+
const onCreate = () => {
state.showCreateDrawer = false;
emit("dismiss");
diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vue
index 065b745de2..821f05a254 100644
--- a/frontend/src/components/v2/Model/ProjectV1Table.vue
+++ b/frontend/src/components/v2/Model/ProjectV1Table.vue
@@ -7,6 +7,12 @@
@click-row="clickProject"
>
<template #item="{ item: project }: ProjectGridRow">
+ <div v-if="currentProject" class="bb-grid-cell">
+ <CheckIcon
+ v-if="currentProject.name === project.name"
+ class="w-4 text-accent"
+ />
+ </div>
<div class="bb-grid-cell text-gray-500">
<span class="flex flex-row items-center space-x-1">
<span>{{ project.key }}</span>
@@ -24,6 +30,7 @@
</template>
<script lang="ts" setup>
+import { CheckIcon } from "lucide-vue-next";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
@@ -33,8 +40,9 @@ import { projectV1Slug } from "@/utils";
export type ProjectGridRow = BBGridRow<Project>;
-defineProps<{
+const props = defineProps<{
projectList: Project[];
+ currentProject?: Project;
}>();
const emit = defineEmits<{
@@ -43,16 +51,25 @@ const emit = defineEmits<{
const router = useRouter();
const { t } = useI18n();
-const columnList = computed((): BBGridColumn[] => [
- {
- title: t("project.table.key"),
- width: "minmax(auto, 25%)",
- },
- {
- title: t("project.table.name"),
- width: "1fr",
- },
-]);
+const columnList = computed((): BBGridColumn[] => {
+ const list = [
+ {
+ title: t("project.table.key"),
+ width: "minmax(min-content, 25%)",
+ },
+ {
+ title: t("project.table.name"),
+ width: "minmax(min-content, auto)",
+ },
+ ];
+ if (props.currentProject) {
+ list.unshift({
+ title: "",
+ width: "minmax(min-content, 3rem)",
+ });
+ }
+ return list;
+});
const clickProject = function (
project: Project,
@@ -60,7 +77,9 @@ const clickProject = function (
row: number,
e: MouseEvent
) {
- const url = `/project/${projectV1Slug(project)}`;
+ const url = `/project/${projectV1Slug(project)}${
+ router.currentRoute.value.hash
+ }`;
if (e.ctrlKey || e.metaKey) {
window.open(url, "_blank");
} else {
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index b0bcffe6ca..f08996de8a 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -82,6 +82,7 @@
<ProjectSwitchModal
v-if="state.showProjectModal"
+ :project="project"
@dismiss="state.showProjectModal = false"
/>
</template>