diff --git a/web/src/components/settings/SecretField.tsx b/web/src/components/settings/SecretField.tsx index 8b79a4539e..ba8448b00a 100644 --- a/web/src/components/settings/SecretField.tsx +++ b/web/src/components/settings/SecretField.tsx @@ -39,6 +39,8 @@ export interface SecretFieldProps { hint?: string; /** Extra line under the description, e.g. a save error for this field. */ status?: ReactNode; + /** Marks the row as holding an unsaved change, as `SettingField` does. */ + dirty?: boolean; disabled?: boolean; restartRequired?: boolean; /** The environment variable that sets this secret; disables the control. */ @@ -67,6 +69,7 @@ export function SecretField({ cleared = false, hint, status, + dirty, disabled: disabledProp = false, restartRequired = false, managedByEnv, @@ -104,6 +107,7 @@ export function SecretField({ ({ + sensitiveStatus: { + current: { configured: [], managed_by_env: [] } as { + configured: string[]; + managed_by_env: string[]; + managed_by_env_vars?: Record; + }, + }, +})); + +vi.mock("@/hooks/queries/admin/settings", () => ({ + useAdminServerSettings: () => ({ data: SETTINGS, isLoading: false }), + useAdminSensitiveStatus: () => ({ data: sensitiveStatus.current, isError: false }), + useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), + useJellyfinCompatStatus: () => ({ + data: { enabled: true, web_enabled: true, api_state: "running", web_state: "missing" }, + isLoading: false, + }), + useInstallJellyfinCompatWeb: () => ({ mutate: vi.fn(), isPending: false }), + useRemoveJellyfinCompatWeb: () => ({ mutate: vi.fn(), isPending: false }), + useUpdateJellyfinCompatSettings: () => ({ mutate: vi.fn(), isPending: false }), +})); + +vi.mock("@/hooks/useRestartKeys", () => ({ useRestartKeys: () => ({ has: () => false }) })); + +beforeEach(() => { + sensitiveStatus.current = { configured: [], managed_by_env: [] }; +}); + +it("stages nothing when the Jellyfin API is switched off and back on", async () => { + render(); + const api = screen.getByRole("switch", { name: "Allow Jellyfin apps to connect" }); + await userEvent.click(api); + await userEvent.click(api); + + expect(screen.queryByText(/unsaved change/)).not.toBeInTheDocument(); +}); + +it("takes back the Jellyfin Web switch-off once the environment sets the API switch", async () => { + const { rerender } = render(); + await userEvent.click(screen.getByRole("switch", { name: "Allow Jellyfin apps to connect" })); + expect(screen.getByText("2 unsaved changes")).toBeInTheDocument(); + + // A restart with SILO_JELLYFIN_ENABLED set: the form drops the API draft. + sensitiveStatus.current = { + configured: [], + managed_by_env: ["jellyfin_compat.enabled"], + managed_by_env_vars: { "jellyfin_compat.enabled": "SILO_JELLYFIN_ENABLED" }, + }; + rerender(); + + expect(screen.queryByText(/unsaved change/)).not.toBeInTheDocument(); +}); diff --git a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx index 7ef22409cf..9be90f1cde 100644 --- a/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx +++ b/web/src/pages/admin-settings/CompatibilityProxiesSettings.tsx @@ -1,4 +1,4 @@ -import { useMemo } from "react"; +import { useLayoutEffect, useMemo } from "react"; import { AlertCircle, CheckCircle2, @@ -179,6 +179,22 @@ export default function CompatibilityProxiesSettings() { const removeWeb = useRemoveJellyfinCompatWeb(); const updateCompatSettings = useUpdateJellyfinCompatSettings(); const status = statusQuery.data; + // Switching the API off also turns Jellyfin Web off (setJellyfinAPIEnabled), + // as the server's own Jellyfin settings endpoint does. That edit has no field + // here, so it stays only while an API switch-off is staged: flipping the + // switch back, switching off an API that is already off, or the environment + // taking the switch over (the form then drops its draft) takes it back. + // A layout effect, so the save bar never paints the extra count. + const webOffAlone = + form.isDirty("jellyfin_compat.web_enabled") && + !( + form.isDirty("jellyfin_compat.enabled") && + form.getValue("jellyfin_compat.enabled") === "false" + ); + const { resetValue } = form; + useLayoutEffect(() => { + if (webOffAlone) resetValue("jellyfin_compat.web_enabled"); + }, [webOffAlone, resetValue]); if (form.isLoading || statusQuery.isLoading) return ( diff --git a/web/src/pages/admin-settings/PlaybackSettings.test.tsx b/web/src/pages/admin-settings/PlaybackSettings.test.tsx new file mode 100644 index 0000000000..bcb7a35b5a --- /dev/null +++ b/web/src/pages/admin-settings/PlaybackSettings.test.tsx @@ -0,0 +1,107 @@ +import { render, screen, within } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { MemoryRouter } from "react-router"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +import PlaybackSettings from "./PlaybackSettings"; + +window.HTMLElement.prototype.hasPointerCapture ??= () => false; +window.HTMLElement.prototype.setPointerCapture ??= () => {}; +window.HTMLElement.prototype.releasePointerCapture ??= () => {}; +window.HTMLElement.prototype.scrollIntoView ??= () => {}; + +const A = "/dev/dri/renderD128"; +const B = "/dev/dri/renderD129"; +const C = "/dev/dri/renderD130"; + +const { settings } = vi.hoisted(() => ({ + settings: { current: {} as Record }, +})); + +vi.mock("@/hooks/queries/admin/settings", () => ({ + useAdminServerSettings: () => ({ data: settings.current, isLoading: false }), + useAdminSensitiveStatus: () => ({ data: { configured: [], managed_by_env: [] }, isError: false }), + useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), +})); +vi.mock("@/hooks/queries/admin/system", () => ({ + useHWAccelDetection: () => ({ + data: { + resolved: "vaapi", + render_device_details: [ + { path: A, description: "GPU A" }, + { path: B, description: "GPU B" }, + { path: C, description: "GPU C" }, + ], + }, + isLoading: false, + }), +})); +vi.mock("@/hooks/queries/admin/nodes", () => ({ + useAdminNodes: () => ({ data: [], isSuccess: true }), +})); +vi.mock("@/hooks/queries/admin/libraries", () => ({ + useLibraryCapabilities: () => ({ data: { trickplay: false } }), +})); +vi.mock("@/hooks/queries/admin/markers", () => ({ + useAdminMarkerCapabilities: () => ({ data: undefined }), +})); +vi.mock("@/hooks/queries/admin/trickplay", () => ({ + useAdminTrickplayLibraries: () => ({ data: [], isSuccess: true }), +})); +vi.mock("@/hooks/useRestartKeys", () => ({ useRestartKeys: () => ({ has: () => false }) })); +vi.mock("./MarkerTasksCard", () => ({ MarkerTasksCard: () => null })); + +const page = ( + + + +); + +async function openDevices() { + const transcoding = within(screen.getByRole("group", { name: "Transcoding" })); + await userEvent.click(transcoding.getByRole("button", { name: /Advanced/ })); +} + +async function switchToNvenc() { + await userEvent.click(screen.getByRole("combobox", { name: "Hardware acceleration" })); + await userEvent.click(screen.getByRole("option", { name: "NVIDIA NVENC" })); +} + +describe("hardware device picker kept for an unsaved change", () => { + beforeEach(() => { + // Disclosures remember being opened; start every case collapsed. + localStorage.clear(); + settings.current = { "playback.hw_accel": "vaapi", "playback.hw_device": A }; + }); + + it("under NVENC only takes the staged device back off", async () => { + render(page); + await openDevices(); + await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); + await switchToNvenc(); + + // A render path NVENC can't use can't be added, and the staged one can + // go back off. + expect(screen.getByRole("switch", { name: "GPU C" })).toBeDisabled(); + await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); + + expect(screen.queryByRole("switch", { name: "GPU B" })).not.toBeInTheDocument(); + expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); + }); + + it("can restore a saved list that differs from the staged one only in order", async () => { + const { rerender } = render(page); + await openDevices(); + await userEvent.click(screen.getByRole("switch", { name: "GPU B" })); + // Someone else saves the same devices in the other order. + settings.current = { "playback.hw_accel": "vaapi", "playback.hw_device": `${B},${A}` }; + rerender(page); + await switchToNvenc(); + + await userEvent.click(screen.getByRole("switch", { name: "GPU A" })); + await userEvent.click(screen.getByRole("switch", { name: "GPU A" })); + + expect(screen.queryByRole("switch", { name: "GPU A" })).not.toBeInTheDocument(); + expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); + }); +}); diff --git a/web/src/pages/admin-settings/PlaybackSettings.tsx b/web/src/pages/admin-settings/PlaybackSettings.tsx index dc90c256f7..5701f803b6 100644 --- a/web/src/pages/admin-settings/PlaybackSettings.tsx +++ b/web/src/pages/admin-settings/PlaybackSettings.tsx @@ -78,15 +78,41 @@ export default function PlaybackSettings() { const hwDevice = form.getValue("playback.hw_device"); const hwDeviceEnv = form.envVar("playback.hw_device"); const selectedDevices = parseHWDeviceList(hwDevice); - const deviceRows = buildHWDeviceRows(hwDetection.data, hwDevice); - const detectedPaths = deviceRows.filter((row) => row.detected).map((row) => row.path); + // Saved paths keep their rows when the draft drops them, so switching off a + // device that detection doesn't list leaves its row in place. A toggle orders + // the list saved paths first, in their saved order, so switching a device + // back on restores the saved list. + const savedDevices = parseHWDeviceList(form.getPersistedValue("playback.hw_device")); + const deviceRows = buildHWDeviceRows(hwDetection.data, [...savedDevices, hwDevice].join(",")); + const deviceOrder = [ + ...savedDevices, + ...deviceRows.map((row) => row.path).filter((path) => !savedDevices.includes(path)), + ]; // Balancing is QSV/VAAPI-only: NVENC addresses GPUs by CUDA index/UUID, so // the multi-select picker is hidden for it (the server uses the first // configured entry). const isNvenc = hwAccel === "nvenc" || (hwAccel === "auto" && hwDetection.data?.resolved === "nvenc"); const inventoriesDiverge = nodeInventoriesDiverge(hwDetection.data); - const showDevicePicker = hwAccel !== "none" && !isNvenc && deviceRows.length > 0; + // A device choice staged before switching acceleration keeps the picker in + // view, so Save never writes a value the admin can't see. Under a mode the + // picker doesn't apply to, it only takes the list back toward the saved one: + // any device can be switched off, and only saved devices on. NVENC reads the + // setting as a CUDA device, so render paths can't be added there. + const devicePickerApplies = hwAccel !== "none" && !isNvenc; + const hwDeviceDirty = form.isDirty("playback.hw_device"); + const showDevicePicker = deviceRows.length > 0 && (devicePickerApplies || hwDeviceDirty); + const deviceChanged = (path: string) => + selectedDevices.includes(path) !== savedDevices.includes(path); + // A staged list can match the saved devices and differ only in order, as + // after a refresh; its selected rows then carry the change. + const orderOnlyDraft = hwDeviceDirty && !deviceRows.some((row) => deviceChanged(row.path)); + const deviceKeptForEdit = (path: string) => + !devicePickerApplies && + (deviceChanged(path) || (orderOnlyDraft && selectedDevices.includes(path))); + const deviceSwitchLocked = (path: string) => + hwDeviceEnv != null || + (!devicePickerApplies && !selectedDevices.includes(path) && !savedDevices.includes(path)); const nodes = useAdminNodes(); const trickplayExecution = @@ -133,8 +159,12 @@ export default function PlaybackSettings() { const anyDirty = (keys: readonly string[]) => keys.some((key) => isDirty(key)); const allRestart = (keys: readonly string[]) => keys.every((key) => restartKeys.has(key)); + // Each of these rows also stays in view, marked as changed, while it holds + // an unsaved edit after its switch is turned off. const throttleOn = form.getValue("enable_transcode_throttle") === "true"; + const throttleSecondsKept = !throttleOn && isDirty("transcode_throttle_seconds"); const allow4KTranscode = form.getValue("allow_4k_transcode") === "true"; + const preferLowerKept = !allow4KTranscode && isDirty("playback.prefer_lower_version_transcode"); // Every advanced transcoding key has one row, except the device picker, // which renders only when it applies. const transcodingAdvancedCount = TRANSCODING_ADVANCED_KEYS.length - (showDevicePicker ? 0 : 1); @@ -279,9 +309,10 @@ export default function PlaybackSettings() { onChange={(v) => form.setValue("allow_4k_transcode", v)} restartRequired={restartKeys.has("allow_4k_transcode")} /> - {allow4KTranscode && ( + {(allow4KTranscode || preferLowerKept) && ( form.setValue("enable_transcode_throttle", v)} restartRequired={restartKeys.has("enable_transcode_throttle")} /> - {throttleOn && ( + {(throttleOn || throttleSecondsKept) && ( ( - form.setValue( - "playback.hw_device", - toggleHWDevice( - form.getValue("playback.hw_device"), - row.path, - detectedPaths, - ), - ) - } + disabled={deviceSwitchLocked(row.path)} + onCheckedChange={() => { + const next = toggleHWDevice( + form.getValue("playback.hw_device"), + row.path, + deviceOrder, + ); + // Back to the saved devices stages the saved string + // itself, so the form can tell it undoes the edit + // however that string is spaced, and keeps it staged + // while a save settles. An unset value is never in + // the snapshot, so outside a save that draft is + // dropped directly. + const saved = form.getPersistedValue("playback.hw_device"); + if (next !== savedDevices.join(",")) { + form.setValue("playback.hw_device", next); + } else if (saved === "" && !form.isSaving) { + form.resetValue("playback.hw_device"); + } else { + form.setValue("playback.hw_device", saved); + } + }} /> ))} diff --git a/web/src/pages/admin-settings/RedisGroup.test.tsx b/web/src/pages/admin-settings/RedisGroup.test.tsx new file mode 100644 index 0000000000..6795d4f6e6 --- /dev/null +++ b/web/src/pages/admin-settings/RedisGroup.test.tsx @@ -0,0 +1,92 @@ +import { render, screen } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { beforeEach, describe, expect, it, vi } from "vitest"; + +import { useSettingsForm } from "@/hooks/useSettingsForm"; + +import { RedisGroup } from "./RedisGroup"; +import { REDIS_KEYS } from "./redisDraft"; + +const { sensitiveStatus } = vi.hoisted(() => ({ + sensitiveStatus: { + current: {} as { + configured: string[]; + managed_by_env: string[]; + managed_by_env_vars?: Record; + }, + }, +})); + +vi.mock("@/hooks/queries/admin/settings", () => ({ + // The snapshot never carries the URL; whether one is saved comes from the + // protected-credential status. + // The server reports the number in use: 0 when the URL names none. + useAdminServerSettings: () => ({ data: { "redis.db": "0" }, isLoading: false }), + useAdminSensitiveStatus: () => ({ data: sensitiveStatus.current, isError: false }), + useUpdateServerSettings: () => ({ mutateAsync: vi.fn(), isPending: false }), + useCheckAdminSettingsConnection: () => ({ mutateAsync: vi.fn(), isPending: false }), +})); + +const OTHER_KEY = "server.public_url"; + +function Harness() { + const form = useSettingsForm({ keys: [...REDIS_KEYS, OTHER_KEY] }); + return ( + <> + false }} + secrets={{ keepSaved: form.resetValue, setSecret: form.setValue, disabled: false }} + /> + {/* Another setting on the same page, so an edit can stay staged. */} + form.setValue(OTHER_KEY, e.target.value)} + /> +

{`${form.dirtyCount} staged`}

+ + ); +} + +describe("RedisGroup", () => { + beforeEach(() => { + sensitiveStatus.current = { configured: [], managed_by_env: [] }; + }); + + it("stages nothing when Use Redis goes on and back off with no saved URL", async () => { + render(); + const useRedis = screen.getByRole("switch", { name: "Use Redis" }); + + await userEvent.click(useRedis); + await userEvent.type(screen.getByLabelText("Connection URL"), "redis://cache:6379"); + await userEvent.click(useRedis); + + expect(useRedis).not.toBeChecked(); + expect(screen.getByText("0 staged")).toBeInTheDocument(); + }); + + it("shows the connection REDIS_URL sets once it takes over a staged switch-off", async () => { + sensitiveStatus.current = { configured: ["redis.url"], managed_by_env: [] }; + const { rerender } = render(); + // An edit elsewhere on the page stays staged after the environment takes + // the Redis keys over. + await userEvent.type(screen.getByLabelText("Other setting"), "https://media.example.com"); + await userEvent.click(screen.getByRole("switch", { name: "Use Redis" })); + expect(screen.queryByLabelText("Connection URL")).not.toBeInTheDocument(); + // The switch-off stages the URL and the number with it. + expect(screen.getByText("3 staged")).toBeInTheDocument(); + + // REDIS_URL sets both keys, as the server reports it. + sensitiveStatus.current = { + configured: ["redis.url"], + managed_by_env: ["redis.url", "redis.db"], + managed_by_env_vars: { "redis.url": "REDIS_URL", "redis.db": "REDIS_URL" }, + }; + rerender(); + + expect(screen.getByRole("switch", { name: "Use Redis" })).toBeChecked(); + expect(screen.getByLabelText("Connection URL")).toBeInTheDocument(); + // The Redis drafts went with the takeover; the other edit stays. + expect(screen.getByText("1 staged")).toBeInTheDocument(); + }); +}); diff --git a/web/src/pages/admin-settings/RedisGroup.tsx b/web/src/pages/admin-settings/RedisGroup.tsx index a1b9086903..8ae86067f5 100644 --- a/web/src/pages/admin-settings/RedisGroup.tsx +++ b/web/src/pages/admin-settings/RedisGroup.tsx @@ -50,6 +50,9 @@ export function RedisGroup({ setLastDirtyCount(form.dirtyCount); if (form.dirtyCount === 0) setEnabledOverride(null); } + // Once REDIS_URL sets the connection the switch is locked, so a choice + // made before it took over no longer applies. + if (urlEnv && enabledOverride !== null) setEnabledOverride(null); const enabled = enabledOverride ?? (redisUrl.trim() !== "" || configured); // URL edits go through the page's editors, which drop a keystroke that // arrives while a save is in flight. @@ -97,6 +100,13 @@ export function RedisGroup({ return; } setEnabledOverride(false); + // With no saved URL there is nothing to switch off: drop what was + // typed, since the fields that showed it are about to hide. + if (!configured) { + form.resetValue("redis.url"); + form.resetValue("redis.db"); + return; + } stageRedisUrl(form, ""); }} disabled={secrets.disabled} diff --git a/web/src/pages/admin-settings/StorageSettings.test.tsx b/web/src/pages/admin-settings/StorageSettings.test.tsx index 4da84af5a0..8f7cd93ac0 100644 --- a/web/src/pages/admin-settings/StorageSettings.test.tsx +++ b/web/src/pages/admin-settings/StorageSettings.test.tsx @@ -1348,4 +1348,37 @@ describe("StorageSettings", () => { ); }); }); + + describe("leaving Cloudflare token links", () => { + beforeEach(() => { + realForm.enabled = true; + serverSettings.current = { + "artwork.storage_backend": "s3", + "s3.public_url_auth": "presigned", + }; + sensitiveStatus.current = { configured: [], managed_by_env: [] }; + }); + + afterEach(() => { + realForm.enabled = false; + }); + + it("keeps a typed token secret in view after switching back to signed links", async () => { + render(); + + const publicGroup = within(screen.getByRole("group", { name: "Public storage" })); + const linkMode = publicGroup.getByRole("combobox", { + name: "How asset links are authorized", + }); + await userEvent.click(linkMode); + await userEvent.click(screen.getByRole("option", { name: "Cloudflare signed token" })); + await userEvent.click(publicGroup.getByRole("button", { name: /Advanced/ })); + await userEvent.type(publicGroup.getByLabelText("Token Secret"), "secret"); + await userEvent.click(linkMode); + await userEvent.click(screen.getByRole("option", { name: "Signed links (recommended)" })); + + expect(screen.getByText("1 unsaved change")).toBeInTheDocument(); + expect(publicGroup.getByLabelText("Token Secret")).toHaveValue("secret"); + }); + }); }); diff --git a/web/src/pages/admin-settings/StorageSettings.tsx b/web/src/pages/admin-settings/StorageSettings.tsx index e29ab4cef0..390131de30 100644 --- a/web/src/pages/admin-settings/StorageSettings.tsx +++ b/web/src/pages/admin-settings/StorageSettings.tsx @@ -271,11 +271,18 @@ function S3Group({ // Everything that reaches the bucket is shown. Only public storage has an // Advanced tier: the CDN address and the Cloudflare token settings, which - // exist only for the link modes that use them. - const advancedCount = - scope === "public" - ? (urlAuth !== "presigned" ? 1 : 0) + (urlAuth === "cloudflare_token" ? 3 : 0) - : 0; + // exist only for the link modes that use them. A row the selected mode + // doesn't use stays, marked as changed, while it holds an unsaved edit, so + // Save never writes a value the admin can't see. + const linkModeUses = (advancedKey: string) => + advancedKey === "s3.public_read_endpoint" + ? urlAuth !== "presigned" + : urlAuth === "cloudflare_token"; + const keptForEdit = (advancedKey: string) => + !linkModeUses(advancedKey) && form.isDirty(advancedKey); + const showsAdvanced = (advancedKey: string) => + scope === "public" && (linkModeUses(advancedKey) || form.isDirty(advancedKey)); + const advancedCount = PUBLIC_S3_ADVANCED_KEYS.filter(showsAdvanced).length; const advancedChanged = countDirty(form, PUBLIC_S3_ADVANCED_KEYS); async function handleCheckConnection() { @@ -431,53 +438,61 @@ function S3Group({ count={advancedCount} forceOpen={advancedChanged > 0} > - form.setValue("s3.public_read_endpoint", v)} - restartRequired={restartKeys.has("s3.public_read_endpoint")} - managedByEnv={form.envVar("s3.public_read_endpoint")} - /> - {urlAuth === "cloudflare_token" && ( - <> - {/* - Cloudflare token auth requires this secret, so a clear only - saves alongside a switch back to another mode — the one - order that works, since the field is hidden in those modes. - */} - secrets.keepSaved("s3.public_token_secret")} - onClear={() => secrets.clearSaved("s3.public_token_secret")} - cleared={form.isClearStaged("s3.public_token_secret")} - onChange={(v) => secrets.setSecret("s3.public_token_secret", v)} - hint={t("web.admin.settings.storage.s3.tokenSecretHint")} - disabled={secrets.disabled} - restartRequired={restartKeys.has("s3.public_token_secret")} - managedByEnv={form.envVar("s3.public_token_secret")} - /> - form.setValue("s3.public_token_param", v)} - restartRequired={restartKeys.has("s3.public_token_param")} - managedByEnv={form.envVar("s3.public_token_param")} - /> - form.setValue("s3.public_token_ttl", v)} - restartRequired={restartKeys.has("s3.public_token_ttl")} - managedByEnv={form.envVar("s3.public_token_ttl")} - /> - + {showsAdvanced("s3.public_read_endpoint") && ( + form.setValue("s3.public_read_endpoint", v)} + restartRequired={restartKeys.has("s3.public_read_endpoint")} + managedByEnv={form.envVar("s3.public_read_endpoint")} + /> + )} + {/* + Cloudflare token auth requires this secret, so a clear only + saves alongside a switch back to another mode. The staged clear + keeps the row in view after that switch. + */} + {showsAdvanced("s3.public_token_secret") && ( + secrets.keepSaved("s3.public_token_secret")} + onClear={() => secrets.clearSaved("s3.public_token_secret")} + cleared={form.isClearStaged("s3.public_token_secret")} + onChange={(v) => secrets.setSecret("s3.public_token_secret", v)} + hint={t("web.admin.settings.storage.s3.tokenSecretHint")} + disabled={secrets.disabled} + restartRequired={restartKeys.has("s3.public_token_secret")} + managedByEnv={form.envVar("s3.public_token_secret")} + /> + )} + {showsAdvanced("s3.public_token_param") && ( + form.setValue("s3.public_token_param", v)} + restartRequired={restartKeys.has("s3.public_token_param")} + managedByEnv={form.envVar("s3.public_token_param")} + /> + )} + {showsAdvanced("s3.public_token_ttl") && ( + form.setValue("s3.public_token_ttl", v)} + restartRequired={restartKeys.has("s3.public_token_ttl")} + managedByEnv={form.envVar("s3.public_token_ttl")} + /> )} )} diff --git a/web/src/pages/setup-wizard/steps/ConnectStep.tsx b/web/src/pages/setup-wizard/steps/ConnectStep.tsx index d5d8cfa5d6..68c4d267cf 100644 --- a/web/src/pages/setup-wizard/steps/ConnectStep.tsx +++ b/web/src/pages/setup-wizard/steps/ConnectStep.tsx @@ -21,6 +21,9 @@ export function ConnectStep() { // The snapshot always carries the effective value, so the default (on) is // never read as blank. const jellyfinEnabled = form.getValue("jellyfin_compat.enabled") === "true"; + // An address typed before turning Jellyfin off stays in view, marked as + // changed, so Continue never saves a value the admin can't see. + const addressKept = !jellyfinEnabled && form.isDirty("jellyfin_compat.public_url"); useStepSummary( "connect", jellyfinEnabled @@ -51,9 +54,10 @@ export function ConnectStep() { onChange={(v) => form.setValue("jellyfin_compat.enabled", v)} managedByEnv={form.envVar("jellyfin_compat.enabled")} /> - {jellyfinEnabled ? ( + {jellyfinEnabled || addressKept ? ( `s3.${prefix}_${name}`; const urlAuth = form.getValue(key("url_auth")) || "presigned"; + // Link-mode settings show for the modes that use them. One the selected mode + // doesn't use stays, marked as changed, while it holds an unsaved edit, so + // Continue never saves a value the admin can't see. + const linkModeUses = (linkKey: string) => + linkKey === "s3.public_read_endpoint" + ? urlAuth !== "presigned" + : urlAuth === "cloudflare_token"; + const keptForEdit = (linkKey: string) => !linkModeUses(linkKey) && form.isDirty(linkKey); + const showsLinkSetting = (linkKey: string) => linkModeUses(linkKey) || form.isDirty(linkKey); return ( <> - {urlAuth !== "presigned" ? ( + {showsLinkSetting("s3.public_read_endpoint") ? ( ) : null} - {urlAuth === "cloudflare_token" ? ( - <> - form.setValue("s3.public_token_secret", v)} - sensitiveConfigured={form.sensitiveConfigured.includes("s3.public_token_secret")} - managedByEnv={form.envVar("s3.public_token_secret")} - /> - form.setValue("s3.public_token_param", v)} - managedByEnv={form.envVar("s3.public_token_param")} - /> - form.setValue("s3.public_token_ttl", v)} - managedByEnv={form.envVar("s3.public_token_ttl")} - /> - + {showsLinkSetting("s3.public_token_secret") ? ( + form.setValue("s3.public_token_secret", v)} + sensitiveConfigured={form.sensitiveConfigured.includes("s3.public_token_secret")} + managedByEnv={form.envVar("s3.public_token_secret")} + /> + ) : null} + {showsLinkSetting("s3.public_token_param") ? ( + form.setValue("s3.public_token_param", v)} + managedByEnv={form.envVar("s3.public_token_param")} + /> + ) : null} + {showsLinkSetting("s3.public_token_ttl") ? ( + form.setValue("s3.public_token_ttl", v)} + managedByEnv={form.envVar("s3.public_token_ttl")} + /> ) : null} ) : null}