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: only record project switch (#13311)
ecmadao85f4ceb4d34c
diff --git a/frontend/src/DummyRootView.ts b/frontend/src/DummyRootView.tsindex f3c2acf999..9ab4d117b5 100644--- a/frontend/src/DummyRootView.ts+++ b/frontend/src/DummyRootView.ts@@ -10,11 +10,14 @@ export default defineComponent({name: "DummyRootView",setup() {const { lastVisit } = useRecentVisit();+const router = useRouter();const actuatorStore = useActuatorV1Store();+const mode = computed(() => {return actuatorStore.appProfile.mode;});+watch(mode,() => {@@ -23,6 +26,7 @@ export default defineComponent({name: WORKSPACE_ROUTE_MY_ISSUES,});};+// Redirect to// - /sql-editor if mode == 'EDITOR'// - lastVisit.path if not empty@@ -42,7 +46,8 @@ export default defineComponent({if (!lastVisit.value) {return fallback();}- const { path } = lastVisit.value;+ const path = lastVisit.value;+// Ignore all possible root path recordsif (path === "" ||diff --git a/frontend/src/components/BytebaseLogo.vue b/frontend/src/components/BytebaseLogo.vueindex 4536652559..8575f8c7cb 100644--- a/frontend/src/components/BytebaseLogo.vue+++ b/frontend/src/components/BytebaseLogo.vue@@ -5,7 +5,7 @@<component:is="component":to="{- name: WORKSPACE_ROUTE_MY_ISSUES,+ name: redirect,}"class="w-full select-none flex flex-row justify-center items-center"active-class=""@@ -29,18 +29,19 @@<script lang="ts" setup>import { computed } from "vue";-import { WORKSPACE_ROUTE_MY_ISSUES } from "@/router/dashboard/workspaceRoutes";import { useActuatorV1Store } from "@/store/modules/v1/actuator";-withDefaults(+const props = withDefaults(defineProps<{- component?: "router-link" | "span";+ redirect?: string;}>(),{- component: "router-link",+ redirect: "",});+const component = computed(() => (props.redirect ? "router-link" : "span"));+const customBrandingLogo = computed((): string => {return useActuatorV1Store().brandingLogo;});diff --git a/frontend/src/components/CommonSidebar.vue b/frontend/src/components/CommonSidebar.vueindex d46b7a2ca7..9b4c18d61a 100644--- a/frontend/src/components/CommonSidebar.vue+++ b/frontend/src/components/CommonSidebar.vue@@ -1,6 +1,10 @@<template><nav class="flex-1 flex flex-col overflow-y-hidden">- <BytebaseLogo v-if="showLogo" class="w-full px-4 shrink-0" />+ <BytebaseLogo+ v-if="showLogo"+ class="w-full px-4 shrink-0"+ :redirect="logoRedirect"+ /><div class="flex-1 overflow-y-auto px-2.5 space-y-1"><div v-for="(item, i) in filteredSidebarList" :key="i"><router-link@@ -100,10 +104,12 @@ const props = withDefaults(defineProps<{itemList: SidebarItem[];showLogo?: boolean;+ logoRedirect?: string;getItemClass?: (item: SidebarItem) => string[];}>(),{showLogo: true,+ logoRedirect: "",getItemClass: (_: SidebarItem) => [],});diff --git a/frontend/src/components/KBar/KBarHelper.vue b/frontend/src/components/KBar/KBarHelper.vueindex 333ae1ca0e..f69510ddd4 100644--- a/frontend/src/components/KBar/KBarHelper.vue+++ b/frontend/src/components/KBar/KBarHelper.vue@@ -8,7 +8,7 @@ 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";+import { useRecentVisit } from "./useRecentVisit";const handler = useKBarHandler();const route = useRoute();diff --git a/frontend/src/components/KBar/useRecentVisit.ts b/frontend/src/components/KBar/useRecentVisit.tsnew file mode 100644index 0000000000..36bd87587d--- /dev/null+++ b/frontend/src/components/KBar/useRecentVisit.ts@@ -0,0 +1,118 @@+import { useDebounce } from "@vueuse/core";+import { computed, ref, watch, nextTick } from "vue";+import { useRoute } from "vue-router";+import { WORKSPACE_ROOT_MODULE } from "@/router/dashboard/workspaceRoutes";+import { useCurrentUserV1 } from "@/store";+import { useDynamicLocalStorage } from "@/utils";++type RecentVisit = {+ title: string;+ path: string;+};++const STORAGE_KEY = "bb.kbar.recently_visited";+const MAX_HISTORY = 3;++export function useRecentVisit() {+ const route = useRoute();+ const currentUser = useCurrentUserV1();++ const recentVisit = useDynamicLocalStorage<RecentVisit[]>(+ computed(() => `${STORAGE_KEY}.${currentUser.value.name}`),+ []+ );++ const currentRoute = 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 {+ name: route.name?.toString() ?? "",+ path: route.fullPath,+ };+ });+ const currentPage = ref<RecentVisit>();++ watch(+ // Debounce the listener so we can skip internal immediate redirections+ useDebounce(currentRoute, 50),+ async (currentRoute) => {+ if (!currentRoute) return;+ if (currentRoute.name === WORKSPACE_ROOT_MODULE) {+ // ignore app root path+ return;+ }+ if (+ currentRoute.path.startsWith("/auth") ||+ currentRoute.path.startsWith("/sql-editor") ||+ currentRoute.path.startsWith("/403") ||+ currentRoute.path.startsWith("/404")+ ) {+ // 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 = {+ title,+ ...currentRoute,+ };+ },+ { 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"+ // Because usually they are just different tab-panes+ // or filters on the page.+ return getPath(item.path) === getPath(curr.path);+ });+ 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,+ }+ );++ return {+ recentVisit,+ };+}++function getPath(url: string): string {+ return url.replace(/[?#].*$/, "");+}diff --git a/frontend/src/components/Project/ProjectSidebarV1.vue b/frontend/src/components/Project/ProjectSidebarV1.vueindex f3ed8f4a3f..cc92a1e2c4 100644--- a/frontend/src/components/Project/ProjectSidebarV1.vue+++ b/frontend/src/components/Project/ProjectSidebarV1.vue@@ -3,6 +3,7 @@:key="'project'":item-list="projectSidebarItemList":get-item-class="getItemClass"+ :logo-redirect="PROJECT_V1_ROUTE_DETAIL"@select="onSelect"/></template>@@ -14,6 +15,7 @@ import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";import type { SidebarItem } from "@/components/CommonSidebar.vue";import CommonSidebar from "@/components/CommonSidebar.vue";+import { PROJECT_V1_ROUTE_DETAIL } from "@/router/dashboard/projectV1";import { getProjectName } from "@/store/modules/v1/common";import { useProjectDatabaseActions } from "../KBar/useDatabaseActions";import { useCurrentProject } from "./useCurrentProject";diff --git a/frontend/src/components/Project/ProjectSwitchModal.vue b/frontend/src/components/Project/ProjectSwitchModal.vueindex dcc738f2e5..af594008a3 100644--- a/frontend/src/components/Project/ProjectSwitchModal.vue+++ b/frontend/src/components/Project/ProjectSwitchModal.vue@@ -3,11 +3,20 @@:close-on-esc="true":mask-closable="true":trap-focus="false"+ :show="show":title="$t('project.select')"class="w-[48rem] max-w-full h-128 max-h-full"@close="$emit('dismiss')"><div class="h-full overflow-y-auto relative">+ <div v-if="currentProject" class="mb-2">+ <NButton text @click="gotoWorkspace">+ <template #icon>+ <ChevronLeftIcon class="w-4" />+ </template>+ {{ $t("common.back-to-workspace") }}+ </NButton>+ </div><div class="w-full bg-white sticky top-0 z-50"><div class="flex items-center justify-between space-x-2"><SearchBox@@ -42,7 +51,7 @@:current-project="currentProject":pagination="false":keyword="state.searchText"- @row-click="$emit('dismiss')"+ @row-click="onProjectSelect"/></NTabPane></NTabs>@@ -59,14 +68,20 @@</template><script lang="ts" setup>+import { ChevronLeftIcon } from "lucide-vue-next";import { NButton, NTabPane, NTabs } from "naive-ui";import { computed, reactive, onMounted } from "vue";import { useI18n } from "vue-i18n";+import { useRouter } from "vue-router";import { BBModal } from "@/bbkit";import { useRecentProjects } from "@/components/Project/useRecentProjects";import { SearchBox, ProjectV1Table } from "@/components/v2";import { Drawer } from "@/components/v2";+import { PROJECT_V1_ROUTE_DETAIL } from "@/router/dashboard/projectV1";+import { WORKSPACE_ROUTE_MY_ISSUES } from "@/router/dashboard/workspaceRoutes";+import { useRecentVisit } from "@/router/useRecentVisit";import { useProjectV1List } from "@/store";+import { getProjectName } from "@/store/modules/v1/common";import type { ComposedProject } from "@/types";import { isValidProjectName, DEFAULT_PROJECT_NAME } from "@/types";import { filterProjectV1ListByKeyword } from "@/utils";@@ -79,6 +94,7 @@ interface LocalState {}const props = defineProps<{+ show: boolean;project?: ComposedProject;}>();@@ -94,6 +110,8 @@ const state = reactive<LocalState>({});const { projectList } = useProjectV1List();const { recentViewProjects } = useRecentProjects();+const router = useRouter();+const { record } = useRecentVisit();onMounted(() => {state.selectedTab = recentViewProjects.value.length < 1 ? "all" : "recent";@@ -150,4 +168,20 @@ const onCreate = () => {state.showCreateDrawer = false;emit("dismiss");};++const onProjectSelect = (project: ComposedProject) => {+ const route = router.resolve({+ name: PROJECT_V1_ROUTE_DETAIL,+ params: {+ projectId: getProjectName(project.name),+ },+ });+ record(route.fullPath);+ emit("dismiss");+};++const gotoWorkspace = () => {+ router.push({ name: WORKSPACE_ROUTE_MY_ISSUES });+ emit("dismiss");+};</script>diff --git a/frontend/src/components/v2/Model/ProjectV1Table.vue b/frontend/src/components/v2/Model/ProjectV1Table.vueindex 50f6dd1813..0e26fd5e91 100644--- a/frontend/src/components/v2/Model/ProjectV1Table.vue+++ b/frontend/src/components/v2/Model/ProjectV1Table.vue@@ -61,7 +61,7 @@ const props = withDefaults();const emit = defineEmits<{- (event: "row-click"): void;+ (event: "row-click", project: ComposedProject): void;}>();const router = useRouter();@@ -158,7 +158,7 @@ const rowProps = (project: ComposedProject) => {} else {router.push(route);}- emit("row-click");+ emit("row-click", project);},};};diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 1067d0ed48..8835a0921b 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -285,6 +285,7 @@"self": "rows","n-rows": "{n} rows"},+ "back-to-workspace": "Back to workspace","override": "Override"},"error-page": {diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 8d375895a6..e5938e5f16 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -285,6 +285,7 @@"self": "filas","n-rows": "{n} filas"},+ "back-to-workspace": "Volver al espacio de trabajo","override": "Anular"},"error-page": {diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 47c243e139..cd8e469f4b 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -285,6 +285,7 @@"self": "行","n-rows": "{n} 行"},+ "back-to-workspace": "ワークスペースに戻る","override": "オーバーライド"},"error-page": {diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex e6c703c154..7a92655f9d 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -285,6 +285,7 @@"self": "行","n-rows": "{n} 行"},+ "back-to-workspace": "返回工作空间","override": "覆盖"},"error-page": {diff --git a/frontend/src/router/useRecentVisit.ts b/frontend/src/router/useRecentVisit.tsindex 15100ed1a1..e21cb5d7eb 100644--- a/frontend/src/router/useRecentVisit.ts+++ b/frontend/src/router/useRecentVisit.ts@@ -1,23 +1,14 @@-import { useDebounce } from "@vueuse/core";-import { computed, ref, watch, nextTick } from "vue";-import { useRoute } from "vue-router";+import { computed } from "vue";import { useCurrentUserV1 } from "@/store";import { useDynamicLocalStorage } from "@/utils";-import { WORKSPACE_ROOT_MODULE } from "./dashboard/workspaceRoutes";-type RecentVisit = {- title: string;- path: string;-};--const STORAGE_KEY = "bb.recently_visited";+const STORAGE_KEY = "bb.space.recently_visited";const MAX_HISTORY = 3;export function useRecentVisit() {- const route = useRoute();const currentUser = useCurrentUserV1();- const recentVisit = useDynamicLocalStorage<RecentVisit[]>(+ const recentVisit = useDynamicLocalStorage<string[]>(computed(() => `${STORAGE_KEY}.${currentUser.value.name}`),[]);@@ -29,94 +20,35 @@ export function useRecentVisit() {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- // 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;+ const record = (path: string) => {+ 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"+ // Because usually they are just different tab-panes+ // or filters on the page.+ return getPath(item) === getPath(path);+ });+ if (index >= 0) {+ // current page exists in the history already+ // pull it out before next step+ list.splice(index, 1);}- return {- name: route.name?.toString() ?? "",- path: route.fullPath,- };- });- const currentPage = ref<RecentVisit>();-- watch(- // Debounce the listener so we can skip internal immediate redirections- useDebounce(currentRoute, 50),- async (currentRoute) => {- if (!currentRoute) return;- if (currentRoute.name === WORKSPACE_ROOT_MODULE) {- // ignore app root path- return;- }- if (- currentRoute.path.startsWith("/auth") ||- currentRoute.path.startsWith("/sql-editor") ||- currentRoute.path.startsWith("/403") ||- currentRoute.path.startsWith("/404")- ) {- // 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 = {- title,- ...currentRoute,- };- },- { 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"- // Because usually they are just different tab-panes- // or filters on the page.- return getPath(item.path) === getPath(item.path);- });- 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,+ // then prepend the latest item to the queue+ list.unshift(path);++ // 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();}- );+ };return {- recentVisit,+ record,lastVisit,};}diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vueindex 29642a7172..844e036c02 100644--- a/frontend/src/views/DashboardHeader.vue+++ b/frontend/src/views/DashboardHeader.vue@@ -1,7 +1,10 @@<template><div class="flex items-center justify-between h-10 px-4 my-1 space-x-3"><div class="flex items-center">- <BytebaseLogo class="block md:hidden" />+ <BytebaseLogo+ class="block md:hidden"+ :redirect="WORKSPACE_ROUTE_MY_ISSUES"+ /><NButtonclass="hidden sm:inline"@@ -84,7 +87,7 @@/><ProjectSwitchModal- v-if="state.showProjectModal"+ :show="state.showProjectModal":project="project"@dismiss="state.showProjectModal = false"/>@@ -103,6 +106,7 @@ import ProjectSwitchModal from "@/components/Project/ProjectSwitchModal.vue";import { useCurrentProject } from "@/components/Project/useCurrentProject";import WeChatQRModal from "@/components/WeChatQRModal.vue";import { ProjectNameCell } from "@/components/v2/Model/DatabaseV1Table/cells";+import { WORKSPACE_ROUTE_MY_ISSUES } from "@/router/dashboard/workspaceRoutes";import { SETTING_ROUTE_WORKSPACE_GENERAL } from "@/router/dashboard/workspaceSetting";import {SQL_EDITOR_HOME_MODULE,diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vueindex 0cf39e9249..77b7a48397 100644--- a/frontend/src/views/DashboardSidebar.vue+++ b/frontend/src/views/DashboardSidebar.vue@@ -4,6 +4,7 @@:key="'dashboard'":item-list="dashboardSidebarItemList":get-item-class="getItemClass"+ :logo-redirect="WORKSPACE_ROUTE_MY_ISSUES"/></template>diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vueindex f4de289774..40b267f007 100644--- a/frontend/src/views/SettingSidebar.vue+++ b/frontend/src/views/SettingSidebar.vue@@ -3,6 +3,7 @@:key="'setting'":item-list="settingSidebarItemList":get-item-class="getItemClass"+ :logo-redirect="WORKSPACE_ROUTE_MY_ISSUES"@select="onSelect"/></template>@@ -15,6 +16,7 @@ import type { RouteRecordRaw } from "vue-router";import { useRoute, useRouter } from "vue-router";import type { SidebarItem } from "@/components/CommonSidebar.vue";import CommonSidebar from "@/components/CommonSidebar.vue";+import { WORKSPACE_ROUTE_MY_ISSUES } from "@/router/dashboard/workspaceRoutes";import workspaceSettingRoutes, {SETTING_ROUTE_PROFILE,SETTING_ROUTE_PROFILE_TWO_FACTOR,diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vueindex 7df190a262..b7be0bd285 100644--- a/frontend/src/views/auth/Signin.vue+++ b/frontend/src/views/auth/Signin.vue@@ -1,7 +1,7 @@<template><template v-if="initialized"><div class="mx-auto w-full max-w-sm">- <BytebaseLogo component="span" class="mx-auto" />+ <BytebaseLogo class="mx-auto" /><div class="mt-8"><NCard>diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vueindex 414bf6ebe1..d6481e5a68 100644--- a/frontend/src/views/auth/Signup.vue+++ b/frontend/src/views/auth/Signup.vue@@ -1,7 +1,7 @@<template><div class="mx-auto w-full max-w-sm"><div>- <BytebaseLogo component="span" class="mx-auto mb-8" />+ <BytebaseLogo class="mx-auto mb-8" /><h2 class="text-2xl leading-9 font-medium text-main"><template v-if="needAdminSetup">diff --git a/frontend/src/views/sql-editor/EditorPanel/Welcome/Welcome.vue b/frontend/src/views/sql-editor/EditorPanel/Welcome/Welcome.vueindex 5b1e39f73b..17e761181f 100644--- a/frontend/src/views/sql-editor/EditorPanel/Welcome/Welcome.vue+++ b/frontend/src/views/sql-editor/EditorPanel/Welcome/Welcome.vue@@ -3,7 +3,7 @@class="w-full flex-1 flex flex-col items-center justify-start gap-y-4"style="padding-top: calc(clamp(40px, 15vh, 200px)">- <BytebaseLogo v-if="!hideLogo" component="span" />+ <BytebaseLogo v-if="!hideLogo" /><divclass="hidden lg:grid items-center gap-4"diff --git a/frontend/src/views/sql-editor/Setting/Sidebar/Sidebar.vue b/frontend/src/views/sql-editor/Setting/Sidebar/Sidebar.vueindex 82c0814224..b77c6964db 100644--- a/frontend/src/views/sql-editor/Setting/Sidebar/Sidebar.vue+++ b/frontend/src/views/sql-editor/Setting/Sidebar/Sidebar.vue@@ -1,7 +1,10 @@<template><div class="h-full flex flex-col overflow-y-auto bg-control-bg"><nav class="flex-1 flex flex-col overflow-y-hidden">- <BytebaseLogo class="w-full px-4 shrink-0" />+ <BytebaseLogo+ class="w-full px-4 shrink-0"+ :redirect="SQL_EDITOR_HOME_MODULE"+ /><div class="flex-1 overflow-y-auto px-2.5 space-y-1"><div v-for="item in itemList" :key="item.name">