Skip to content

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

feat(frontend): better kbar experience (#131)

Liu Ji863f479485c8
diff --git a/frontend/package.json b/frontend/package.json
index 371f3dbcd6..1f837fe97f 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -11,7 +11,7 @@
"lint:fix": "eslint --cache --ext .js,.ts,.tsx,.vue --fix src"
},
"dependencies": {
- "@bytebase/vue-kbar": "^0.1.2",
+ "@bytebase/vue-kbar": "^0.1.4",
"@soerenmartius/vue3-clipboard": "^0.1.2",
"@tailwindcss/forms": "^0.2.1",
"@tailwindcss/typography": "^0.4.0",
diff --git a/frontend/src/components/BookmarkListSidePanel.vue b/frontend/src/components/BookmarkListSidePanel.vue
index ba8dc71b92..604d71e119 100644
--- a/frontend/src/components/BookmarkListSidePanel.vue
+++ b/frontend/src/components/BookmarkListSidePanel.vue
@@ -19,10 +19,12 @@ import { useStore } from "vuex";
import { UNKNOWN_ID } from "../types";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { useRouter } from "vue-router";
+import { useI18n } from "vue-i18n";
export default {
name: "BookmarkListSidePanel",
setup() {
+ const { t } = useI18n();
const store = useStore();
const router = useRouter();
@@ -53,7 +55,7 @@ export default {
defineAction({
// here `id` looks like "bb.bookmark.12345"
id: `bb.bookmark.${item.id}`,
- section: "Bookmarks",
+ section: t("common.bookmarks"),
name: item.name,
keywords: "bookmark",
perform: () => {
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index 99eac78efb..074c809d31 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -17,10 +17,12 @@ import { databaseSlug, environmentName } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { useRouter } from "vue-router";
+import { useI18n } from "vue-i18n";
export default {
name: "DatabaseListSidePanel",
setup() {
+ const { t } = useI18n();
const store = useStore();
const router = useRouter();
@@ -90,9 +92,11 @@ export default {
// `db.id` is global unique, so need not to specify `env.id`
// so here `id` looks like "bb.database.1234"
id: `bb.database.${db.id}`,
- section: "Databases",
+ section: t("common.databases"),
name: db.name,
- keywords: "database db",
+ // env.name is also a keyword to provide better search
+ // e.g. "Blog" under "staged" now can be searched by "bl st"
+ keywords: `database db ${env.name}`,
data: {
tags: [env.name],
},
diff --git a/frontend/src/components/KBar/KBarFooter.vue b/frontend/src/components/KBar/KBarFooter.vue
index 6a9a859deb..e6aefec5f8 100644
--- a/frontend/src/components/KBar/KBarFooter.vue
+++ b/frontend/src/components/KBar/KBarFooter.vue
@@ -14,7 +14,7 @@
</g>
</svg>
</kbd>
- <span>to perform</span>
+ <span>{{ $t("kbar.help.perform") }}</span>
</div>
<div class="key">
<kbd>
@@ -43,7 +43,23 @@
</g>
</svg>
</kbd>
- <span>to navigate</span>
+ <span>{{ $t("kbar.help.navigate") }}</span>
+ </div>
+ <div v-if="isDeepAction" class="key">
+ <kbd>
+ <svg width="15" height="15" class="transform rotate-90">
+ <g
+ fill="none"
+ stroke="currentColor"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="1.2"
+ >
+ <path d="M7.5 3.5v8M10.5 8.5l-3 3-3-3"></path>
+ </g>
+ </svg>
+ </kbd>
+ <span>{{ $t("kbar.help.back") }}</span>
</div>
<div class="key">
<kbd>
@@ -61,16 +77,26 @@
</g>
</svg>
</kbd>
- <span>to close</span>
+ <span>{{ $t("kbar.help.close") }}</span>
</div>
</footer>
</template>
<script lang="ts">
-import { defineComponent } from "vue";
+import { useKBarState } from "@bytebase/vue-kbar";
+import { computed, defineComponent } from "vue";
export default defineComponent({
name: "KBarFooter",
+ setup() {
+ const state = useKBarState();
+
+ const isDeepAction = computed(() => {
+ return !!state.value.currentRootActionId;
+ });
+
+ return { isDeepAction };
+ },
});
</script>
diff --git a/frontend/src/components/KBar/KBarHelper.vue b/frontend/src/components/KBar/KBarHelper.vue
index bb5d1b10ff..8edfcde8d6 100644
--- a/frontend/src/components/KBar/KBarHelper.vue
+++ b/frontend/src/components/KBar/KBarHelper.vue
@@ -6,6 +6,7 @@
import { useKBarHandler } from "@bytebase/vue-kbar";
import { defineComponent, watch } from "vue";
import { useRoute } from "vue-router";
+import { useRecentVisit } from "./useRecentVisit";
export default defineComponent({
name: "KBarFooter",
@@ -19,6 +20,8 @@ export default defineComponent({
handler.value.hide();
}
);
+
+ useRecentVisit();
},
});
</script>
diff --git a/frontend/src/components/KBar/KBarWrapper.vue b/frontend/src/components/KBar/KBarWrapper.vue
index f78ed0cbd6..fbad961e9d 100644
--- a/frontend/src/components/KBar/KBarWrapper.vue
+++ b/frontend/src/components/KBar/KBarWrapper.vue
@@ -1,16 +1,19 @@
<template>
- <KBarProvider :actions="globalActions" :options="{ disabled }">
+ <KBarProvider
+ :actions="globalActions"
+ :options="{ placeholder, disabled, compare }"
+ >
<KBarPortal>
<KBarPositioner class="mask">
<KBarAnimator class="container">
<KBarSearch class="searchbox" />
- <KBarHelper />
<RenderResults />
<KBarFooter />
</KBarAnimator>
</KBarPositioner>
</KBarPortal>
+ <KBarHelper />
<slot />
</KBarProvider>
</template>
@@ -25,11 +28,13 @@ import {
KBarSearch,
defineAction,
} from "@bytebase/vue-kbar";
+import { compareAction as compare } from "./utils";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import RenderResults from "./RenderResults.vue";
import KBarHelper from "./KBarHelper.vue";
import KBarFooter from "./KBarFooter.vue";
+import { useI18n } from "vue-i18n";
export default defineComponent({
name: "KBarWrapper",
@@ -44,9 +49,12 @@ export default defineComponent({
KBarFooter,
},
setup() {
+ const { t } = useI18n();
const store = useStore();
const router = useRouter();
+ const placeholder = computed(() => t("kbar.options.placeholder"));
+
const disabled = computed(() => {
const currentUser = store.getters["auth/currentUser"]();
// totally disable kbar when not logged in
@@ -54,26 +62,30 @@ export default defineComponent({
return !currentUser || currentUser.id < 0;
});
- const globalActions = [
+ const globalActions = computed(() => [
defineAction({
id: "bb.navigation.home",
name: "Home",
shortcut: ["g", "h"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation",
perform: () => router.push({ name: "workspace.home" }),
}),
defineAction({
id: "bb.navigation.anomaly-center",
name: "Anomaly Center",
shortcut: ["g", "a", "c"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation",
perform: () => router.push({ name: "workspace.anomaly-center" }),
}),
- ];
+ ]);
return {
globalActions,
+ placeholder,
disabled,
+ compare,
};
},
});
diff --git a/frontend/src/components/KBar/RenderResults.vue b/frontend/src/components/KBar/RenderResults.vue
index c5bccbfbe5..3030d036d6 100644
--- a/frontend/src/components/KBar/RenderResults.vue
+++ b/frontend/src/components/KBar/RenderResults.vue
@@ -11,6 +11,10 @@
<div v-else class="item" :class="{ active }" :data-index="index">
<div class="content">
<div class="main">
+ <span v-if="isDeepAction(item)" class="parent">
+ {{ findParent(item).name }}
+ </span>
+
<span>{{ item.name }}</span>
<span v-for="(tag, i) in item.data?.tags" :key="i" class="tag">
@@ -32,19 +36,35 @@
<script lang="ts">
import { defineComponent } from "vue";
-import { useKBarMatches, KBarResults } from "@bytebase/vue-kbar";
+import {
+ useKBarMatches,
+ KBarResults,
+ ActionImpl,
+ useKBarState,
+} from "@bytebase/vue-kbar";
export default defineComponent({
name: "RenderResults",
components: { KBarResults },
setup() {
+ const state = useKBarState();
const matches = useKBarMatches();
const itemHeight = (params: { item: any; index: number }) => {
if (typeof params.item === "string") return 32;
return 48;
};
- return { matches, itemHeight };
+ const isDeepAction = (action: ActionImpl): boolean => {
+ return (
+ !!action.parent && action.parent !== state.value.currentRootActionId
+ );
+ };
+
+ const findParent = (child: ActionImpl): ActionImpl => {
+ return state.value.actions.find((action) => action.id === child.parent)!;
+ };
+
+ return { matches, itemHeight, isDeepAction, findParent };
},
});
</script>
@@ -71,6 +91,13 @@ export default defineComponent({
.subtitle {
@apply text-xs text-gray-500;
}
+.parent {
+ @apply text-gray-500;
+}
+.parent::after {
+ content: "›";
+ @apply text-gray-500 mx-1;
+}
.shortcut {
@apply grid grid-flow-col gap-1 justify-self-end text-gray-500;
}
diff --git a/frontend/src/components/KBar/useRecentVisit.ts b/frontend/src/components/KBar/useRecentVisit.ts
new file mode 100644
index 0000000000..f991f246bf
--- /dev/null
+++ b/frontend/src/components/KBar/useRecentVisit.ts
@@ -0,0 +1,119 @@
+import { useRoute, useRouter } from "vue-router";
+import { defineAction, useRegisterActions } from "@bytebase/vue-kbar";
+import { useStorage, useDebounce } from "@vueuse/core";
+import { computed, ref, watch, nextTick } from "vue";
+import { useI18n } from "vue-i18n";
+
+type RecentVisit = {
+ title: string;
+ url: string;
+};
+
+const STORAGE_KEY = "ui.kbar.recently_visited";
+const MAX_HISTORY = 3;
+
+export function useRecentVisit() {
+ const { t } = useI18n();
+ const route = useRoute();
+ const router = useRouter();
+ const recentVisit = useStorage(STORAGE_KEY, [] as RecentVisit[]);
+ const url = computed(() => {
+ if (route.matched.length === 0) {
+ // When the application is landing, vue router will
+ // perform a redirection from "/" to current path
+ // e.g. if landing URL is "/instance", this redirection
+ // will be "/" -> "/instance".
+ // This even happens when "/" -> "/".
+ // `route.matched` is an empty array means this kind
+ // of redirection is going to be performed right now.
+ // We don't want to record the first "/" as a visit
+ // because Home page is not shown at this time.
+ return undefined;
+ }
+ return route.fullPath;
+ });
+ const currentPage = ref<RecentVisit>();
+
+ watch(
+ // Debounce the listener so we can skip internal immediate redirections
+ useDebounce(url, 50),
+ async (url) => {
+ if (!url) return;
+ if (url.startsWith("/auth")) {
+ // ignore auth related pages
+ // kbar is invisible on these pages
+ // and navigating to these pages does not make sense
+ return;
+ }
+ // wait for vue flushing
+ // otherwise `document.title` will not be dynamically updated
+ await nextTick();
+ const { title } = document;
+ currentPage.value = {
+ url,
+ title,
+ };
+ },
+ { immediate: true }
+ );
+
+ watch(
+ currentPage,
+ (curr) => {
+ if (!curr) return;
+ const list = recentVisit.value;
+ const index = list.findIndex((item) => {
+ // We treat the two URLs "the same" when their urls'
+ // `path` are the same (means ignoring querystring and hash).
+ // e.g. "/db?environment=5003" & "/db?environment=5005"
+ // e.g. "/environment#5001" & "/environment#5005"
+ // Because usually they are just different tab-panes
+ // or filters on the page.
+ return getPath(item.url) === getPath(curr.url);
+ });
+ if (index >= 0) {
+ // current page exists in the history already
+ // pull it out before next step
+ list.splice(index, 1);
+ }
+ // then prepend the latest item to the queue
+ list.unshift(curr);
+
+ // ensure the queue's length
+ // should be no more than (MAX_HISTORY + 1)
+ // because current page will always be the first one in the list
+ // but it will be not shown in kbar
+ while (list.length > MAX_HISTORY + 1) {
+ list.pop();
+ }
+ },
+ {
+ immediate: true,
+ }
+ );
+
+ const actions = computed(() => {
+ return recentVisit.value
+ .slice(1) // The first item is current page, just skip it.
+ .filter(({ title, url }) => title && url)
+ .map(({ title, url }, index) =>
+ defineAction({
+ // here `id` looks like "bb.recent_visited.1"
+ id: `bb.recently_visited.${index + 1}`,
+ section: t("kbar.recently-visited"),
+ name: title,
+ subtitle: url,
+ shortcut: ["g", `${index + 1}`],
+ keywords: "recently visited",
+ perform: () => router.push({ path: url }),
+ })
+ );
+ });
+
+ // prepend recent visit actions to kbar
+ useRegisterActions(actions, true);
+}
+
+function getPath(url: string): string {
+ return url.replace(/[?#].*$/, "");
+}
diff --git a/frontend/src/components/KBar/utils.ts b/frontend/src/components/KBar/utils.ts
new file mode 100644
index 0000000000..22f6d1fcce
--- /dev/null
+++ b/frontend/src/components/KBar/utils.ts
@@ -0,0 +1,34 @@
+import { Action, CompareFn } from "@bytebase/vue-kbar";
+
+const MAX_RANKING = Infinity;
+
+export const ACTION_RANKINGS = [
+ "bb.recently_visited.",
+ "bb.quickaction.",
+ "bb.navigation.",
+ "bb.bookmark.",
+ "bb.project.",
+ "bb.database.",
+ "bb.preferences.",
+];
+
+export const compareAction: CompareFn = (a, b) => {
+ const ar = getActionRankingById(a.item);
+ const br = getActionRankingById(b.item);
+
+ // Sort by original index if they have same ranks.
+ if (ar === br) return a.index - b.index;
+
+ // Otherwise sort by ranking.
+ return ar - br;
+};
+
+function getActionRankingById(action: Action) {
+ const rank = ACTION_RANKINGS.findIndex((prefix) =>
+ action.id.startsWith(prefix)
+ );
+ // non-specified namespaces should always rank behind specified ones.
+ if (rank < 0) return MAX_RANKING;
+
+ return rank;
+}
diff --git a/frontend/src/components/ProjectListSidePanel.vue b/frontend/src/components/ProjectListSidePanel.vue
index 26dfadecf3..52e3e9068b 100644
--- a/frontend/src/components/ProjectListSidePanel.vue
+++ b/frontend/src/components/ProjectListSidePanel.vue
@@ -16,11 +16,13 @@ import { projectName, projectSlug } from "../utils";
import { BBOutlineItem } from "../bbkit/types";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { useRouter } from "vue-router";
+import { useI18n } from "vue-i18n";
export default {
name: "ProjectListSidePanel",
props: {},
setup() {
+ const { t } = useI18n();
const store = useStore();
const router = useRouter();
@@ -60,7 +62,7 @@ export default {
defineAction({
// here `id` looks like "bb.project.1234"
id: `bb.project.${proj.id}`,
- section: "Projects",
+ section: t("common.projects"),
name: proj.name,
keywords: "project",
perform: () => {
diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vue
index 3b324666d6..684ae886f4 100644
--- a/frontend/src/components/QuickActionPanel.vue
+++ b/frontend/src/components/QuickActionPanel.vue
@@ -1,12 +1,6 @@
<template>
<div
- class="
- pt-1
- overflow-hidden
- grid grid-cols-4
- gap-x-2 gap-y-4
- md:inline-flex md:gap-x-0
- "
+ class="pt-1 overflow-hidden grid grid-cols-4 gap-x-2 gap-y-4 md:inline-flex md:gap-x-0"
>
<template v-for="(quickAction, index) in quickActionList" :key="index">
<div
@@ -55,13 +49,7 @@
</svg>
</router-link>
<h3
- class="
- mt-1
- text-center text-base
- font-normal
- text-main
- tracking-tight
- "
+ class="mt-1 text-center text-base font-normal text-main tracking-tight"
>
Manage User
</h3>
@@ -88,13 +76,7 @@
</svg>
</button>
<h3
- class="
- mt-1
- text-center text-base
- font-normal
- text-main
- tracking-tight
- "
+ class="mt-1 text-center text-base font-normal text-main tracking-tight"
>
Query
</h3>
@@ -121,13 +103,7 @@
</svg>
</button>
<h3
- class="
- mt-1
- text-center text-base
- font-normal
- text-main
- tracking-tight
- "
+ class="mt-1 text-center text-base font-normal text-main tracking-tight"
>
Edit Data
</h3>
@@ -154,13 +130,7 @@
</svg>
</button>
<h3
- class="
- mt-1
- text-base text-center
- font-normal
- text-main
- tracking-tight
- "
+ class="mt-1 text-base text-center font-normal text-main tracking-tight"
>
New DB
</h3>
@@ -187,13 +157,7 @@
</svg>
</button>
<h3
- class="
- mt-1
- text-base text-center
- font-normal
- text-main
- tracking-tight
- "
+ class="mt-1 text-base text-center font-normal text-main tracking-tight"
>
Request DB
</h3>
@@ -444,6 +408,7 @@ import TransferDatabaseForm from "../components/TransferDatabaseForm.vue";
import { DEFAULT_PROJECT_ID, ProjectId, QuickActionType } from "../types";
import { idFromSlug } from "../utils";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
+import { useI18n } from "vue-i18n";
interface LocalState {
showModal: boolean;
@@ -469,6 +434,7 @@ export default defineComponent({
},
},
setup(props) {
+ const { t } = useI18n();
const router = useRouter();
const store = useStore();
@@ -603,7 +569,8 @@ export default defineComponent({
const id = qa.replace(/^quickaction\.bb\.(.+)$/, "bb.quickaction.$1");
return defineAction({
id,
- section: "Quick Action",
+ section: t("common.quick-action"),
+ keywords: "quick action",
...QuickActionMap[qa],
});
});
diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.yml
index ce80e8f1ae..36dab29dbe 100644
--- a/frontend/src/locales/en.yml
+++ b/frontend/src/locales/en.yml
@@ -8,8 +8,22 @@ common:
instances: Instances
environments: Environments
bookmarks: Bookmarks
+ quick-action: Quick Action
archive: Archive
quickstart: Quickstart
logout: Logout
not-found: Not Found
anomaly-center: Anomaly Center
+kbar:
+ recently-visited: Recently Visited
+ navigation: Navigation
+ help:
+ navigate: to navigate
+ perform: to perform
+ close: to close
+ back: to back
+ options:
+ placeholder: Type a command or search…
+ preferences:
+ common: Preferences
+ change-language: Change Language…
diff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.yml
index d1bc33a4d6..676c98156b 100644
--- a/frontend/src/locales/zh-CN.yml
+++ b/frontend/src/locales/zh-CN.yml
@@ -8,8 +8,22 @@ common:
instances: 实例
environments: 环境
bookmarks: 书签
+ quick-action: 快捷操作
archive: 归档
quickstart: 快速入门
logout: 登出
not-found: 未找到
anomaly-center: 异常中心
+kbar:
+ recently-visited: 最近访问
+ navigation: 导航
+ help:
+ navigate: 选择
+ perform: 执行
+ close: 关闭
+ back: 返回
+ options:
+ placeholder: 输入命令或搜索…
+ preferences:
+ common: 偏好设置
+ change-language: 更改语言…
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index 570a1b221d..0996006073 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -47,15 +47,7 @@
<div class="flex items-center space-x-3">
<div
v-if="showSwitchPlan"
- class="
- hidden
- md:flex
- sm:flex-row
- items-center
- space-x-2
- text-sm
- font-medium
- "
+ class="hidden md:flex sm:flex-row items-center space-x-2 text-sm font-medium"
>
<span class="hidden lg:block font-normal text-accent">Plan</span>
<div
@@ -85,15 +77,7 @@
</div>
<div
v-if="!isRelease"
- class="
- hidden
- md:flex
- sm:flex-row
- items-center
- space-x-2
- text-sm
- font-medium
- "
+ class="hidden md:flex sm:flex-row items-center space-x-2 text-sm font-medium"
>
<span class="hidden lg:block font-normal text-accent">Role</span>
<div
@@ -124,16 +108,7 @@
<router-link to="/inbox" exact-active-class="">
<span
v-if="inboxSummary.hasUnread"
- class="
- absolute
- rounded-full
- ml-4
- -mt-1
- h-2.5
- w-2.5
- bg-accent
- opacity-75
- "
+ class="absolute rounded-full ml-4 -mt-1 h-2.5 w-2.5 bg-accent opacity-75"
></span>
<heroicons-outline:bell class="w-6 h-6" />
</router-link>
@@ -233,6 +208,7 @@ export default {
name: "DashboardHeader",
components: { ProfileDropdown },
setup() {
+ const { t, availableLocales, locale } = useI18n();
const store = useStore();
const router = useRouter();
@@ -301,68 +277,102 @@ export default {
store.dispatch("plan/changePlan", PlanType.ENTERPRISE);
};
- const kbarActions = [
+ const kbarActions = computed(() => [
defineAction({
id: "bb.navigation.projects",
name: "Projects",
shortcut: ["g", "p"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation",
perform: () => router.push({ name: "workspace.project" }),
}),
defineAction({
id: "bb.navigation.databases",
name: "Databases",
- keywords: "db",
shortcut: ["g", "d"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation db",
perform: () => router.push({ name: "workspace.database" }),
}),
defineAction({
id: "bb.navigation.instances",
name: "Instances",
shortcut: ["g", "i"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation",
perform: () => router.push({ name: "workspace.instance" }),
}),
defineAction({
id: "bb.navigation.environments",
name: "Environments",
shortcut: ["g", "e"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation",
perform: () => router.push({ name: "workspace.environment" }),
}),
defineAction({
id: "bb.navigation.settings",
name: "Settings",
shortcut: ["g", "s"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation",
perform: () => router.push({ name: "setting.workspace.general" }),
}),
defineAction({
id: "bb.navigation.inbox",
name: "Inbox",
shortcut: ["g", "m"],
- section: "Navigation",
+ section: t("kbar.navigation"),
+ keywords: "navigation",
perform: () => router.push({ name: "setting.inbox" }),
}),
- ];
+ ]);
useRegisterActions(kbarActions);
- const { availableLocales, locale } = useI18n();
const storage = useLocalStorage("bytebase_options", {}) as any;
- const toggleLocales = () => {
- // TODO change to some real logic
- const locales = availableLocales;
- locale.value =
- locales[(locales.indexOf(locale.value) + 1) % locales.length];
+ const setLocale = (lang: string) => {
+ locale.value = lang;
storage.value = {
appearance: {
- language: locale.value,
+ language: lang,
},
};
};
+ const toggleLocales = () => {
+ // TODO change to some real logic
+ const locales = availableLocales;
+ const nextLocale =
+ locales[(locales.indexOf(locale.value) + 1) % locales.length];
+ setLocale(nextLocale);
+ };
+
+ const I18N_CHANGE_ACTION_ID_NAMESPACE = "bb.preferences.locale";
+ const i18nChangeAction = computed(() =>
+ defineAction({
+ // here `id` is "bb.preferences.locale"
+ id: I18N_CHANGE_ACTION_ID_NAMESPACE,
+ section: t("kbar.preferences.common"),
+ name: t("kbar.preferences.change-language"),
+ keywords: "language lang locale",
+ })
+ );
+ const i18nActions = computed(() => [
+ i18nChangeAction.value,
+ ...availableLocales.map((lang) => {
+ return defineAction({
+ // here `id` looks like "bb.preferences.locale.en"
+ id: `${I18N_CHANGE_ACTION_ID_NAMESPACE}.${lang}`,
+ name: lang,
+ parent: I18N_CHANGE_ACTION_ID_NAMESPACE,
+ keywords: `language lang locale ${lang}`,
+ perform: () => setLocale(lang),
+ });
+ }),
+ ]);
+ useRegisterActions(i18nActions);
+
return {
state,
currentUser,
diff --git a/frontend/yarn.lock b/frontend/yarn.lock
index 5e5ed1034e..bd23843eea 100644
--- a/frontend/yarn.lock
+++ b/frontend/yarn.lock
@@ -43,10 +43,10 @@
"@babel/helper-validator-identifier" "^7.15.7"
to-fast-properties "^2.0.0"
-"@bytebase/vue-kbar@^0.1.2":
- version "0.1.2"
- resolved "https://registry.yarnpkg.com/@bytebase/vue-kbar/-/vue-kbar-0.1.2.tgz#9b325d1a5a366d1fe68c983a85400651b1436ce7"
- integrity sha512-cKBv61M1LkCibpxy5WFOzd15uqka1XYYM91Pm1Wo57ojgljZJPJhmu2+oE9pGYr+NSAIryIw2Hglgv0b6E/8Vg==
+"@bytebase/vue-kbar@^0.1.4":
+ version "0.1.4"
+ resolved "https://registry.yarnpkg.com/@bytebase/vue-kbar/-/vue-kbar-0.1.4.tgz#5ce6e36142b7d35a59e4db9dac9f49bf73ce8777"
+ integrity sha512-teYoVjbE3aSHptHl0evqCugOOhqJg6CLgQCmvC8j11Qau6Pq9kMeoMb7nrVIgo0sZbknf52VZsHdy/sTUQF2Rw==
dependencies:
"@vueuse/core" "^7.1.2"
match-sorter "^6.3.1"