Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

WorktreesSettings.tsx

81 lines3.0 KB

1import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
2import { useGT } from "gt-react";
3​
4import { AdvancedSettings } from "./AdvancedSettings";
5import { BranchNamingSettings } from "./BranchNamingSettings";
6import { WorktreeSubmodulesRow } from "./ProjectDefaultsSettings";
7import { ScopedSwitch } from "./ScopedSwitch";
8import { useSettingsScope } from "./SettingsScopeContext";
9import {
10 SettingResetButton,
11 SettingsPageContainer,
12 SettingsRow,
13 SettingsSection,
14} from "./settingsLayout";
15import { useSearchableSetting } from "./settingsSearch";
16import { WorktreeCleanupSection, WorktreesDirectoryRow } from "./StorageSettings";
17import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
18​
19function StartFromRemoteRow() {
20 const gt = useGT();
21 const searchableSetting = useSearchableSetting();
22 const settings = useScopedSettings();
23 const updateSettings = useUpdateScopedSettings();
24 return (
25 <SettingsRow
26 serverScoped
27 settingKeys={["newWorktreesStartFromOrigin"]}
28 {...searchableSetting("start-from-origin")}
29 description={gt`Uses the latest commit of the base branch’s tracked remote branch, even if its name differs. Otherwise uses the same-named branch on origin. Uses your local branch if that remote branch is missing.`}
30 resetAction={
31 settings.newWorktreesStartFromOrigin !==
32 DEFAULT_UNIFIED_SETTINGS.newWorktreesStartFromOrigin ? (
33 <SettingResetButton
34 ariaLabel={gt`Reset new worktrees start from remote to default`}
35 onClick={() =>
36 updateSettings({
37 newWorktreesStartFromOrigin: DEFAULT_UNIFIED_SETTINGS.newWorktreesStartFromOrigin,
38 })
39 }
40 />
41 ) : null
42 }
43 control={
44 <ScopedSwitch
45 settingKeys={["newWorktreesStartFromOrigin"]}
46 checked={settings.newWorktreesStartFromOrigin}
47 onCheckedChange={(checked) =>
48 updateSettings({ newWorktreesStartFromOrigin: Boolean(checked) })
49 }
50 aria-label={gt`Start new worktrees from remote by default`}
51 />
52 }
53 />
54 );
56​
57export function WorktreesSettingsPanel() {
58 const gt = useGT();
59 const searchableSetting = useSearchableSetting();
60 const { scope } = useSettingsScope();
61 const isProjectScope = scope.kind === "project" || scope.kind === "checkout";
62​
63 return (
64 <SettingsPageContainer>
65 <SettingsSection
66 id="worktree-creation"
67 title={gt({ context: "settings section about creating worktrees" })`Creation`}
68 >
69 {!isProjectScope && <WorktreesDirectoryRow />}
70 <StartFromRemoteRow />
71 <AdvancedSettings targetIds={[searchableSetting("worktree-submodules").id]}>
72 <WorktreeSubmodulesRow />
73 </AdvancedSettings>
74 </SettingsSection>
75 <SettingsSection id="worktree-branches" title={gt`Branches`}>
76 <BranchNamingSettings />
77 </SettingsSection>
78 <WorktreeCleanupSection />
79 </SettingsPageContainer>
80 );