Skip to content

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

chore(frontend): redirect to /sql-editor after login when workspace_database_change_mode is EDITOR (#13064)

Liu Jib8e28c7e2fe1
diff --git a/frontend/src/DummyRootView.ts b/frontend/src/DummyRootView.ts
new file mode 100644
index 0000000000..f3c2acf999
--- /dev/null
+++ b/frontend/src/DummyRootView.ts
@@ -0,0 +1,71 @@
+import { computed, defineComponent, watch } from "vue";
+import { useRouter } from "vue-router";
+import { WORKSPACE_ROUTE_MY_ISSUES } from "./router/dashboard/workspaceRoutes";
+import { SQL_EDITOR_HOME_MODULE } from "./router/sqlEditor";
+import { useRecentVisit } from "./router/useRecentVisit";
+import { useActuatorV1Store } from "./store";
+import { isDev } from "./utils";
+
+export default defineComponent({
+ name: "DummyRootView",
+ setup() {
+ const { lastVisit } = useRecentVisit();
+ const router = useRouter();
+ const actuatorStore = useActuatorV1Store();
+ const mode = computed(() => {
+ return actuatorStore.appProfile.mode;
+ });
+ watch(
+ mode,
+ () => {
+ const fallback = () => {
+ router.replace({
+ name: WORKSPACE_ROUTE_MY_ISSUES,
+ });
+ };
+ // Redirect to
+ // - /sql-editor if mode == 'EDITOR'
+ // - lastVisit.path if not empty
+ // - /issues as fallback
+ // Only turned on when isDev() is true
+ if (!isDev()) {
+ return fallback();
+ }
+
+ if (actuatorStore.appProfile.mode === "EDITOR") {
+ router.replace({
+ name: SQL_EDITOR_HOME_MODULE,
+ });
+ return;
+ }
+
+ if (!lastVisit.value) {
+ return fallback();
+ }
+ const { path } = lastVisit.value;
+ // Ignore all possible root path records
+ if (
+ path === "" ||
+ path === "/" ||
+ path.startsWith("?") ||
+ path.startsWith("#") ||
+ path.startsWith("/?") ||
+ path.startsWith("/#") ||
+ path.startsWith("/403") ||
+ path.startsWith("/404")
+ ) {
+ return fallback();
+ }
+ router.replace({
+ path,
+ });
+ },
+ {
+ immediate: true,
+ }
+ );
+ },
+ render() {
+ return null;
+ },
+});
diff --git a/frontend/src/components/BytebaseLogo.vue b/frontend/src/components/BytebaseLogo.vue
index a0a9289ec9..3a2b4c18e6 100644
--- a/frontend/src/components/BytebaseLogo.vue
+++ b/frontend/src/components/BytebaseLogo.vue
@@ -4,7 +4,9 @@
>
<component
:is="component"
- to="/"
+ :to="{
+ name: WORKSPACE_ROUTE_MY_ISSUES,
+ }"
class="w-full select-none flex flex-row justify-center items-center"
active-class=""
exact-active-class=""
@@ -27,6 +29,7 @@
<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(
diff --git a/frontend/src/components/SyncDatabaseSchema/index.vue b/frontend/src/components/SyncDatabaseSchema/index.vue
index 72ec3adb53..0d17a0dc95 100644
--- a/frontend/src/components/SyncDatabaseSchema/index.vue
+++ b/frontend/src/components/SyncDatabaseSchema/index.vue
@@ -71,7 +71,7 @@ import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { StepTab } from "@/components/v2";
import { PROJECT_V1_ROUTE_ISSUE_DETAIL } from "@/router/dashboard/projectV1";
-import { WORKSPACE_HOME_MODULE } from "@/router/dashboard/workspaceRoutes";
+import { WORKSPACE_ROOT_MODULE } from "@/router/dashboard/workspaceRoutes";
import { useProjectV1Store } from "@/store";
import type { ComposedProject } from "@/types";
import {
@@ -284,7 +284,7 @@ const generateIssueName = (databaseNameList: string[]) => {
const cancelSetup = () => {
router.replace({
- name: WORKSPACE_HOME_MODULE,
+ name: WORKSPACE_ROOT_MODULE,
});
};
</script>
diff --git a/frontend/src/customAppProfile.ts b/frontend/src/customAppProfile.ts
index 21800a0646..a819e674ce 100644
--- a/frontend/src/customAppProfile.ts
+++ b/frontend/src/customAppProfile.ts
@@ -1,11 +1,25 @@
-import { useActuatorV1Store, useAppFeature } from "./store";
+import { computed, watch } from "vue";
+import { useActuatorV1Store, useAppFeature, useSettingByName } from "./store";
+import { DatabaseChangeMode } from "./types/proto/v1/setting_service";
import { useCustomTheme } from "./utils/customTheme";
export const overrideAppProfile = () => {
- const query = new URLSearchParams(window.location.search);
const actuatorStore = useActuatorV1Store();
- const mode = query.get("mode");
- if (mode === "STANDALONE") {
+ const setting = useSettingByName("bb.workspace.profile");
+ const workspaceMode = computed(() => {
+ return setting.value?.value?.workspaceProfileSettingValue
+ ?.databaseChangeMode === DatabaseChangeMode.EDITOR
+ ? "EDITOR"
+ : "CONSOLE";
+ });
+ actuatorStore.appProfile.mode = workspaceMode.value;
+ watch(workspaceMode, (mode) => {
+ actuatorStore.appProfile.mode = mode;
+ });
+
+ const query = new URLSearchParams(window.location.search);
+ const modeInQuery = query.get("mode");
+ if (modeInQuery === "STANDALONE") {
// The webapp is embedded within iframe
actuatorStore.appProfile.embedded = true;
diff --git a/frontend/src/layouts/BodyLayout.vue b/frontend/src/layouts/BodyLayout.vue
index 0f83bf221c..cda87331d7 100644
--- a/frontend/src/layouts/BodyLayout.vue
+++ b/frontend/src/layouts/BodyLayout.vue
@@ -1,7 +1,7 @@
<template>
<div class="h-full flex flex-col overflow-hidden">
<div class="flex-1 flex overflow-hidden">
- <template v-if="!hideSidebar">
+ <template v-if="!hideSidebar && !isRootPath">
<!-- Off-canvas menu for mobile, show/hide based on off-canvas menu state. -->
<div
v-show="state.showMobileOverlay"
@@ -178,7 +178,7 @@
data-label="bb-main-body-wrapper"
>
<nav
- v-if="!hideHeader"
+ v-if="!hideHeader && !isRootPath"
class="bg-white border-b border-block-border"
data-label="bb-dashboard-header"
>
@@ -187,7 +187,7 @@
</div>
</nav>
- <aside v-if="!hideSidebar" class="md:hidden">
+ <aside v-if="!hideSidebar && !isRootPath" class="md:hidden">
<!-- Static sidebar for mobile -->
<div
class="flex items-center justify-start bg-gray-50 border-b border-block-border px-4"
@@ -255,6 +255,7 @@ import { computed, reactive, ref } from "vue";
import { useRouter } from "vue-router";
import ReleaseRemindModal from "@/components/ReleaseRemindModal.vue";
import TrialModal from "@/components/TrialModal.vue";
+import { WORKSPACE_ROOT_MODULE } from "@/router/dashboard/workspaceRoutes";
import { SETTING_ROUTE_WORKSPACE_SUBSCRIPTION } from "@/router/dashboard/workspaceSetting";
import {
useActuatorV1Store,
@@ -292,6 +293,10 @@ const currentUserV1 = useCurrentUserV1();
const mainContainerRef = ref<HTMLDivElement>();
const { width: windowWidth } = useWindowSize();
+const isRootPath = computed(() => {
+ return router.currentRoute.value.name === WORKSPACE_ROOT_MODULE;
+});
+
const sidebarView = computed(() => {
return windowWidth.value >= 768 ? "DESKTOP" : "MOBILE";
});
diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vue
index a5e6bd9747..cbfd8af569 100644
--- a/frontend/src/layouts/DashboardLayout.vue
+++ b/frontend/src/layouts/DashboardLayout.vue
@@ -16,16 +16,13 @@
</template>
<script lang="ts" setup>
-import { reactive, watch, onMounted } from "vue";
-import { useRoute, useRouter } from "vue-router";
+import { reactive, watch } from "vue";
+import { useRoute } from "vue-router";
import BannersWrapper from "@/components/BannersWrapper.vue";
import HelpDrawer from "@/components/HelpDrawer";
import ProvideDashboardContext from "@/components/ProvideDashboardContext.vue";
-import { WORKSPACE_HOME_MODULE } from "@/router/dashboard/workspaceRoutes";
-import { useRecentVisit } from "@/router/useRecentVisit";
import { useAppFeature, useHelpStore, useUIStateStore } from "@/store";
import type { RouteMapList } from "@/types";
-import { isDev } from "@/utils";
interface LocalState {
helpTimer: number | undefined;
@@ -33,12 +30,10 @@ 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
@@ -77,16 +72,4 @@ watch(
}
}
);
-
-onMounted(() => {
- if (
- isDev() &&
- lastVisit.value?.path &&
- route.name?.toString() === WORKSPACE_HOME_MODULE
- ) {
- router.replace({
- path: lastVisit.value?.path,
- });
- }
-});
</script>
diff --git a/frontend/src/router/dashboard/workspace.ts b/frontend/src/router/dashboard/workspace.ts
index ea079f3875..3034efbab6 100644
--- a/frontend/src/router/dashboard/workspace.ts
+++ b/frontend/src/router/dashboard/workspace.ts
@@ -1,12 +1,13 @@
import { startCase } from "lodash-es";
import type { RouteRecordRaw } from "vue-router";
+import DummyRootView from "@/DummyRootView";
import { t } from "@/plugins/i18n";
import MyIssues from "@/views/MyIssues.vue";
import {
PROJECT_V1_ROUTE_DASHBOARD,
INSTANCE_ROUTE_DASHBOARD,
ENVIRONMENT_V1_ROUTE_DASHBOARD,
- WORKSPACE_HOME_MODULE,
+ WORKSPACE_ROOT_MODULE,
WORKSPACE_ROUTE_MY_ISSUES,
WORKSPACE_ROUTE_EXPORT_CENTER,
WORKSPACE_ROUTE_ANOMALY_CENTER,
@@ -32,39 +33,39 @@ import {
WORKSPACE_ROUTE_IM,
} from "./workspaceRoutes";
-const homePage: RouteRecordRaw = {
+const rootRoute: 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",
- ];
- },
- },
+ name: WORKSPACE_ROOT_MODULE,
components: {
- content: MyIssues,
- leftSidebar: () => import("@/views/DashboardSidebar.vue"),
- },
- props: {
- content: true,
- leftSidebar: true,
+ content: DummyRootView,
},
};
const workspaceRoutes: RouteRecordRaw[] = [
+ rootRoute,
{
- ...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/router/dashboard/workspaceRoutes.ts b/frontend/src/router/dashboard/workspaceRoutes.ts
index e32c28d53c..61230328bc 100644
--- a/frontend/src/router/dashboard/workspaceRoutes.ts
+++ b/frontend/src/router/dashboard/workspaceRoutes.ts
@@ -1,4 +1,4 @@
-export const WORKSPACE_HOME_MODULE = "workspace.home";
+export const WORKSPACE_ROOT_MODULE = "workspace.root";
export const WORKSPACE_ROUTE_MY_ISSUES = "workspace.my-issues";
export const WORKSPACE_ROUTE_REVIEW_CENTER = "workspace.review-center";
export const WORKSPACE_ROUTE_EXPORT_CENTER = "workspace.export-center";
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 03f056b626..c0b6133a69 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -29,7 +29,7 @@ import {
ENVIRONMENT_V1_ROUTE_DASHBOARD,
INSTANCE_ROUTE_DASHBOARD,
PROJECT_V1_ROUTE_DASHBOARD,
- WORKSPACE_HOME_MODULE,
+ WORKSPACE_ROOT_MODULE,
} from "./dashboard/workspaceRoutes";
import { SETTING_ROUTE } from "./dashboard/workspaceSetting";
import sqlEditorRoutes from "./sqlEditor";
@@ -79,10 +79,10 @@ router.beforeEach((to, from, next) => {
const fromModule = from.name
? from.name.toString().split(".")[0]
- : WORKSPACE_HOME_MODULE;
+ : WORKSPACE_ROOT_MODULE;
const toModule = to.name
? to.name.toString().split(".")[0]
- : WORKSPACE_HOME_MODULE;
+ : WORKSPACE_ROOT_MODULE;
if (toModule != fromModule) {
routerStore.setBackPath(from.fullPath);
@@ -119,7 +119,7 @@ router.beforeEach((to, from, next) => {
location.replace(to.query.redirect);
return;
}
- next({ name: WORKSPACE_HOME_MODULE, replace: true });
+ next({ name: WORKSPACE_ROOT_MODULE, replace: true });
} else {
next();
}
diff --git a/frontend/src/router/useRecentVisit.ts b/frontend/src/router/useRecentVisit.ts
index 18a9e4a656..59d5087d95 100644
--- a/frontend/src/router/useRecentVisit.ts
+++ b/frontend/src/router/useRecentVisit.ts
@@ -1,6 +1,7 @@
import { useLocalStorage, useDebounce } from "@vueuse/core";
import { computed, ref, watch, nextTick } from "vue";
import { useRoute } from "vue-router";
+import { WORKSPACE_ROOT_MODULE } from "./dashboard/workspaceRoutes";
type RecentVisit = {
title: string;
@@ -46,7 +47,16 @@ export function useRecentVisit() {
useDebounce(currentRoute, 50),
async (currentRoute) => {
if (!currentRoute) return;
- if (currentRoute.path.startsWith("/auth") || currentRoute.path.startsWith("/sql-editor")) {
+ 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
diff --git a/frontend/src/store/modules/v1/setting.ts b/frontend/src/store/modules/v1/setting.ts
index fbb2f98fb8..b3a3c7b559 100644
--- a/frontend/src/store/modules/v1/setting.ts
+++ b/frontend/src/store/modules/v1/setting.ts
@@ -1,4 +1,5 @@
import { defineStore } from "pinia";
+import { computed } from "vue";
import { settingServiceClient } from "@/grpcweb";
import { settingNamePrefix } from "@/store/modules/v1/common";
import type {
@@ -130,3 +131,10 @@ export const useSettingV1Store = defineStore("setting_v1", {
},
},
});
+
+export const useSettingByName = (name: SettingName) => {
+ const store = useSettingV1Store();
+ const setting = computed(() => store.getSettingByName(name));
+ store.getOrFetchSettingByName(name);
+ return setting;
+};
diff --git a/frontend/src/types/appProfile.ts b/frontend/src/types/appProfile.ts
index 37811a35bb..7321860669 100644
--- a/frontend/src/types/appProfile.ts
+++ b/frontend/src/types/appProfile.ts
@@ -1,4 +1,4 @@
-export type AppMode = "CONSOLE" | "SQL-EDITOR";
+export type WorkspaceMode = "CONSOLE" | "EDITOR";
export type AppFeatures = {
// Use simple and accurate phrases. Namespace if needed
@@ -38,7 +38,7 @@ export type AppFeatures = {
};
export type AppProfile = {
- mode: AppMode;
+ mode: WorkspaceMode;
embedded: boolean; // Whether the web app is embedded within iframe or not
features: AppFeatures;
};
diff --git a/frontend/src/views/DashboardSidebar.vue b/frontend/src/views/DashboardSidebar.vue
index 6814dedf93..2f0969cd33 100644
--- a/frontend/src/views/DashboardSidebar.vue
+++ b/frontend/src/views/DashboardSidebar.vue
@@ -32,7 +32,6 @@ 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,
@@ -81,10 +80,8 @@ const getItemClass = (item: SidebarItem): string[] => {
return classes;
}
if (
- (item.name === WORKSPACE_ROUTE_MEMBERS &&
- current?.toString() === WORKSPACE_ROUTE_USER_PROFILE) ||
- (item.name === WORKSPACE_ROUTE_MY_ISSUES &&
- current?.toString() === WORKSPACE_HOME_MODULE)
+ item.name === WORKSPACE_ROUTE_MEMBERS &&
+ current?.toString() === WORKSPACE_ROUTE_USER_PROFILE
) {
classes.push("router-link-active", "bg-link-hover");
return classes;
diff --git a/frontend/src/views/Page403.vue b/frontend/src/views/Page403.vue
index 251fdac1db..706478c15c 100644
--- a/frontend/src/views/Page403.vue
+++ b/frontend/src/views/Page403.vue
@@ -21,11 +21,11 @@
<script lang="ts" setup>
import { NButton } from "naive-ui";
import { useRouter } from "vue-router";
-import { WORKSPACE_HOME_MODULE } from "@/router/dashboard/workspaceRoutes";
+import { WORKSPACE_ROOT_MODULE } from "@/router/dashboard/workspaceRoutes";
const router = useRouter();
const goHome = () => {
- router.push({ name: WORKSPACE_HOME_MODULE });
+ router.push({ name: WORKSPACE_ROOT_MODULE });
};
</script>
diff --git a/frontend/src/views/Page404.vue b/frontend/src/views/Page404.vue
index 37e53c8c72..b299c4b45c 100644
--- a/frontend/src/views/Page404.vue
+++ b/frontend/src/views/Page404.vue
@@ -21,11 +21,11 @@
<script lang="ts" setup>
import { NButton } from "naive-ui";
import { useRouter } from "vue-router";
-import { WORKSPACE_HOME_MODULE } from "@/router/dashboard/workspaceRoutes";
+import { WORKSPACE_ROOT_MODULE } from "@/router/dashboard/workspaceRoutes";
const router = useRouter();
const goHome = () => {
- router.push({ name: WORKSPACE_HOME_MODULE });
+ router.push({ name: WORKSPACE_ROOT_MODULE });
};
</script>
diff --git a/frontend/src/views/sql-editor/AsidePanel/GutterBar/GutterBar.vue b/frontend/src/views/sql-editor/AsidePanel/GutterBar/GutterBar.vue
index 27567854ba..1e9ce51406 100644
--- a/frontend/src/views/sql-editor/AsidePanel/GutterBar/GutterBar.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/GutterBar/GutterBar.vue
@@ -108,7 +108,7 @@ const hideSettingButton = computed(() => {
return true;
}
- return true;
+ return false;
});
const handleClickTab = (target: AsidePanelTab) => {