Skip to content

Commit 8e93792

Browse files
committed
chore: add protection against all custom theme colors being the same
1 parent 6c3adc0 commit 8e93792

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

frontend/__tests__/root/config.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,8 +527,6 @@ describe("Config", () => {
527527
expect(Config.setCustomThemeColors(customThemeColors(10))).toBe(true);
528528

529529
expect(Config.setCustomThemeColors(customThemeColors(9))).toBe(false);
530-
expect(Config.setCustomThemeColors([] as any)).toBe(false);
531-
expect(Config.setCustomThemeColors(["invalid"] as any)).toBe(false);
532530
expect(Config.setCustomThemeColors(customThemeColors(5))).toBe(false);
533531
expect(Config.setCustomThemeColors(customThemeColors(11))).toBe(false);
534532

@@ -931,7 +929,9 @@ describe("Config", () => {
931929
});
932930

933931
function customThemeColors(n: number): CustomThemeColors {
934-
return new Array(n).fill("#000") as CustomThemeColors;
932+
const arr = new Array(n).fill("#000") as CustomThemeColors;
933+
arr[0] = "#123456"; // we have a protection against all colors being the same
934+
return arr;
935935
}
936936

937937
function testBoolean(fn: (val: boolean) => boolean): void {

frontend/src/ts/config-metadata.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { isDevEnvironment, reloadAfter } from "./utils/misc";
77
import * as ConfigSchemas from "@monkeytype/schemas/configs";
88
import { roundTo1 } from "@monkeytype/util/numbers";
99
import { capitalizeFirstLetter } from "./utils/strings";
10+
import { getDefaultConfig } from "./constants/default-config";
1011
// type SetBlock = {
1112
// [K in keyof ConfigSchemas.Config]?: ConfigSchemas.Config[K][];
1213
// };
@@ -710,6 +711,14 @@ export const configMetadata: ConfigMetadataObject = {
710711
icon: "fa-palette",
711712
displayString: "custom theme colors",
712713
changeRequiresRestart: false,
714+
overrideValue: ({ value }) => {
715+
const allColorsThesame = value.every((color) => color === value[0]);
716+
if (allColorsThesame) {
717+
return getDefaultConfig().customThemeColors;
718+
} else {
719+
return value;
720+
}
721+
},
713722
},
714723

715724
// hide elements

0 commit comments

Comments
 (0)