Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: record and redirect to last visit page (#12952)
ecmadao668fdaf01f9f
diff --git a/frontend/src/components/KBar/KBarHelper.vue b/frontend/src/components/KBar/KBarHelper.vueindex 8edfcde8d6..333ae1ca0e 100644--- a/frontend/src/components/KBar/KBarHelper.vue+++ b/frontend/src/components/KBar/KBarHelper.vue@@ -2,26 +2,46 @@<slot /></template>-<script lang="ts">+<script lang="ts" setup>import { useKBarHandler } from "@bytebase/vue-kbar";-import { defineComponent, watch } from "vue";-import { useRoute } from "vue-router";-import { useRecentVisit } from "./useRecentVisit";+import { defineAction, useRegisterActions } from "@bytebase/vue-kbar";+import { watch, computed } from "vue";+import { useI18n } from "vue-i18n";+import { useRoute, useRouter } from "vue-router";+import { useRecentVisit } from "@/router/useRecentVisit";-export default defineComponent({- name: "KBarFooter",- setup() {- const handler = useKBarHandler();- const route = useRoute();- watch(- () => route.fullPath,- () => {- // force hide kbar when page navigated- handler.value.hide();- }- );+const handler = useKBarHandler();+const route = useRoute();+const router = useRouter();+const { recentVisit } = useRecentVisit();+const { t } = useI18n();++watch(+ () => route.fullPath,+ () => {+ // force hide kbar when page navigated+ handler.value.hide();+ }+);- useRecentVisit();- },+const actions = computed(() => {+ return recentVisit.value+ .slice(1) // The first item is current page, just skip it.+ .filter(({ title, path }) => title && path)+ .map(({ title, path }, index) =>+ defineAction({+ // here `id` looks like "bb.recent_visited.1"+ id: `bb.recently_visited.${index + 1}`,+ section: t("kbar.recently-visited"),+ name: title,+ subtitle: path,+ shortcut: ["g", `${index + 1}`],+ keywords: "recently visited",+ perform: () => router.push({ path }),+ })+ );});++// prepend recent visit actions to kbar+useRegisterActions(actions, true);</script>diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vueindex cbfd8af569..8fa468cb5a 100644--- a/frontend/src/layouts/DashboardLayout.vue+++ b/frontend/src/layouts/DashboardLayout.vue@@ -16,11 +16,13 @@</template><script lang="ts" setup>-import { reactive, watch } from "vue";-import { useRoute } from "vue-router";+import { reactive, watch, onMounted } from "vue";+import { useRoute, useRouter } from "vue-router";import BannersWrapper from "@/components/BannersWrapper.vue";import HelpDrawer from "@/components/HelpDrawer";import ProvideDashboardContext from "@/components/ProvideDashboardContext.vue";+import { WORKSPACE_ROUTE_MY_ISSUES } from "@/router/dashboard/workspaceRoutes";+import { useRecentVisit } from "@/router/useRecentVisit";import { useAppFeature, useHelpStore, useUIStateStore } from "@/store";import type { RouteMapList } from "@/types";@@ -30,10 +32,12 @@ interface LocalState {}const route = useRoute();+const router = useRouter();const state = reactive<LocalState>({helpTimer: undefined,RouteMapList: null,});+const { lastVisit } = useRecentVisit();const hideHelp = useAppFeature("bb.feature.hide-help");// watch route change for help@@ -72,4 +76,16 @@ watch(}});++onMounted(() => {+ if (lastVisit.value?.path) {+ router.replace({+ path: lastVisit.value?.path,+ });+ } else {+ router.replace({+ name: WORKSPACE_ROUTE_MY_ISSUES,+ });+ }+});</script>diff --git a/frontend/src/router/dashboard/workspace.ts b/frontend/src/router/dashboard/workspace.tsindex 29ef8417b4..b7334876fa 100644--- a/frontend/src/router/dashboard/workspace.ts+++ b/frontend/src/router/dashboard/workspace.ts@@ -1,7 +1,6 @@import { startCase } from "lodash-es";import type { RouteRecordRaw } from "vue-router";import { t } from "@/plugins/i18n";-import DashboardLandingPage from "@/views/DashboardLandingPage.vue";import MyIssues from "@/views/MyIssues.vue";import {PROJECT_V1_ROUTE_DASHBOARD,@@ -34,42 +33,39 @@ import {WORKSPACE_ROUTE_IM,} from "./workspaceRoutes";+const homePage: RouteRecordRaw = {+ path: "",+ name: WORKSPACE_HOME_MODULE,+ meta: {+ getQuickActionList: () => {+ return [+ "quickaction.bb.database.schema.update",+ "quickaction.bb.database.data.update",+ "quickaction.bb.database.create",+ "quickaction.bb.instance.create",+ "quickaction.bb.issue.grant.request.querier",+ "quickaction.bb.issue.grant.request.exporter",+ ];+ },+ },+ components: {+ content: MyIssues,+ leftSidebar: () => import("@/views/DashboardSidebar.vue"),+ },+ props: {+ content: true,+ leftSidebar: true,+ },+};+const workspaceRoutes: RouteRecordRaw[] = [{- path: "",- name: WORKSPACE_HOME_MODULE,- components: {- content: DashboardLandingPage,- leftSidebar: () => import("@/views/DashboardSidebar.vue"),- },- props: {- content: true,- leftSidebar: true,- },+ ...homePage,},{+ ...homePage,path: "issues",name: WORKSPACE_ROUTE_MY_ISSUES,- meta: {- getQuickActionList: () => {- return [- "quickaction.bb.database.schema.update",- "quickaction.bb.database.data.update",- "quickaction.bb.database.create",- "quickaction.bb.instance.create",- "quickaction.bb.issue.grant.request.querier",- "quickaction.bb.issue.grant.request.exporter",- ];- },- },- components: {- content: MyIssues,- leftSidebar: () => import("@/views/DashboardSidebar.vue"),- },- props: {- content: true,- leftSidebar: true,- },},{path: "projects",diff --git a/frontend/src/components/KBar/useRecentVisit.ts b/frontend/src/router/useRecentVisit.tssimilarity index 64%rename from frontend/src/components/KBar/useRecentVisit.tsrename to frontend/src/router/useRecentVisit.tsindex cf7ca0560b..c205230999 100644--- a/frontend/src/components/KBar/useRecentVisit.ts+++ b/frontend/src/router/useRecentVisit.ts@@ -1,23 +1,27 @@-import { defineAction, useRegisterActions } from "@bytebase/vue-kbar";-import { useStorage, useDebounce } from "@vueuse/core";+import { useLocalStorage, useDebounce } from "@vueuse/core";import { computed, ref, watch, nextTick } from "vue";-import { useI18n } from "vue-i18n";-import { useRoute, useRouter } from "vue-router";+import { useRoute } from "vue-router";type RecentVisit = {title: string;- url: string;+ path: string;};-const STORAGE_KEY = "ui.kbar.recently_visited";+const STORAGE_KEY = "bb.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(() => {+ const recentVisit = useLocalStorage(STORAGE_KEY, [] as RecentVisit[]);++ const lastVisit = computed(() => {+ if (recentVisit.value.length === 0) {+ return;+ }+ return recentVisit.value[0];+ });++ const currentRoute = computed(() => {if (route.matched.length === 0) {// When the application is landing, vue router will// perform a redirection from "/" to current path@@ -30,16 +34,19 @@ export function useRecentVisit() {// because Home page is not shown at this time.return undefined;}- return route.fullPath;+ return {+ name: route.name?.toString() ?? "",+ path: 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")) {+ useDebounce(currentRoute, 50),+ async (currentRoute) => {+ if (!currentRoute) return;+ if (currentRoute.path.startsWith("/auth")) {// ignore auth related pages// kbar is invisible on these pages// and navigating to these pages does not make sense@@ -50,8 +57,8 @@ export function useRecentVisit() {await nextTick();const { title } = document;currentPage.value = {- url,title,+ ...currentRoute,};},{ immediate: true }@@ -68,7 +75,7 @@ export function useRecentVisit() {// e.g. "/db?environment=5003" & "/db?environment=5005"// Because usually they are just different tab-panes// or filters on the page.- return getPath(item.url) === getPath(curr.url);+ return getPath(item.path) === getPath(item.path);});if (index >= 0) {// current page exists in the history already@@ -91,26 +98,10 @@ export function useRecentVisit() {});- 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);+ return {+ recentVisit,+ lastVisit,+ };}function getPath(url: string): string {diff --git a/frontend/src/views/DashboardLandingPage.vue b/frontend/src/views/DashboardLandingPage.vuedeleted file mode 100644index 006d032b8d..0000000000--- a/frontend/src/views/DashboardLandingPage.vue+++ /dev/null@@ -1,17 +0,0 @@-<template>- <slot />-</template>--<script setup lang="ts">-import { onMounted } from "vue";-import { useRouter } from "vue-router";-import { WORKSPACE_ROUTE_MY_ISSUES } from "@/router/dashboard/workspaceRoutes";--const router = useRouter();--onMounted(() => {- router.replace({- name: WORKSPACE_ROUTE_MY_ISSUES,- });-});-</script>diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vueindex e0a8bd7aba..4b525bc1d8 100644--- a/frontend/src/views/DashboardSidebar.vue+++ b/frontend/src/views/DashboardSidebar.vue@@ -31,6 +31,7 @@ import { useGlobalDatabaseActions } from "@/components/KBar/useDatabaseActions";import { useProjectActions } from "@/components/KBar/useProjectActions";import workspaceRoutes from "@/router/dashboard/workspace";import {+ WORKSPACE_HOME_MODULE,DATABASE_ROUTE_DASHBOARD,ENVIRONMENT_V1_ROUTE_DASHBOARD,INSTANCE_ROUTE_DASHBOARD,@@ -80,8 +81,10 @@ const getItemClass = (item: SidebarItem): string[] => {return classes;}if (- item.name === WORKSPACE_ROUTE_MEMBERS &&- current?.toString() === WORKSPACE_ROUTE_USER_PROFILE+ (item.name === WORKSPACE_ROUTE_MEMBERS &&+ current?.toString() === WORKSPACE_ROUTE_USER_PROFILE) ||+ (item.name === WORKSPACE_ROUTE_MY_ISSUES &&+ current?.toString() === WORKSPACE_HOME_MODULE)) {classes.push("router-link-active", "bg-link-hover");return classes;