Skip to content

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

feat: preserve query fields even when page changed (#10833)

boojack3d2c94e6c502
diff --git a/frontend/naive-ui.config.ts b/frontend/naive-ui.config.ts
index 53a0f763b1..502838ed3b 100644
--- a/frontend/naive-ui.config.ts
+++ b/frontend/naive-ui.config.ts
@@ -7,13 +7,9 @@ import {
} from "naive-ui";
import { computed } from "vue";
import { callCssVariable } from "@/utils";
-import { customTheme } from "@/utils/customTheme";
import { curLocale } from "./src/plugins/i18n";
export const themeOverrides = computed((): GlobalThemeOverrides => {
- // Touch customTheme.value here, so when customTheme changes, this computed
- // value will be re-evaluated reactively
- console.debug(customTheme.value);
return {
common: {
primaryColor: callCssVariable("--color-accent"),
@@ -46,9 +42,6 @@ export const themeOverrides = computed((): GlobalThemeOverrides => {
});
export const darkThemeOverrides = computed((): GlobalThemeOverrides => {
- // Touch customTheme.value here, so when customTheme changes, this computed
- // value will be re-evaluated reactively
- console.debug(customTheme.value);
return {
common: {
primaryColor: callCssVariable("--color-matrix-green"),
diff --git a/frontend/src/App.vue b/frontend/src/App.vue
index 1eec63de20..5ba2758df0 100644
--- a/frontend/src/App.vue
+++ b/frontend/src/App.vue
@@ -1,5 +1,10 @@
<template>
- <CustomThemeProvider>
+ <NConfigProvider
+ :key="key"
+ :locale="generalLang"
+ :date-locale="dateLang"
+ :theme-overrides="themeOverrides"
+ >
<Watermark />
<NNotificationProvider
@@ -16,17 +21,24 @@
</OverlayStackManager>
</NDialogProvider>
</NNotificationProvider>
- </CustomThemeProvider>
+ </NConfigProvider>
</template>
<script lang="ts" setup>
-import { NDialogProvider, NNotificationProvider } from "naive-ui";
+import { cloneDeep, isEqual } from "lodash-es";
+import {
+ NConfigProvider,
+ NDialogProvider,
+ NNotificationProvider,
+} from "naive-ui";
import { ServerError } from "nice-grpc-common";
import { ClientError, Status } from "nice-grpc-web";
import { reactive, onErrorCaptured } from "vue";
-import { useRouter } from "vue-router";
+import { watch } from "vue";
+import { useRoute, useRouter } from "vue-router";
import Watermark from "@/components/misc/Watermark.vue";
-import CustomThemeProvider from "./CustomThemeProvider.vue";
+import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
+import { provideAppRootContext } from "./AppRootContext";
import NotificationContext from "./NotificationContext.vue";
import KBarWrapper from "./components/KBar/KBarWrapper.vue";
import OverlayStackManager from "./components/misc/OverlayStackManager.vue";
@@ -45,7 +57,9 @@ interface LocalState {
prevLoggedIn: boolean;
}
+const route = useRoute();
const router = useRouter();
+const { key } = provideAppRootContext();
const authStore = useAuthStore();
const notificationStore = useNotificationStore();
@@ -95,4 +109,25 @@ window.addEventListener("bb.oauth.unknown", (event) => {
title: t("oauth.unknown-event"),
});
});
+
+// Preserve specific query fields when navigating between pages.
+watch(route, (current, prev) => {
+ // fields is the list of query fields that we want to preserve.
+ const fields = ["mode", "project", "filter", "customTheme"];
+ const preservedQuery = cloneDeep(current.query);
+ for (const key of fields) {
+ if (preservedQuery[key] === undefined) {
+ preservedQuery[key] = prev.query[key];
+ }
+ }
+ // If the query is the same, we don't need to update the route.
+ if (isEqual(current.query, preservedQuery)) {
+ return;
+ }
+ // Otherwise, replace current route with the preserved query.
+ router.replace({
+ ...current,
+ query: preservedQuery,
+ });
+});
</script>
diff --git a/frontend/src/CustomThemeProvider.vue b/frontend/src/CustomThemeProvider.vue
deleted file mode 100644
index 6d03194ae0..0000000000
--- a/frontend/src/CustomThemeProvider.vue
+++ /dev/null
@@ -1,59 +0,0 @@
-<template>
- <NConfigProvider
- :key="key"
- :locale="generalLang"
- :date-locale="dateLang"
- :theme-overrides="themeOverrides"
- >
- <slot></slot>
- </NConfigProvider>
-</template>
-
-<script lang="ts" setup>
-import { NConfigProvider } from "naive-ui";
-import { watch } from "vue";
-import { useRoute } from "vue-router";
-import { themeOverrides, dateLang, generalLang } from "../naive-ui.config";
-import { provideAppRootContext } from "./AppRootContext";
-import { useLanguage } from "./composables/useLanguage";
-import {
- customTheme as cachedCustomTheme,
- applyCustomTheme,
-} from "./utils/customTheme";
-
-const route = useRoute();
-const { key } = provideAppRootContext();
-const { setLocale } = useLanguage();
-
-watch(
- () => route.fullPath,
- () => {
- const searchParams = new URLSearchParams(window.location.search);
- // Initial custom theme.
- const customTheme =
- searchParams.get("customTheme") || cachedCustomTheme.value;
- if (customTheme) {
- if (customTheme !== cachedCustomTheme.value) {
- // Save custom theme to local storage.
- cachedCustomTheme.value = customTheme;
- }
- }
- // Initial custom language.
- const lang = searchParams.get("lang") || "";
- if (lang) {
- setLocale(lang);
- }
- },
- {
- immediate: true,
- }
-);
-
-watch(
- cachedCustomTheme,
- () => {
- applyCustomTheme();
- },
- { immediate: true }
-);
-</script>
diff --git a/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue b/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue
index f7370f70d1..767f6d211f 100644
--- a/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue
+++ b/frontend/src/components/IssueV1/components/HeaderSection/Actions/review/IssueReviewButtonGroup.vue
@@ -30,18 +30,18 @@ import {
taskRolloutActionDisplayName,
useIssueContext,
} from "@/components/IssueV1";
-import { useCurrentUserV1, usePageMode } from "@/store";
+import { useActuatorV1Store, useCurrentUserV1, usePageMode } from "@/store";
import { PresetRoleType } from "@/types";
import {
IssueStatus,
Issue_Approver_Status,
} from "@/types/proto/v1/issue_service";
import { extractUserResourceName } from "@/utils";
-import { customTheme } from "@/utils/customTheme";
import { ExtraActionOption, IssueStatusActionButtonGroup } from "../common";
import ReviewActionButton from "./ReviewActionButton.vue";
const { t } = useI18n();
+const actuatorStore = useActuatorV1Store();
const currentUser = useCurrentUserV1();
const pageMode = usePageMode();
const { issue, phase, reviewContext, events, activeTask, activeStage } =
@@ -141,7 +141,9 @@ const forceRolloutActionList = computed((): ExtraActionOption[] => {
});
const showIssueReviewActions = computed(() => {
- return !(pageMode.value === "STANDALONE" && customTheme.value === "lixiang");
+ return !(
+ pageMode.value === "STANDALONE" && actuatorStore.customTheme === "lixiang"
+ );
});
const displayMode = computed(() => {
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 53bc80f07b..88e0f75171 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -1,4 +1,3 @@
-import { useLocalStorage } from "@vueuse/core";
import axios from "axios";
import isEmpty from "lodash-es/isEmpty";
import Long from "long";
@@ -37,6 +36,7 @@ import {
sizeToFit,
urlfy,
} from "./utils";
+import { applyCustomTheme } from "./utils/customTheme";
protobufjs.util.Long = Long;
protobufjs.configure();
@@ -159,16 +159,20 @@ app
// We use finally because we always want to mount the app regardless of the error.
const initActuator = async () => {
const actuatorStore = useActuatorV1Store();
-
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;
+ const mode = searchParams.get("mode") as PageMode;
+ if (mode === "BUNDLED" || mode === "STANDALONE") {
+ actuatorStore.pageMode = mode;
+ }
+ const customTheme = searchParams.get("customTheme");
+ if (customTheme) {
+ actuatorStore.customTheme = customTheme;
+ applyCustomTheme(customTheme);
+ }
+ const lang = searchParams.get("lang");
+ if (lang) {
+ i18n.global.locale.value = lang;
}
-
- cachedMode.value = mode;
- actuatorStore.pageMode = mode;
actuatorStore.fetchServerInfo();
};
diff --git a/frontend/src/plugins/i18n.ts b/frontend/src/plugins/i18n.ts
index 8c9a4af8c6..13552a9e67 100644
--- a/frontend/src/plugins/i18n.ts
+++ b/frontend/src/plugins/i18n.ts
@@ -1,6 +1,5 @@
import { useLocalStorage } from "@vueuse/core";
import _ from "lodash-es";
-import { App } from "vue";
import { createI18n } from "vue-i18n";
const localPathPrefix = "../locales/";
@@ -87,8 +86,4 @@ export const te = i18n.global.te;
export const curLocale = i18n.global.locale;
-const install = (app: App) => {
- app.use(i18n);
-};
-
-export default install;
+export default i18n;
diff --git a/frontend/src/store/modules/sqlEditorTree.ts b/frontend/src/store/modules/sqlEditorTree.ts
index dae2df1201..4fcbcae781 100644
--- a/frontend/src/store/modules/sqlEditorTree.ts
+++ b/frontend/src/store/modules/sqlEditorTree.ts
@@ -32,10 +32,10 @@ import {
} from "@/types";
import { Environment } from "@/types/proto/v1/environment_service";
import { emptyConnection, getSemanticLabelValue, groupBy } from "@/utils";
-import { customTheme } from "@/utils/customTheme";
import { useFilterStore } from "./filter";
import { useTabStore } from "./tab";
import {
+ useActuatorV1Store,
useDBSchemaV1Store,
useDatabaseV1Store,
useEnvironmentV1Store,
@@ -55,16 +55,18 @@ const defaultEnvironmentFactor: StatefulFactor = {
disabled: false,
};
-const defaultFactorList = (): StatefulFactor[] => {
- if (customTheme.value === "lixiang") {
- return [defaultEnvironmentFactor];
- } else {
- return [defaultProjectFactor];
- }
-};
-
export const useSQLEditorTreeStore = defineStore("SQL-Editor-Tree", () => {
+ const actuatorStore = useActuatorV1Store();
const { filter } = useFilterStore();
+
+ const defaultFactorList = (): StatefulFactor[] => {
+ if (actuatorStore.customTheme === "lixiang") {
+ return [defaultEnvironmentFactor];
+ } else {
+ return [defaultProjectFactor];
+ }
+ };
+
const factorListInLocalStorage = useLocalStorage<StatefulFactor[]>(
"bb.sql-editor.tree-factor-list",
defaultFactorList(),
@@ -103,6 +105,7 @@ export const useSQLEditorTreeStore = defineStore("SQL-Editor-Tree", () => {
const factorList = ref<StatefulFactor[]>(
cloneDeep(factorListInLocalStorage.value)
);
+
const filteredDatabaseList = computed(() => {
if (filter.database) {
return databaseList.value.filter((database) => {
diff --git a/frontend/src/store/modules/v1/actuator.ts b/frontend/src/store/modules/v1/actuator.ts
index c95125488d..4be8e38f46 100644
--- a/frontend/src/store/modules/v1/actuator.ts
+++ b/frontend/src/store/modules/v1/actuator.ts
@@ -27,6 +27,7 @@ export type PageMode =
interface ActuatorState {
pageMode: PageMode;
+ customTheme?: string;
serverInfo?: ActuatorInfo;
resourcePackage?: ResourcePackage;
releaseInfo: RemovableRef<ReleaseInfo>;
diff --git a/frontend/src/utils/customTheme.ts b/frontend/src/utils/customTheme.ts
index ea055a20cc..a49b41c61d 100644
--- a/frontend/src/utils/customTheme.ts
+++ b/frontend/src/utils/customTheme.ts
@@ -1,11 +1,8 @@
-import { useLocalStorage } from "@vueuse/core";
import { hexToRgb } from "./css";
-export const customTheme = useLocalStorage<string>("bb.custom-theme", "");
-
-export const applyCustomTheme = () => {
+export const applyCustomTheme = (customTheme: string) => {
const rootElement = document.documentElement;
- if (customTheme.value === "lixiang") {
+ if (customTheme === "lixiang") {
rootElement.style.setProperty(
"--color-accent",
hexToRgb("#00665f").join(" ")
diff --git a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
index c5f4c6e48d..801fa4993b 100644
--- a/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/EditorAction.vue
@@ -126,11 +126,11 @@ import {
useInstanceV1ByUID,
useWebTerminalV1Store,
usePageMode,
+ useActuatorV1Store,
} from "@/store";
import type { ExecuteConfig, ExecuteOption, FeatureType } from "@/types";
import { TabMode, UNKNOWN_ID } from "@/types";
import { formatEngineV1, keyboardShortcutStr } from "@/utils";
-import { customTheme } from "@/utils/customTheme";
import { useSQLEditorContext } from "../context";
import AdminModeButton from "./AdminModeButton.vue";
import QueryContextSettingPopover from "./QueryContextSettingPopover.vue";
@@ -150,6 +150,7 @@ const emit = defineEmits<{
(e: "clear-screen"): void;
}>();
+const actuatorStore = useActuatorV1Store();
const state = reactive<LocalState>({});
const tabStore = useTabStore();
const sqlEditorStore = useSQLEditorStore();
@@ -232,7 +233,7 @@ const showQueryContextSettingPopover = computed(() => {
return (
Boolean(selectedInstance.value) &&
tabStore.currentTab.mode !== TabMode.Admin &&
- customTheme.value === "lixiang"
+ actuatorStore.customTheme === "lixiang"
);
});
diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
index 43587138b6..03b84e9389 100644
--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue
@@ -176,6 +176,7 @@ import {
useDatabaseV1Store,
useCurrentUserV1,
usePageMode,
+ useActuatorV1Store,
} from "@/store";
import { useExportData } from "@/store/modules/export";
import {
@@ -196,7 +197,6 @@ import {
hasWorkspacePermissionV2,
instanceV1HasStructuredQueryResult,
} from "@/utils";
-import { customTheme } from "@/utils/customTheme";
import DataBlock from "./DataBlock.vue";
import DataTable from "./DataTable";
import EmptyView from "./EmptyView.vue";
@@ -233,6 +233,7 @@ const state = reactive<LocalState>({
const { dark, keyword } = useSQLResultViewContext();
+const actuatorStore = useActuatorV1Store();
const { t } = useI18n();
const tabStore = useTabStore();
const instanceStore = useInstanceV1Store();
@@ -265,7 +266,7 @@ const showSearchFeature = computed(() => {
});
const showExportButton = computed(() => {
- return customTheme.value !== "lixiang";
+ return actuatorStore.customTheme !== "lixiang";
});
const allowToExportData = computed(() => {