keep Manual selected when switching to it from Disabled or Auto

Choosing Manual after an unsaved Disabled or Auto sent `""`, which counts as no change, so BaseSection reset the form to the saved value and the field snapped back to the saved option. Manual now stays selected when the form falls back to the saved value, and it starts from the saved manual args when there are any, otherwise from an empty box.
This commit is contained in:
Josh Hawkins
2026-12-01 23:20:24 -06:00
parent c1f9a3ddbd
commit 4af82b23d6
2 changed files with 77 additions and 6 deletions
@@ -158,6 +158,47 @@ test.describe("hwaccel args widget @medium", () => {
});
});
test("Preset then Disabled then Manual stays on Manual", async ({
frigateApp,
}) => {
await openSettings(frigateApp, "/settings?page=globalFfmpeg");
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
await manual.click();
await expect(manual).toBeChecked();
await expect(manualInput(frigateApp)).toHaveValue("");
});
test("Auto then Manual starts with an empty box", async ({ frigateApp }) => {
await openSettings(frigateApp, "/settings?page=globalFfmpeg");
await radio(frigateApp, "root_hwaccel_args", "auto").click();
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
await manual.click();
await expect(manual).toBeChecked();
await expect(manualInput(frigateApp)).toHaveValue("");
});
test("switching back to Manual shows the saved manual args", async ({
frigateApp,
}) => {
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
ffmpeg: { hwaccel_args: "-hwaccel vaapi" },
});
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
for (const from of ["preset", "disabled", "auto"]) {
await radio(frigateApp, "root_hwaccel_args", from).click();
await manual.click();
await expect(manual).toBeChecked();
await expect(manualInput(frigateApp)).toHaveValue("-hwaccel vaapi");
}
});
test("Disabled keeps the side-by-side layout", async ({ frigateApp }) => {
test.skip(frigateApp.isMobile, "the layout stacks on narrow screens");
await openSettings(frigateApp, "/settings?page=globalFfmpeg");
@@ -251,12 +251,19 @@ export function FfmpegArgsWidget(props: WidgetProps) {
id,
].join(":");
// An empty manual box is no change, so the form falls back to the saved
// value while Manual stays chosen.
const chosenMode = useCallback(
(current: unknown) => {
const chosen = chosenModes.get(modeKey);
return chosen && isEqual(chosen.value, current) ? chosen.mode : undefined;
if (!chosen) return undefined;
const emptyManual = chosen.mode === "manual" && chosen.value === "";
return isEqual(chosen.value, current) ||
(emptyManual && isEqual(current, savedValue))
? chosen.mode
: undefined;
},
[modeKey],
[modeKey, savedValue],
);
// A remount mounts the replacement before the timer fires, so only leaving
@@ -337,14 +344,34 @@ export function FfmpegArgsWidget(props: WidgetProps) {
return;
}
if (mode === "preset" || mode === "auto") {
choose(nextMode, "");
// Start from the saved manual args, if any, so a switch back to Manual
// shows them instead of an empty box.
if (mode === "preset" || mode === "auto" || mode === "disabled") {
const savedIsManual =
resolveMode(
savedValue,
presetOptions,
defaultMode,
allowInherit,
hwaccelModes,
) === "manual";
choose(nextMode, savedIsManual ? normalizeManualText(savedValue) : "");
return;
}
choose(nextMode, normalizeManualText(value));
},
[choose, isInherited, mode, presetOptions, savedValue, value],
[
allowInherit,
choose,
defaultMode,
hwaccelModes,
isInherited,
mode,
presetOptions,
savedValue,
value,
],
);
const handlePresetChange = useCallback(
@@ -358,7 +385,10 @@ export function FfmpegArgsWidget(props: WidgetProps) {
[choose],
);
const manualValue = normalizeManualText(value);
const manualValue =
mode === "manual" && chosenModes.get(modeKey)?.value === ""
? ""
: normalizeManualText(value);
const presetValue =
typeof value === "string" && presetOptions.includes(value) ? value : "";
const fallbackDescriptionKey = useMemo(() => {