Skip to content

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

chore(frontend): refactor standalone mode to actuator store (#8767)

Liu Ji6e633dced582
diff --git a/frontend/src/layouts/SQLEditorLayout.vue b/frontend/src/layouts/SQLEditorLayout.vue
index a3dc7948b3..f19c668329 100644
--- a/frontend/src/layouts/SQLEditorLayout.vue
+++ b/frontend/src/layouts/SQLEditorLayout.vue
@@ -24,39 +24,17 @@
</template>
<script lang="ts" setup>
-import { useLocalStorage } from "@vueuse/core";
-import { computed, onMounted } from "vue";
+import { storeToRefs } from "pinia";
+import { computed } from "vue";
import BannersWrapper from "@/components/BannersWrapper.vue";
import ProvideSQLEditorContext from "@/components/ProvideSQLEditorContext.vue";
-import {
- pushNotification,
- useActuatorV1Store,
- useSQLEditorStore,
-} from "@/store";
-import { SQLEditorMode } from "@/types";
+import { pushNotification, useActuatorV1Store } from "@/store";
const actuatorStore = useActuatorV1Store();
-const sqlEditorStore = useSQLEditorStore();
+const { pageMode } = storeToRefs(actuatorStore);
const showBanners = computed(() => {
- return sqlEditorStore.mode === "BUNDLED";
-});
-
-onMounted(() => {
- const searchParams = new URLSearchParams(window.location.search);
- let mode = searchParams.get("mode") as SQLEditorMode;
- const cachedMode = useLocalStorage<SQLEditorMode>(
- "bb.sql-editor.mode",
- "BUNDLED"
- );
- if (mode != "BUNDLED" && mode != "STANDALONE") {
- mode = cachedMode.value;
- }
-
- cachedMode.value = mode;
- sqlEditorStore.setSQLEditorState({
- mode,
- });
+ return pageMode.value === "BUNDLED";
});
const ping = () => {
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 65d29ff076..4f310ff5c6 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -1,3 +1,4 @@
+import { useLocalStorage } from "@vueuse/core";
import axios from "axios";
import isEmpty from "lodash-es/isEmpty";
import Long from "long";
@@ -20,6 +21,7 @@ import {
useActuatorV1Store,
useAuthStore,
useSubscriptionV1Store,
+ PageMode,
} from "./store";
import {
databaseSlug,
@@ -166,9 +168,20 @@ app
// We need to restore the basic info in order to perform route authentication.
// Even using the <suspense>, it's still too late, thus we do the fetch here.
// We use finally because we always want to mount the app regardless of the error.
-const initActuator = () => {
+const initActuator = async () => {
const actuatorStore = useActuatorV1Store();
- return actuatorStore.fetchServerInfo();
+
+ const searchParams = new URLSearchParams(window.location.search);
+ let mode = searchParams.get("mode") as PageMode;
+ const cachedMode = useLocalStorage<PageMode>("bb.page-mode", "BUNDLED");
+ if (mode !== "BUNDLED" && mode !== "STANDALONE") {
+ mode = cachedMode.value;
+ }
+
+ cachedMode.value = mode;
+ actuatorStore.pageMode = mode;
+
+ actuatorStore.fetchServerInfo();
};
const initSubscription = () => {
const subscriptionStore = useSubscriptionV1Store();
diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.ts
index 1034dd1161..71648f685d 100644
--- a/frontend/src/store/modules/sqlEditor.ts
+++ b/frontend/src/store/modules/sqlEditor.ts
@@ -19,7 +19,6 @@ export const useSQLEditorStore = defineStore("sqlEditor", {
queryHistoryList: [],
isFetchingQueryHistory: false,
isFetchingSheet: false,
- mode: "BUNDLED",
}),
actions: {
diff --git a/frontend/src/store/modules/v1/actuator.ts b/frontend/src/store/modules/v1/actuator.ts
index c3bcf6b655..65969333e7 100644
--- a/frontend/src/store/modules/v1/actuator.ts
+++ b/frontend/src/store/modules/v1/actuator.ts
@@ -14,7 +14,15 @@ const EXTERNAL_URL_PLACEHOLDER =
const GITHUB_API_LIST_BYTEBASE_RELEASE =
"https://api.github.com/repos/bytebase/bytebase/releases";
+export type PageMode =
+ // General mode. Console is full-featured and SQL Editor is bundled in the layout.
+ | "BUNDLED"
+ // Vender customized mode. Hide certain parts (e.g., headers, sidebars) and
+ // some features are disabled or hidden.
+ | "STANDALONE";
+
interface ActuatorState {
+ pageMode: PageMode;
serverInfo?: ActuatorInfo;
releaseInfo: RemovableRef<ReleaseInfo>;
debugLogList: DebugLog[];
@@ -22,6 +30,7 @@ interface ActuatorState {
export const useActuatorV1Store = defineStore("actuator_v1", {
state: (): ActuatorState => ({
+ pageMode: "BUNDLED",
serverInfo: undefined,
releaseInfo: useLocalStorage("bytebase_release", {
ignoreRemindModalTillNextRelease: false,
diff --git a/frontend/src/types/sqlEditor.ts b/frontend/src/types/sqlEditor.ts
index 0475d5a0e7..984fb4c290 100644
--- a/frontend/src/types/sqlEditor.ts
+++ b/frontend/src/types/sqlEditor.ts
@@ -8,12 +8,6 @@ export type CompletionItems = monaco.languages.CompletionItem[];
export type Language = "sql" | "javascript" | "redis";
-export type SQLEditorMode =
- // SQL Editor is bundled with main console.
- | "BUNDLED"
- // SQL Editor is by its own.
- | "STANDALONE";
-
export const EngineTypesUsingSQL = [
"MYSQL",
"CLICKHOUSE",
diff --git a/frontend/src/types/store.ts b/frontend/src/types/store.ts
index 6ccf7a6714..cd5fed526e 100644
--- a/frontend/src/types/store.ts
+++ b/frontend/src/types/store.ts
@@ -19,7 +19,6 @@ import { Notification } from "./notification";
import { Principal } from "./principal";
import { Project } from "./project";
import { DatabaseMetadata } from "./proto/store/database";
-import { SQLEditorMode } from "./sqlEditor";
import { VCS } from "./vcs";
export interface PrincipalState {
@@ -94,7 +93,6 @@ export interface SQLEditorState {
isFetchingQueryHistory: boolean;
isFetchingSheet: boolean;
isShowExecutingHint: boolean;
- mode: SQLEditorMode;
}
export interface DebugState {
diff --git a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
index 8ca23e23b6..9626889bbc 100644
--- a/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/DatabaseTree.vue
@@ -54,15 +54,16 @@
import { useMounted, useThrottleFn } from "@vueuse/core";
import { head } from "lodash-es";
import { NTree, NInput, NDropdown, DropdownOption, TreeOption } from "naive-ui";
+import { storeToRefs } from "pinia";
import { ref, computed, nextTick, watch, h } from "vue";
import { useI18n } from "vue-i18n";
import {
+ useActuatorV1Store,
useCurrentUserV1,
useDBSchemaV1Store,
useDatabaseV1Store,
useInstanceV1Store,
useIsLoggedIn,
- useSQLEditorStore,
useTabStore,
} from "@/store";
import { useSQLEditorTreeStore } from "@/store/modules/sqlEditorTree";
@@ -112,7 +113,7 @@ defineEmits<{
}>();
const { t } = useI18n();
-const sqlEditorStore = useSQLEditorStore();
+const { pageMode } = storeToRefs(useActuatorV1Store());
const treeStore = useSQLEditorTreeStore();
const tabStore = useTabStore();
const databaseStore = useDatabaseV1Store();
@@ -165,7 +166,7 @@ const dropdownOptions = computed((): DropdownOptionWithTreeNode[] => {
});
}
}
- if (type === "database" && sqlEditorStore.mode === "BUNDLED") {
+ if (type === "database" && pageMode.value === "BUNDLED") {
const database = target as ComposedDatabase;
if (instanceV1HasAlterSchema(database.instanceEntity)) {
items.push({
diff --git a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
index 7aa73a91f2..e784fc3ead 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ExecuteHint.vue
@@ -64,15 +64,16 @@
</template>
<script lang="ts" setup>
+import { storeToRefs } from "pinia";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { parseSQL, isDDLStatement } from "@/components/MonacoEditor/sqlParser";
import {
pushNotification,
+ useActuatorV1Store,
useDatabaseV1Store,
useTabStore,
- useSQLEditorStore,
} from "@/store";
import { UNKNOWN_ID } from "@/types";
import AdminModeButton from "./AdminModeButton.vue";
@@ -87,7 +88,7 @@ const DMLIssueTemplate = "bb.issue.database.data.update";
const router = useRouter();
const { t } = useI18n();
const tabStore = useTabStore();
-const sqlEditorStore = useSQLEditorStore();
+const { pageMode } = storeToRefs(useActuatorV1Store());
const sqlStatement = computed(
() => tabStore.currentTab.selectedStatement || tabStore.currentTab.statement
@@ -98,7 +99,7 @@ const isDDL = computed(() => {
return data !== null ? isDDLStatement(data, "some") : false;
});
-const showActionButtons = computed(() => sqlEditorStore.mode === "BUNDLED");
+const showActionButtons = computed(() => pageMode.value === "BUNDLED");
const handleClose = () => {
emit("close");
diff --git a/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue b/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue
index f74077d3f3..f271bfb32f 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ReadonlyDatasourceHint.vue
@@ -9,7 +9,7 @@
<template v-if="allowManageInstance">
{{ $t("instance.no-read-only-data-source-warn-for-owner-dba") }}
<span
- v-if="mode === 'BUNDLED'"
+ v-if="pageMode === 'BUNDLED'"
class="underline text-accent cursor-pointer hover:opacity-80"
@click="gotoInstanceDetailPage"
>
@@ -27,7 +27,7 @@
import { storeToRefs } from "pinia";
import { computed } from "vue";
import { useRouter } from "vue-router";
-import { useCurrentUserV1, useSQLEditorStore, useTabStore } from "@/store";
+import { useCurrentUserV1, useTabStore, useActuatorV1Store } from "@/store";
import { ComposedInstance, TabMode, UNKNOWN_ID } from "@/types";
import { DataSourceType } from "@/types/proto/v1/instance_service";
import { hasWorkspacePermissionV1, instanceV1Slug } from "@/utils";
@@ -37,7 +37,7 @@ const props = defineProps<{
}>();
const router = useRouter();
-const { mode } = storeToRefs(useSQLEditorStore());
+const { pageMode } = storeToRefs(useActuatorV1Store());
const tabStore = useTabStore();
const me = useCurrentUserV1();
diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vue
index f147f3b963..3032bbe361 100644
--- a/frontend/src/views/sql-editor/SQLEditorPage.vue
+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue
@@ -153,6 +153,7 @@ import SchemaEditorModal from "@/components/AlterSchemaPrepForm/SchemaEditorModa
import { Drawer, DrawerContent, InstanceV1Name } from "@/components/v2";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import {
+ useActuatorV1Store,
useCurrentUserV1,
useDatabaseV1Store,
useInstanceV1ByUID,
@@ -195,6 +196,7 @@ const state = reactive<LocalState>({
const tabStore = useTabStore();
const databaseStore = useDatabaseV1Store();
+const actuatorStore = useActuatorV1Store();
const sqlEditorStore = useSQLEditorStore();
const currentUserV1 = useCurrentUserV1();
// provide context for SQL Editor
@@ -203,7 +205,7 @@ const { events: editorEvents } = provideSQLEditorContext();
const { showPanel: showSheetPanel } = provideSheetContext();
const { show: showSecondarySidebar } = provideSecondarySidebarContext();
-const showQuickstart = computed(() => sqlEditorStore.mode === "BUNDLED");
+const showQuickstart = computed(() => actuatorStore.pageMode === "BUNDLED");
const isDisconnected = computed(() => tabStore.isDisconnected);
const isFetchingSheet = computed(() => sqlEditorStore.isFetchingSheet);
diff --git a/frontend/src/views/sql-editor/TabList/TabList.vue b/frontend/src/views/sql-editor/TabList/TabList.vue
index df674da07c..13d9cc1ea4 100644
--- a/frontend/src/views/sql-editor/TabList/TabList.vue
+++ b/frontend/src/views/sql-editor/TabList/TabList.vue
@@ -53,12 +53,13 @@
<script lang="ts" setup>
import { useResizeObserver } from "@vueuse/core";
import { useDialog } from "naive-ui";
+import { storeToRefs } from "pinia";
import scrollIntoView from "scroll-into-view-if-needed";
import { ref, reactive, nextTick, computed, onMounted, watch } from "vue";
import { useI18n } from "vue-i18n";
import Draggable from "vuedraggable";
import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
-import { useSQLEditorStore, useTabStore } from "@/store";
+import { useTabStore, useActuatorV1Store } from "@/store";
import type { TabInfo } from "@/types";
import { TabMode } from "@/types";
import {
@@ -86,6 +87,7 @@ const state = reactive<LocalState>({
dragging: false,
hoverTabId: "",
});
+const { pageMode } = storeToRefs(useActuatorV1Store());
const { events: sheetEvents } = useSheetContext();
const tabListRef = ref<InstanceType<typeof Draggable>>();
const context = provideTabListContext();
@@ -97,7 +99,7 @@ const scrollState = reactive({
});
const showProfileDropdown = computed(() => {
- return useSQLEditorStore().mode === "BUNDLED";
+ return pageMode.value === "BUNDLED";
});
const handleSelectTab = async (tab: TabInfo) => {