Skip to content

Commit a9bcd94

Browse files
Yih-Chun HuYih-Chun Hu
authored andcommitted
fix(web): validate snooze hours and keep auto-settle settings unchanged
1 parent 13c1a93 commit a9bcd94

5 files changed

Lines changed: 410 additions & 333 deletions

File tree

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 153 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { SettingsGroup } from "./SettingsGroup";
2-
import { SnoozeAndAutoSettleSettings } from "./SnoozeAndAutoSettleSettings";
2+
import { SnoozeSettings } from "./SnoozeSettings";
33
import { NotificationSettings } from "./NotificationSettings";
44
import { PRIVACY_POLICY_URL } from "../../legalLinks";
55
import { CheckIcon, ChevronRightIcon } from "lucide-react";
@@ -16,6 +16,8 @@ import {
1616
import {
1717
DEFAULT_UNIFIED_SETTINGS,
1818
type DiffLayout,
19+
MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
20+
MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS,
1921
type ResponseStreamingMode,
2022
type QuitConfirmationMode,
2123
SidebarProjectSortOrder,
@@ -71,6 +73,7 @@ import { EMPTY_SERVER_PROVIDERS } from "../../state/server";
7173
import { Button } from "../ui/button";
7274
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
7375
import { DraftInput } from "../ui/draft-input";
76+
import { Input } from "../ui/input";
7477
import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
7578
import { Switch } from "../ui/switch";
7679
import { ScopedSwitch } from "./ScopedSwitch";
@@ -657,6 +660,47 @@ export function useSettingsRestore(onRestored?: () => void) {
657660
};
658661
}
659662

663+
const AUTO_SETTLE_DEFAULT_DAYS = DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays ?? 3;
664+
665+
function AutoSettleDaysInput({
666+
value,
667+
onCommit,
668+
}: {
669+
value: number;
670+
onCommit: (days: number) => void;
671+
}) {
672+
const [draft, setDraft] = useState(String(value));
673+
const [draftSource, setDraftSource] = useState(value);
674+
if (draftSource !== value) {
675+
setDraftSource(value);
676+
setDraft(String(value));
677+
}
678+
679+
return (
680+
<Input
681+
size="sm"
682+
type="number"
683+
min={MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS}
684+
max={MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS}
685+
className="w-full sm:w-24"
686+
value={draft}
687+
onChange={(event) => {
688+
setDraft(event.target.value);
689+
const parsed = Number(event.target.value);
690+
if (
691+
Number.isInteger(parsed) &&
692+
parsed >= MIN_SIDEBAR_AUTO_SETTLE_AFTER_DAYS &&
693+
parsed <= MAX_SIDEBAR_AUTO_SETTLE_AFTER_DAYS
694+
) {
695+
onCommit(parsed);
696+
}
697+
}}
698+
onBlur={() => setDraft(String(value))}
699+
aria-label="Days of inactivity before auto-settle"
700+
/>
701+
);
702+
}
703+
660704
const LEGACY_FEATURE_TARGET_IDS: ReadonlySet<string> = new Set([
661705
"legacy-plan-mode",
662706
"legacy-context-window-indicator",
@@ -762,6 +806,14 @@ export function GeneralSettingsPanel() {
762806
(environment?.serverConfig
763807
? providersByEnvironment.get(environment.environmentId)
764808
: undefined) ?? EMPTY_SERVER_PROVIDERS;
809+
const supportsAutoSettlement =
810+
connectedEnvironments.length > 0 &&
811+
connectedEnvironments.every(
812+
(target) => target.serverConfig?.environment.capabilities.threadAutoSettlement === true,
813+
);
814+
const supportsAutoSettlementScope = connectedEnvironments.every(
815+
(target) => target.serverConfig?.environment.capabilities.threadAutoSettlementScope === true,
816+
);
765817
const supportsRestartContinuation =
766818
connectedEnvironments.length > 0 &&
767819
connectedEnvironments.every(
@@ -999,9 +1051,108 @@ export function GeneralSettingsPanel() {
9991051
</Select>
10001052
}
10011053
/>
1054+
1055+
{supportsAutoSettlement ? (
1056+
<>
1057+
<SettingsRow
1058+
serverScoped
1059+
settingKeys={["sidebarAutoSettleOnMerge"]}
1060+
{...searchableSetting("auto-settle-merged-threads")}
1061+
description="Settle a thread when its pull request merges. Closed pull requests still settle automatically."
1062+
resetAction={
1063+
settings.sidebarAutoSettleOnMerge !==
1064+
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge ? (
1065+
<SettingResetButton
1066+
label="auto-settle on merge"
1067+
onClick={() =>
1068+
updateSettings({
1069+
sidebarAutoSettleOnMerge: DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleOnMerge,
1070+
})
1071+
}
1072+
/>
1073+
) : null
1074+
}
1075+
control={
1076+
<ScopedSwitch
1077+
settingKeys={["sidebarAutoSettleOnMerge"]}
1078+
checked={settings.sidebarAutoSettleOnMerge}
1079+
onCheckedChange={(checked) =>
1080+
updateSettings({ sidebarAutoSettleOnMerge: Boolean(checked) })
1081+
}
1082+
aria-label="Auto-settle merged threads"
1083+
/>
1084+
}
1085+
/>
1086+
1087+
<SettingsRow
1088+
serverScoped
1089+
settingKeys={["sidebarAutoSettleAfterDays"]}
1090+
{...searchableSetting("auto-settle-inactive-threads")}
1091+
description="Sidebar threads with no activity for this long settle automatically."
1092+
resetAction={
1093+
settings.sidebarAutoSettleAfterDays !==
1094+
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays ? (
1095+
<SettingResetButton
1096+
label="auto-settle"
1097+
onClick={() =>
1098+
updateSettings({
1099+
sidebarAutoSettleAfterDays:
1100+
DEFAULT_UNIFIED_SETTINGS.sidebarAutoSettleAfterDays,
1101+
})
1102+
}
1103+
/>
1104+
) : null
1105+
}
1106+
control={
1107+
<ScopedSwitch
1108+
settingKeys={["sidebarAutoSettleAfterDays"]}
1109+
checked={settings.sidebarAutoSettleAfterDays !== null}
1110+
onCheckedChange={(checked) =>
1111+
updateSettings({
1112+
sidebarAutoSettleAfterDays: checked ? AUTO_SETTLE_DEFAULT_DAYS : null,
1113+
})
1114+
}
1115+
aria-label="Auto-settle inactive threads"
1116+
/>
1117+
}
1118+
/>
1119+
{settings.sidebarAutoSettleAfterDays !== null ? (
1120+
<SettingsRow
1121+
serverScoped
1122+
settingKeys={["sidebarAutoSettleAfterDays"]}
1123+
title={searchableSetting("days-before-auto-settle").title}
1124+
description="Any new activity un-settles a thread automatically."
1125+
control={
1126+
<AutoSettleDaysInput
1127+
value={settings.sidebarAutoSettleAfterDays}
1128+
onCommit={(days) => updateSettings({ sidebarAutoSettleAfterDays: days })}
1129+
/>
1130+
}
1131+
/>
1132+
) : null}
1133+
{settings.sidebarAutoSettleAfterDays !== null && supportsAutoSettlementScope ? (
1134+
<SettingsRow
1135+
serverScoped
1136+
settingKeys={["sidebarAutoSettleKeepPullRequests"]}
1137+
title="Keep threads with a PR"
1138+
description="Inactivity does not settle threads with a pull request. Merge and close still do."
1139+
control={
1140+
<ScopedSwitch
1141+
settingKeys={["sidebarAutoSettleKeepPullRequests"]}
1142+
checked={settings.sidebarAutoSettleKeepPullRequests}
1143+
onCheckedChange={(checked) =>
1144+
updateSettings({ sidebarAutoSettleKeepPullRequests: checked })
1145+
}
1146+
aria-label="Keep threads with a PR"
1147+
/>
1148+
}
1149+
/>
1150+
) : null}
1151+
</>
1152+
) : null}
10021153
</SettingsSection>
10031154

1004-
<SnoozeAndAutoSettleSettings />
1155+
<SnoozeSettings />
10051156

10061157
<SettingsSection id="behavior" title="Behavior">
10071158
<NotificationSettings />

0 commit comments

Comments
 (0)