Skip to content

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

chore: bring project kbar actions back for dashboard (#9580)

Liu Ji5d4163750470
diff --git a/frontend/src/components/KBar/useProjectActions.ts b/frontend/src/components/KBar/useProjectActions.ts
new file mode 100644
index 0000000000..d1e197d5a7
--- /dev/null
+++ b/frontend/src/components/KBar/useProjectActions.ts
@@ -0,0 +1,49 @@
+import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
+import { useCurrentUserV1, useProjectV1ListByCurrentUser } from "@/store";
+import { DEFAULT_PROJECT_ID } from "@/types";
+import { isMemberOfProjectV1, projectV1Slug } from "@/utils";
+
+export const useProjectActions = () => {
+ const { t } = useI18n();
+ const router = useRouter();
+ const me = useCurrentUserV1();
+ const { projectList } = useProjectV1ListByCurrentUser();
+
+ const accessibleProjectList = computed(() => {
+ return projectList.value.filter((project) => {
+ return (
+ project.uid != String(DEFAULT_PROJECT_ID) &&
+ // Only show projects that the user is a member of.
+ isMemberOfProjectV1(project.iamPolicy, me.value)
+ );
+ });
+ });
+
+ const sortedProjectList = computed(() => {
+ return [...accessibleProjectList.value].sort((a, b) =>
+ a.title.localeCompare(b.title)
+ );
+ });
+ const kbarActions = computed((): Action[] => {
+ const actions = sortedProjectList.value.map((project) =>
+ defineAction({
+ // here `id` looks like "bb.project.1234"
+ id: `bb.project.${project.uid}`,
+ section: t("common.projects"),
+ name: project.title,
+ keywords: ["project", project.key].join(" "),
+ data: {
+ tags: [project.key],
+ },
+ perform: () => {
+ router.push({ path: `/project/${projectV1Slug(project)}#overview` });
+ },
+ })
+ );
+ return actions;
+ });
+ useRegisterActions(kbarActions);
+};
diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vue
index 38c6a22bac..565697ce4f 100644
--- a/frontend/src/views/DashboardSidebar.vue
+++ b/frontend/src/views/DashboardSidebar.vue
@@ -106,6 +106,7 @@ import { useI18n } from "vue-i18n";
import { RouterLink, useRoute, useRouter } from "vue-router";
import BytebaseLogo from "@/components/BytebaseLogo.vue";
import { useGlobalDatabaseActions } from "@/components/KBar/useDatabaseActions";
+import { useProjectActions } from "@/components/KBar/useProjectActions";
import {
useCurrentUserV1,
useCurrentUserIamPolicy,
@@ -231,5 +232,6 @@ const navigationKbarActions = computed(() => {
});
useRegisterActions(navigationKbarActions);
+useProjectActions();
useGlobalDatabaseActions();
</script>