diff --git a/apps/web/src/components/settings/SettingsPanels.tsx b/apps/web/src/components/settings/SettingsPanels.tsx index 3d400da824..a9ecf2e382 100644 --- a/apps/web/src/components/settings/SettingsPanels.tsx +++ b/apps/web/src/components/settings/SettingsPanels.tsx @@ -1,7 +1,6 @@ import { ArchiveIcon, ArchiveX, - InfoIcon, LoaderIcon, PlusIcon, RefreshCwIcon, @@ -106,6 +105,12 @@ import { SettingsSection, useRelativeTimeTick, } from "./settingsLayout"; +import { + BackgroundPolicyTooltip as PolicyTooltip, + backgroundActivityOverrideSettings, + durationToSeconds, + normalizeIntervalSeconds, +} from "./backgroundActivityUtils"; import { ProjectFavicon } from "../ProjectFavicon"; import { useServerObservability, useServerProviders } from "../../rpc/serverState"; @@ -137,11 +142,6 @@ const BACKGROUND_ACTIVITY_PROFILE_LABELS: Record; const BACKGROUND_ACTIVITY_PROFILE_OPTION_LABELS: Record = { ...BACKGROUND_ACTIVITY_PROFILE_LABELS, @@ -174,17 +174,6 @@ const BACKGROUND_ACTIVITY_BOOLEAN_OVERRIDES: ReadonlyArray<{ { key: "pauseWhenOnBattery", label: "Pause on battery" }, ]; -function durationToSeconds(duration: Duration.Duration): number { - return Math.round(Duration.toMillis(duration) / 1_000); -} - -function normalizeIntervalSeconds(value: number | null): number { - if (value === null || !Number.isFinite(value)) { - return 0; - } - return Math.max(0, Math.round(value)); -} - function resolveBackgroundActivityProfileOption(settings: { readonly backgroundActivity: BackgroundActivitySettings; }): BackgroundActivityProfileOption { @@ -209,50 +198,6 @@ function backgroundActivityProfileSettings(profile: BackgroundActivityProfile) { }; } -function backgroundActivityOverrideSettings( - current: BackgroundActivitySettings, - overrides: BackgroundActivityOverridePatch, -) { - const nextOverrides: BackgroundActivityOverridePatch = { - ...current.overrides, - ...overrides, - }; - for (const [key, value] of Object.entries(nextOverrides)) { - if (value === undefined) { - delete nextOverrides[key as keyof typeof nextOverrides]; - } - } - return { - backgroundActivity: { - schemaVersion: 1 as const, - profile: "custom" as const, - baseProfile: getBackgroundActivityBaseProfile(current), - overrides: nextOverrides as BackgroundActivitySettings["overrides"], - }, - }; -} - -function PolicyTooltip({ children }: { readonly children: string }) { - return ( - - - - - } - /> - - {children} - - - ); -} - function withoutProviderInstanceKey( record: Readonly> | undefined, key: ProviderInstanceId, diff --git a/apps/web/src/components/settings/SourceControlSettings.tsx b/apps/web/src/components/settings/SourceControlSettings.tsx index 3ea7ea2a20..90485ea589 100644 --- a/apps/web/src/components/settings/SourceControlSettings.tsx +++ b/apps/web/src/components/settings/SourceControlSettings.tsx @@ -1,9 +1,8 @@ -import { ChevronDownIcon, GitPullRequestIcon, InfoIcon, RefreshCwIcon } from "lucide-react"; +import { ChevronDownIcon, GitPullRequestIcon, RefreshCwIcon } from "lucide-react"; import * as Duration from "effect/Duration"; import * as Option from "effect/Option"; import { useState, type ReactNode } from "react"; import type { - BackgroundActivitySettings, SourceControlProviderKind, SourceControlDiscoveryResult, SourceControlProviderAuth, @@ -55,6 +54,12 @@ import { } from "../Icons"; import { RedactedSensitiveText } from "./RedactedSensitiveText"; import { SettingResetButton, SettingsPageContainer, SettingsSection } from "./settingsLayout"; +import { + BackgroundPolicyTooltip, + backgroundActivityOverrideSettings, + durationToSeconds, + normalizeIntervalSeconds as normalizeFetchIntervalSeconds, +} from "./backgroundActivityUtils"; const EMPTY_DISCOVERY_RESULT: SourceControlDiscoveryResult = { versionControlSystems: [], @@ -75,43 +80,6 @@ const VCS_ICONS: Partial> = { const SOURCE_CONTROL_SKELETON_ROWS = ["primary", "secondary"] as const; const GIT_FETCH_INTERVAL_STEP_SECONDS = 5; -type BackgroundActivityOverridePatch = Partial<{ - [K in keyof BackgroundActivitySettings["overrides"]]: - | BackgroundActivitySettings["overrides"][K] - | undefined; -}>; - -function durationToSeconds(duration: Duration.Duration): number { - return Math.round(Duration.toMillis(duration) / 1_000); -} - -function normalizeFetchIntervalSeconds(value: number | null): number { - if (value === null || !Number.isFinite(value)) { - return 0; - } - return Math.max(0, Math.round(value)); -} - -function BackgroundPolicyTooltip({ children }: { readonly children: string }) { - return ( - - - - - } - /> - - {children} - - - ); -} function optionLabel(value: Option.Option): string | null { return Option.getOrNull(value); @@ -335,28 +303,6 @@ function GitFetchIntervalSettings() { ); const canResetFetchInterval = automaticGitFetchIntervalSeconds !== defaultAutomaticGitFetchIntervalSeconds; - const backgroundActivityOverrideSettings = ( - current: BackgroundActivitySettings, - overrides: BackgroundActivityOverridePatch, - ) => { - const nextOverrides: BackgroundActivityOverridePatch = { - ...current.overrides, - ...overrides, - }; - for (const [key, value] of Object.entries(nextOverrides)) { - if (value === undefined) { - delete nextOverrides[key as keyof typeof nextOverrides]; - } - } - return { - backgroundActivity: { - schemaVersion: 1 as const, - profile: "custom" as const, - baseProfile: getBackgroundActivityBaseProfile(current), - overrides: nextOverrides as BackgroundActivitySettings["overrides"], - }, - }; - }; return (
diff --git a/apps/web/src/components/settings/backgroundActivityUtils.tsx b/apps/web/src/components/settings/backgroundActivityUtils.tsx new file mode 100644 index 0000000000..b93507e835 --- /dev/null +++ b/apps/web/src/components/settings/backgroundActivityUtils.tsx @@ -0,0 +1,67 @@ +import { InfoIcon } from "lucide-react"; +import * as Duration from "effect/Duration"; +import type { BackgroundActivitySettings } from "@t3tools/contracts"; +import { getBackgroundActivityBaseProfile } from "@t3tools/shared/backgroundActivitySettings"; + +import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; + +export type BackgroundActivityOverridePatch = Partial<{ + [K in keyof BackgroundActivitySettings["overrides"]]: + | BackgroundActivitySettings["overrides"][K] + | undefined; +}>; + +export function durationToSeconds(duration: Duration.Duration): number { + return Math.round(Duration.toMillis(duration) / 1_000); +} + +export function normalizeIntervalSeconds(value: number | null): number { + if (value === null || !Number.isFinite(value)) { + return 0; + } + return Math.max(0, Math.round(value)); +} + +export function backgroundActivityOverrideSettings( + current: BackgroundActivitySettings, + overrides: BackgroundActivityOverridePatch, +) { + const nextOverrides: BackgroundActivityOverridePatch = { + ...current.overrides, + ...overrides, + }; + for (const [key, value] of Object.entries(nextOverrides)) { + if (value === undefined) { + delete nextOverrides[key as keyof typeof nextOverrides]; + } + } + return { + backgroundActivity: { + schemaVersion: 1 as const, + profile: "custom" as const, + baseProfile: getBackgroundActivityBaseProfile(current), + overrides: nextOverrides as BackgroundActivitySettings["overrides"], + }, + }; +} + +export function BackgroundPolicyTooltip({ children }: { readonly children: string }) { + return ( + + + + + } + /> + + {children} + + + ); +} diff --git a/packages/shared/src/serverSettings.ts b/packages/shared/src/serverSettings.ts index c8cee52a68..60fde1daf7 100644 --- a/packages/shared/src/serverSettings.ts +++ b/packages/shared/src/serverSettings.ts @@ -89,26 +89,28 @@ export function applyServerSettingsPatch( ...patchForMerge } = patch; const backgroundActivityPatch = - backgroundActivityProfile !== undefined - ? { - schemaVersion: 1 as const, - profile: backgroundActivityProfile, - overrides: {}, - } - : automaticGitFetchInterval !== undefined || providerHealthRefreshInterval !== undefined + backgroundActivity !== undefined + ? undefined + : backgroundActivityProfile !== undefined ? { schemaVersion: 1 as const, - profile: "custom" as const, - baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity), - overrides: { - ...current.backgroundActivity.overrides, - ...(automaticGitFetchInterval !== undefined ? { automaticGitFetchInterval } : {}), - ...(providerHealthRefreshInterval !== undefined - ? { providerHealthRefreshInterval } - : {}), - }, + profile: backgroundActivityProfile, + overrides: {}, } - : undefined; + : automaticGitFetchInterval !== undefined || providerHealthRefreshInterval !== undefined + ? { + schemaVersion: 1 as const, + profile: "custom" as const, + baseProfile: getBackgroundActivityBaseProfile(current.backgroundActivity), + overrides: { + ...current.backgroundActivity.overrides, + ...(automaticGitFetchInterval !== undefined ? { automaticGitFetchInterval } : {}), + ...(providerHealthRefreshInterval !== undefined + ? { providerHealthRefreshInterval } + : {}), + }, + } + : undefined; const next = deepMerge(current, patchForMerge); const nextWithReplacementsBase = { ...next,