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

LabsSettingsPanel.tsx

205 lines7.2 KB

1import { useAuth } from "@clerk/react";
2import { Link } from "@tanstack/react-router";
3import { managedCapabilityDenial } from "@t3tools/contracts";
4​
5import { hasCloudPublicConfig } from "~/cloud/publicConfig";
6import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt";
7import { Button } from "../ui/button";
8import { Switch } from "../ui/switch";
9import { ScopedSwitch } from "./ScopedSwitch";
10import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsLayout";
11import { searchableSetting } from "./settingsSearch";
12import { LegacyFeaturesSection } from "./SettingsPanels";
13import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
14import { useOptionalSettingsScope } from "./SettingsScopeContext";
15import { firstManagedDenial, usePrimaryManagedPolicy } from "~/state/managedPolicy";
16​
17/** Features still settling in, and legacy behavior kept for people who rely on it. */
18export function LabsSettingsPanel() {
19 return (
20 <SettingsPageContainer>
21 <SettingsSection id="beta" title="Beta">
22 <BoringSidebarRow />
23 <BoringSidebarMultilineRow />
24 {/* Clerk is only mounted when this build has T3 Connect. */}
25 {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
26 <LinkedEnvironmentsRow />
27 <SimlockHostsRow />
28 </SettingsSection>
29 <LegacyFeaturesSection />
30 </SettingsPageContainer>
31 );
33​
34function BoringSidebarRow() {
35 const settings = useScopedSettings();
36 const updateSettings = useUpdateScopedSettings();
37 return (
38 <SettingsRow
39 {...searchableSetting("boring-sidebar")}
40 description="Group sidebar threads into project folders. Pinned threads stay on top, and Snoozed and Settled stay below the folders."
41 control={
42 <Switch
43 checked={settings.boringSidebarEnabled || settings.legacySidebarEnabled}
44 // Turning it off also clears the opt-in of the removed legacy sidebar.
45 onCheckedChange={(checked) =>
46 updateSettings({ boringSidebarEnabled: Boolean(checked), legacySidebarEnabled: false })
47 }
48 aria-label="Boring sidebar (group by project)"
49 />
50 }
51 />
52 );
54​
55function BoringSidebarMultilineRow() {
56 const settings = useScopedSettings();
57 const updateSettings = useUpdateScopedSettings();
58 return (
59 <SettingsRow
60 {...searchableSetting("boring-sidebar-multiline")}
61 description="In the boring sidebar, show folder threads on two lines: the title, then the branch, pull request, and agent."
62 control={
63 <Switch
64 checked={settings.boringSidebarMultilineRows}
65 onCheckedChange={(checked) =>
66 updateSettings({ boringSidebarMultilineRows: Boolean(checked) })
67 }
68 aria-label="Two-line folder rows"
69 />
70 }
71 />
72 );
74​
75/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
76function GuestLinksRowWithSignIn() {
77 const { isSignedIn } = useAuth();
78 const { openAuthPrompt } = useT3ConnectAuthPrompt();
79 // `isSignedIn` is undefined until Clerk loads.
80 if (isSignedIn !== false) return <GuestLinksRow />;
81 return (
82 <SettingsRow
83 {...searchableSetting("guest-links")}
84 description="Share a thread with a guest who watches it live in their browser and sends messages you approve. Sign in to T3 Connect to use guest links."
85 control={
86 <Button size="sm" variant="outline" onClick={openAuthPrompt}>
87 Sign in
88 </Button>
89 }
90 />
91 );
93​
94function GuestLinksRow() {
95 const settings = useScopedSettings();
96 const updateSettings = useUpdateScopedSettings();
97 const scope = useOptionalSettingsScope();
98 const primaryPolicy = usePrimaryManagedPolicy();
99 // Guests arrive through T3 Connect, so a policy that turns Connect off turns this off too.
100 const connectDenial = firstManagedDenial(
101 scope
102 ? scope.connectedEnvironments.map((environment) => environment.serverConfig?.managedPolicy)
103 : [primaryPolicy],
104 (policy) => managedCapabilityDenial(policy, "connect"),
105 );
106 return (
107 <SettingsRow
108 serverScoped
109 {...searchableSetting("guest-links")}
110 settingKeys={["guestSharingEnabled"]}
111 // Turning guest links off still works without T3 Connect.
112 managed={settings.guestSharingEnabled ? undefined : connectDenial}
113 description={
114 <>
115 Share a thread with a guest who watches it live in their browser and sends messages you
116 approve. Needs T3 Connect: sign in and link this machine in{" "}
117 <Link to="/settings/access" className="underline underline-offset-2">
118 Sharing & access
119 </Link>
120 . While it is off, every guest link stops working.
121 </>
122 }
123 control={
124 <ScopedSwitch
125 settingKeys={["guestSharingEnabled"]}
126 checked={settings.guestSharingEnabled}
127 onCheckedChange={(checked) => updateSettings({ guestSharingEnabled: Boolean(checked) })}
128 aria-label="Guest links"
129 />
130 }
131 />
132 );
134​
135function LinkedEnvironmentsRow() {
136 const settings = useScopedSettings();
137 const updateSettings = useUpdateScopedSettings();
138 return (
139 <SettingsRow
140 serverScoped
141 {...searchableSetting("linked-environments-beta")}
142 settingKeys={["linkedEnvironmentsEnabled"]}
143 description={
144 <>
145 Let agents here work on your other machines, and theirs here. Turn it on for each machine,
146 then link them in{" "}
147 <Link to="/settings/connections" className="underline underline-offset-2">
148 Connections
149 </Link>
150 . While it is off, nothing new starts over a link; tasks already running finish.
151 </>
152 }
153 control={
154 <ScopedSwitch
155 settingKeys={["linkedEnvironmentsEnabled"]}
156 checked={settings.linkedEnvironmentsEnabled}
157 onCheckedChange={(checked) =>
158 updateSettings({ linkedEnvironmentsEnabled: Boolean(checked) })
159 }
160 aria-label="Linked environments"
161 />
162 }
163 />
164 );
166​
167function SimlockHostsRow() {
168 const settings = useScopedSettings();
169 const updateSettings = useUpdateScopedSettings();
170 return (
171 <SettingsRow
172 serverScoped
173 {...searchableSetting("simlock-hosts")}
174 settingKeys={["simlockDeviceHostsEnabled"]}
175 description={
176 <>
177 Let the Device panel lease simulators and emulators from your own{" "}
178 <a
179 href="https://incubator.callstack.com/simlock/"
180 target="_blank"
181 rel="noreferrer"
182 className="underline underline-offset-2"
183 >
184 Simlock
185 </a>{" "}
186 pool, added in{" "}
187 <Link to="/settings/devices" className="underline underline-offset-2">
188 Devices
189 </Link>
190 . An alpha that may change or break. T3 Code never installs Simlock.
191 </>
192 }
193 control={
194 <ScopedSwitch
195 settingKeys={["simlockDeviceHostsEnabled"]}
196 checked={settings.simlockDeviceHostsEnabled}
197 onCheckedChange={(checked) =>
198 updateSettings({ simlockDeviceHostsEnabled: Boolean(checked) })
199 }
200 aria-label="Simlock device hosts"
201 />
202 }
203 />
204 );