Skip to content

Commit 2b4022e

Browse files
Copilotsawka
andcommitted
Make configui defaults first-class
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
1 parent 57868f6 commit 2b4022e

4 files changed

Lines changed: 326 additions & 150 deletions

File tree

frontend/app/configui/configvalidation.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
import { describe, expect, it } from "vitest";
55
import {
6+
getEffectiveConfigValue,
7+
isConfigValueOverridden,
68
normalizeConfigStringInput,
79
validateConfigNumberInput,
810
validateConfigStringInput,
@@ -32,4 +34,12 @@ describe("configvalidation", () => {
3234
value: 256,
3335
});
3436
});
37+
38+
it("distinguishes overridden values from inherited defaults", () => {
39+
expect(isConfigValueOverridden(undefined)).toBe(false);
40+
expect(isConfigValueOverridden(false)).toBe(true);
41+
expect(isConfigValueOverridden(0.95)).toBe(true);
42+
expect(getEffectiveConfigValue(undefined, 0.95)).toBe(0.95);
43+
expect(getEffectiveConfigValue(0.95, 0.9)).toBe(0.95);
44+
});
3545
});

frontend/app/configui/configvalidation.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,17 @@ export type ConfigNumberValidationOptions = {
1515
integer?: boolean;
1616
};
1717

18+
export function isConfigValueOverridden<T>(value: T | undefined): boolean {
19+
return value != null;
20+
}
21+
22+
export function getEffectiveConfigValue<T>(value: T | undefined, defaultValue: T): T {
23+
if (value != null) {
24+
return value;
25+
}
26+
return defaultValue;
27+
}
28+
1829
export function normalizeConfigStringInput(value: string, options?: ConfigStringValidationOptions): string {
1930
if (options?.trim === false) {
2031
return value;

0 commit comments

Comments
 (0)