Skip to content

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

fix(sql-editor): infinite re-evaluations of getCustomProjectTitle when customTheme is not empty (#9103)

Liu Ji54a92b0e65f6
diff --git a/frontend/naive-ui.config.ts b/frontend/naive-ui.config.ts
index 502838ed3b..53a0f763b1 100644
--- a/frontend/naive-ui.config.ts
+++ b/frontend/naive-ui.config.ts
@@ -7,9 +7,13 @@ 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"),
@@ -42,6 +46,9 @@ 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/CustomThemeProvider.vue b/frontend/src/CustomThemeProvider.vue
index 16c9afd5af..6d03194ae0 100644
--- a/frontend/src/CustomThemeProvider.vue
+++ b/frontend/src/CustomThemeProvider.vue
@@ -10,19 +10,20 @@
</template>
<script lang="ts" setup>
-import { useLocalStorage } from "@vueuse/core";
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 { applyCustomTheme } from "./utils/customTheme";
+import {
+ customTheme as cachedCustomTheme,
+ applyCustomTheme,
+} from "./utils/customTheme";
const route = useRoute();
const { key } = provideAppRootContext();
const { setLocale } = useLanguage();
-const cachedCustomTheme = useLocalStorage<string>("bb.custom-theme", "");
watch(
() => route.fullPath,
@@ -32,7 +33,6 @@ watch(
const customTheme =
searchParams.get("customTheme") || cachedCustomTheme.value;
if (customTheme) {
- applyCustomTheme(customTheme);
if (customTheme !== cachedCustomTheme.value) {
// Save custom theme to local storage.
cachedCustomTheme.value = customTheme;
@@ -48,4 +48,12 @@ watch(
immediate: true,
}
);
+
+watch(
+ cachedCustomTheme,
+ () => {
+ applyCustomTheme();
+ },
+ { immediate: true }
+);
</script>
diff --git a/frontend/src/utils/customTheme.ts b/frontend/src/utils/customTheme.ts
index d1ad0cff38..4bc113a1e6 100644
--- a/frontend/src/utils/customTheme.ts
+++ b/frontend/src/utils/customTheme.ts
@@ -2,9 +2,11 @@ import { useLocalStorage } from "@vueuse/core";
import { useI18n } from "vue-i18n";
import { hexToRgb } from "./css";
-export const applyCustomTheme = (theme: string) => {
+export const customTheme = useLocalStorage<string>("bb.custom-theme", "");
+
+export const applyCustomTheme = () => {
const rootElement = document.documentElement;
- if (theme === "lixiang") {
+ if (customTheme.value === "lixiang") {
rootElement.style.setProperty(
"--color-accent",
hexToRgb("#00665f").join(" ")
@@ -17,13 +19,16 @@ export const applyCustomTheme = (theme: string) => {
"--color-accent-hover",
hexToRgb("#00554f").join(" ")
);
+ } else {
+ rootElement.style.removeProperty("--color-accent");
+ rootElement.style.removeProperty("--color-accent-disabled");
+ rootElement.style.removeProperty("--color-accent-hover");
}
};
export const getCustomProjectTitle = () => {
const { t } = useI18n();
- const theme = useLocalStorage<string>("bb.custom-theme", "");
- if (theme.value === "lixiang") {
+ if (customTheme.value === "lixiang") {
return t("common.tenant");
}
return t("common.project");
diff --git a/frontend/src/views/sql-editor/AsidePanel/GroupingBar/FactorTag.vue b/frontend/src/views/sql-editor/AsidePanel/GroupingBar/FactorTag.vue
index 44be10a02f..131e560407 100644
--- a/frontend/src/views/sql-editor/AsidePanel/GroupingBar/FactorTag.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/GroupingBar/FactorTag.vue
@@ -37,6 +37,7 @@ import {
const props = defineProps<{
factor: StatefulFactor;
+ allowDisable: boolean;
}>();
const emit = defineEmits<{
(event: "toggle-disabled"): void;
@@ -45,11 +46,6 @@ const emit = defineEmits<{
const treeStore = useSQLEditorTreeStore();
const { factorList, filteredFactorList } = storeToRefs(treeStore);
-const allowDisable = computed(() => {
- // Disallow to disable the only one enabled factor
- return filteredFactorList.value.length > 1;
-});
-
const allowRemove = computed(() => {
const { factor } = props;
// Always allow to remove the disabled factor
@@ -64,7 +60,7 @@ const allowRemove = computed(() => {
const clickable = computed(() => {
if (props.factor.disabled) return true;
- return allowDisable.value;
+ return props.allowDisable;
});
const handleClick = () => {
diff --git a/frontend/src/views/sql-editor/AsidePanel/GroupingBar/GroupingBar.vue b/frontend/src/views/sql-editor/AsidePanel/GroupingBar/GroupingBar.vue
index 9376383773..6b446bab7e 100644
--- a/frontend/src/views/sql-editor/AsidePanel/GroupingBar/GroupingBar.vue
+++ b/frontend/src/views/sql-editor/AsidePanel/GroupingBar/GroupingBar.vue
@@ -9,7 +9,7 @@
class="grouping-bar--tabs"
@update:value="selectPresetFactor"
>
- <NTab name="project">{{ $t("common.project") }}</NTab>
+ <NTab name="project">{{ getCustomProjectTitle() }}</NTab>
<NTab name="instance">{{ $t("common.instance") }}</NTab>
</NTabs>
<div
@@ -66,6 +66,7 @@ import { storeToRefs } from "pinia";
import { computed } from "vue";
import { useSQLEditorTreeStore } from "@/store/modules/sqlEditorTree";
import { StatefulSQLEditorTreeFactor as StatefulFactor } from "@/types";
+import { getCustomProjectTitle } from "@/utils/customTheme";
import FactorPanel from "./FactorPanel.vue";
import FactorTag from "./FactorTag.vue";