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

WorktreesSettings.tsx

73 lines2.7 KB

1import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
2​
3import { AdvancedSettings } from "./AdvancedSettings";
4import { BranchNamingSettings } from "./BranchNamingSettings";
5import { WorktreeSubmodulesRow } from "./ProjectDefaultsSettings";
6import { ScopedSwitch } from "./ScopedSwitch";
7import { useSettingsScope } from "./SettingsScopeContext";
8import {
9 SettingResetButton,
10 SettingsPageContainer,
11 SettingsRow,
12 SettingsSection,
13} from "./settingsLayout";
14import { searchableSetting } from "./settingsSearch";
15import { WorktreeCleanupSection, WorktreesDirectoryRow } from "./StorageSettings";
16import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
17​
18function StartFromRemoteRow() {
19 const settings = useScopedSettings();
20 const updateSettings = useUpdateScopedSettings();
21 return (
22 <SettingsRow
23 serverScoped
24 settingKeys={["newWorktreesStartFromOrigin"]}
25 {...searchableSetting("start-from-origin")}
26 description="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."
27 resetAction={
28 settings.newWorktreesStartFromOrigin !==
29 DEFAULT_UNIFIED_SETTINGS.newWorktreesStartFromOrigin ? (
30 <SettingResetButton
31 label="new worktrees start from remote"
32 onClick={() =>
33 updateSettings({
34 newWorktreesStartFromOrigin: DEFAULT_UNIFIED_SETTINGS.newWorktreesStartFromOrigin,
35 })
36 }
37 />
38 ) : null
39 }
40 control={
41 <ScopedSwitch
42 settingKeys={["newWorktreesStartFromOrigin"]}
43 checked={settings.newWorktreesStartFromOrigin}
44 onCheckedChange={(checked) =>
45 updateSettings({ newWorktreesStartFromOrigin: Boolean(checked) })
46 }
47 aria-label="Start new worktrees from remote by default"
48 />
49 }
50 />
51 );
53​
54export function WorktreesSettingsPanel() {
55 const { scope } = useSettingsScope();
56 const isProjectScope = scope.kind === "project" || scope.kind === "checkout";
57​
58 return (
59 <SettingsPageContainer>
60 <SettingsSection id="worktree-creation" title="Creation">
61 {!isProjectScope && <WorktreesDirectoryRow />}
62 <StartFromRemoteRow />
63 <AdvancedSettings targetIds={[searchableSetting("worktree-submodules").id]}>
64 <WorktreeSubmodulesRow />
65 </AdvancedSettings>
66 </SettingsSection>
67 <SettingsSection id="worktree-branches" title="Branches">
68 <BranchNamingSettings />
69 </SettingsSection>
70 <WorktreeCleanupSection />
71 </SettingsPageContainer>
72 );