Skip to content

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

chore: release sql editor custom theme (#20690)

ecmadao4d81dff16e1a
diff --git a/frontend/src/react/pages/settings/general/SQLEditorSection.test.tsx b/frontend/src/react/pages/settings/general/SQLEditorSection.test.tsx
index eae85de481..a610af895b 100644
--- a/frontend/src/react/pages/settings/general/SQLEditorSection.test.tsx
+++ b/frontend/src/react/pages/settings/general/SQLEditorSection.test.tsx
@@ -55,7 +55,6 @@ vi.mock("react-i18next", () => ({
vi.mock("@/utils", () => ({
hasWorkspacePermissionV2: mocks.hasWorkspacePermissionV2,
- isDev: () => true,
}));
vi.mock("@/react/hooks/useAppState", () => ({
@@ -148,7 +147,14 @@ beforeEach(() => {
root = createRoot(container);
mocks.profile.sqlEditorThemeId = "";
mocks.profile.sqlEditorCustomTheme = undefined;
+ mocks.profile.sqlResultSize = 0n;
+ mocks.profile.queryTimeout = undefined;
+ mocks.policy.disableExport = false;
+ mocks.policy.disableCopyData = false;
+ mocks.policy.allowAdminDataSource = false;
+ mocks.policy.maximumResultRows = 0n;
mocks.updateWorkspaceProfile.mockClear();
+ mocks.upsertPolicy.mockClear();
mocks.hasWorkspacePermissionV2.mockReturnValue(true);
});
@@ -200,6 +206,25 @@ describe("SQLEditorSection theme", () => {
]);
});
+ test("saving a theme-only change does not upsert unchanged query policy", async () => {
+ const ref = createRef<SectionHandle>();
+ render(
+ <SQLEditorSection ref={ref} title="SQL Editor" onDirtyChange={() => {}} />
+ );
+
+ const darkSegment = querySegment("Default Dark");
+ expect(darkSegment).toBeTruthy();
+ act(() => {
+ darkSegment?.querySelector("input")?.click();
+ });
+
+ await act(async () => {
+ await ref.current?.update();
+ });
+
+ expect(mocks.upsertPolicy).not.toHaveBeenCalled();
+ });
+
test("selecting Custom + editing an anchor yields a full-token draft with stable uuid", async () => {
const ref = createRef<SectionHandle>();
render(
diff --git a/frontend/src/react/pages/settings/general/SQLEditorSection.tsx b/frontend/src/react/pages/settings/general/SQLEditorSection.tsx
index 065f3003ef..f3a2f4e713 100644
--- a/frontend/src/react/pages/settings/general/SQLEditorSection.tsx
+++ b/frontend/src/react/pages/settings/general/SQLEditorSection.tsx
@@ -46,7 +46,7 @@ import {
} from "@/types/proto-es/v1/org_policy_service_pb";
import { SQLEditorThemeSettingSchema } from "@/types/proto-es/v1/setting_service_pb";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
-import { hasWorkspacePermissionV2, isDev } from "@/utils";
+import { hasWorkspacePermissionV2 } from "@/utils";
import { ThemeAnchorEditor } from "./sql-editor-theme/ThemeAnchorEditor";
import { ThemePreview } from "./sql-editor-theme/ThemePreview";
import type { SectionHandle } from "./useSettingSection";
@@ -108,7 +108,6 @@ export const SQLEditorSection = forwardRef<
BUILTIN_EDITOR_THEMES
);
useEffect(() => {
- if (!isDev()) return;
let active = true;
void getAvailableEditorThemes().then((themes) => {
if (active) setEditorThemes(themes);
@@ -275,6 +274,17 @@ export const SQLEditorSection = forwardRef<
);
}, [getInitialTheme, selectedThemeId, customDraft]);
+ const isPolicyDirty = useCallback(() => {
+ const init = getInitialState();
+ const maximumResultRows = state.maximumResultRows ?? 0;
+ return (
+ init.disableExport !== state.disableExport ||
+ init.disableCopyData !== state.disableCopyData ||
+ init.allowAdminDataSource !== state.allowAdminDataSource ||
+ init.maximumResultRows !== maximumResultRows
+ );
+ }, [getInitialState, state]);
+
const isDirty = useCallback(
() =>
!isEqual(normalizeForCompare(state), getInitialState()) || isThemeDirty(),
@@ -323,23 +333,25 @@ export const SQLEditorSection = forwardRef<
}
// Update policy (toggles + rows)
- await useAppStore.getState().upsertPolicy({
- parentPath: resource,
- policy: {
- type: PolicyType.DATA_QUERY,
- resourceType: PolicyResourceType.WORKSPACE,
+ if (isPolicyDirty()) {
+ await useAppStore.getState().upsertPolicy({
+ parentPath: resource,
policy: {
- case: "queryDataPolicy",
- value: create(QueryDataPolicySchema, {
- ...policyPayload,
- disableExport: state.disableExport,
- disableCopyData: state.disableCopyData,
- allowAdminDataSource: state.allowAdminDataSource,
- maximumResultRows,
- }),
+ type: PolicyType.DATA_QUERY,
+ resourceType: PolicyResourceType.WORKSPACE,
+ policy: {
+ case: "queryDataPolicy",
+ value: create(QueryDataPolicySchema, {
+ ...policyPayload,
+ disableExport: state.disableExport,
+ disableCopyData: state.disableCopyData,
+ allowAdminDataSource: state.allowAdminDataSource,
+ maximumResultRows,
+ }),
+ },
},
- },
- });
+ });
+ }
// Update SQL Editor theme if changed.
if (isThemeDirty()) {
@@ -364,6 +376,7 @@ export const SQLEditorSection = forwardRef<
resource,
policyPayload,
getInitialState,
+ isPolicyDirty,
isThemeDirty,
selectedThemeId,
customDraft,
@@ -566,62 +579,58 @@ export const SQLEditorSection = forwardRef<
</PermissionGuard>
{/* SQL Editor theme — dev-only until the feature ships. */}
- {isDev() && (
- <PermissionGuard
- permissions={["bb.settings.setWorkspaceProfile"]}
- display="block"
- >
- <div className="flex flex-col gap-y-3">
- <div>
- <p className="text-base font-semibold">
- {t("settings.general.workspace.sql-editor-theme.self")}
- </p>
- <p className="text-sm text-gray-400 mt-1">
- {t("settings.general.workspace.sql-editor-theme.description")}
- </p>
- </div>
+ <PermissionGuard
+ permissions={["bb.settings.setWorkspaceProfile"]}
+ display="block"
+ >
+ <div className="flex flex-col gap-y-3">
+ <div>
+ <p className="text-base font-semibold">
+ {t("settings.general.workspace.sql-editor-theme.self")}
+ </p>
+ <p className="text-sm text-gray-400 mt-1">
+ {t("settings.general.workspace.sql-editor-theme.description")}
+ </p>
+ </div>
- <SegmentedControl
- ariaLabel={t(
- "settings.general.workspace.sql-editor-theme.self"
- )}
+ <SegmentedControl
+ ariaLabel={t("settings.general.workspace.sql-editor-theme.self")}
+ disabled={!canSetWorkspaceProfile}
+ value={isCustomSelected ? CUSTOM_THEME_OPTION : selectedThemeId}
+ onValueChange={handleSelectTheme}
+ options={[
+ ...PRESETS.map((preset) => ({
+ value: preset.id,
+ label: preset.name,
+ })),
+ {
+ value: CUSTOM_THEME_OPTION,
+ label: t(
+ "settings.general.workspace.sql-editor-theme.custom"
+ ),
+ },
+ ]}
+ />
+
+ {isCustomSelected && customDraft && (
+ <ThemeAnchorEditor
+ value={themeToAnchors(customDraft)}
+ editorTheme={customDraft.monacoBase}
+ editorThemes={editorThemes}
disabled={!canSetWorkspaceProfile}
- value={isCustomSelected ? CUSTOM_THEME_OPTION : selectedThemeId}
- onValueChange={handleSelectTheme}
- options={[
- ...PRESETS.map((preset) => ({
- value: preset.id,
- label: preset.name,
- })),
- {
- value: CUSTOM_THEME_OPTION,
- label: t(
- "settings.general.workspace.sql-editor-theme.custom"
- ),
- },
- ]}
+ onChange={handleAnchorsChange}
+ onEditorThemeChange={handleEditorThemeChange}
/>
+ )}
- {isCustomSelected && customDraft && (
- <ThemeAnchorEditor
- value={themeToAnchors(customDraft)}
- editorTheme={customDraft.monacoBase}
- editorThemes={editorThemes}
- disabled={!canSetWorkspaceProfile}
- onChange={handleAnchorsChange}
- onEditorThemeChange={handleEditorThemeChange}
- />
- )}
-
- <div className="flex flex-col gap-y-2">
- <p className="text-sm font-medium text-control">
- {t("common.preview")}
- </p>
- <ThemePreview theme={previewTheme} />
- </div>
+ <div className="flex flex-col gap-y-2">
+ <p className="text-sm font-medium text-control">
+ {t("common.preview")}
+ </p>
+ <ThemePreview theme={previewTheme} />
</div>
- </PermissionGuard>
- )}
+ </div>
+ </PermissionGuard>
</div>
</div>
);