The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { thrownErrorMessage } from "@t3tools/client-runtime/errors"; |
| 2 | import { useComposerMenuState } from "../chat/useComposerMenuState"; |
| 3 | import { m as resolveMessage } from "../../i18n/messages"; |
| 4 | import { useOrchestrationCommand } from "../../state/use-orchestration-command"; |
| 5 | import { AuthOrchestrationOperateScope } from "@t3tools/contracts"; |
| 6 | import { useEnvironmentsWithScope } from "../../state/session"; |
| 7 | import { mapAtomCommandResult, settlePromise } from "@t3tools/client-runtime/state/runtime"; |
| 8 | import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment"; |
| 9 | import { planProjectRemoval } from "@t3tools/client-runtime/state/projects"; |
| 10 | import { type EnvironmentId, type SidebarProjectGroupingMode } from "@t3tools/contracts"; |
| 11 | import { |
| 12 | checkProjectAccess, |
| 13 | reportProjectFailure, |
| 14 | useProjectGroupUpdate, |
| 15 | type ProjectGroupUpdate, |
| 16 | } from "../../hooks/useProjectGroupUpdate"; |
| 17 | import { Navigate, useLocation, useNavigate } from "@tanstack/react-router"; |
| 18 | import { InfoIcon, Trash2Icon } from "lucide-react"; |
| 19 | import { lazy, Suspense, useRef, useState, type ReactNode } from "react"; |
| 20 | import { T, useGT, useMessages } from "gt-react"; |
| 21 | |
| 22 | import { useComposerDraftStore } from "../../composerDraftStore"; |
| 23 | import { releaseProjectDraftUploads } from "../../lib/composerDraftUploads"; |
| 24 | import { persistClientSettingsUpdate, useClientSettings } from "../../hooks/useSettings"; |
| 25 | import { readLocalApi } from "../../localApi"; |
| 26 | import { derivePhysicalProjectKey } from "@t3tools/client-runtime/state/project-grouping"; |
| 27 | import { |
| 28 | PROJECT_GROUPING_MODE_LABELS, |
| 29 | withProjectGroupingOverride, |
| 30 | type SidebarProjectGroupMember, |
| 31 | type SidebarProjectSnapshot, |
| 32 | } from "../../sidebarProjectGrouping"; |
| 33 | import { useEnvironments, usePrimaryEnvironmentId } from "../../state/environments"; |
| 34 | import { useThreadShells, waitForProjectRemoval } from "../../state/entities"; |
| 35 | import { refreshProjectFaviconUrl } from "../../state/assets"; |
| 36 | import { projectEnvironment } from "../../state/projects"; |
| 37 | import { ProjectFavicon } from "../ProjectFavicon"; |
| 38 | import { Alert, AlertDescription } from "../ui/alert"; |
| 39 | import { Button } from "../ui/button"; |
| 40 | import { Input } from "../ui/input"; |
| 41 | import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select"; |
| 42 | import { Switch } from "../ui/switch"; |
| 43 | import { stackedThreadToast, toastManager } from "../ui/toast"; |
| 44 | import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip"; |
| 45 | import { |
| 46 | SettingResetButton, |
| 47 | SettingsPageContainer, |
| 48 | SettingsRow, |
| 49 | SettingsSection, |
| 50 | } from "./settingsLayout"; |
| 51 | import { |
| 52 | canPickExternalProjectFavicon, |
| 53 | ProjectFaviconPickerDialog, |
| 54 | } from "./ProjectFaviconPickerDialog"; |
| 55 | import { ProjectActionsSettings } from "./ProjectActionsSettings"; |
| 56 | import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings"; |
| 57 | import { |
| 58 | defaultProjectIcon, |
| 59 | hasDefaultProjectIcon, |
| 60 | projectGroupTitleNeedsUpdate, |
| 61 | SCRATCH_PROJECT_TITLE, |
| 62 | scopeProjectSettingsGroup, |
| 63 | } from "./ProjectSettingsPanel.logic"; |
| 64 | import { useSettingsProjectGroups } from "./useSettingsProjectGroups"; |
| 65 | import { readUnloadedThreadCount } from "../../state/olderSettledShelf"; |
| 66 | import { settingsScopeEnvironmentLabels } from "./settingsScopeAxis"; |
| 67 | |
| 68 | const ProjectIconPickerDialog = lazy(() => |
| 69 | import("./ProjectIconPickerDialog").then((module) => ({ |
| 70 | default: module.ProjectIconPickerDialog, |
| 71 | })), |
| 72 | ); |
| 73 | |
| 74 | function isGroupingSelection(value: unknown): value is SidebarProjectGroupingMode | "inherit" { |
| 75 | return ( |
| 76 | value === "inherit" || |
| 77 | value === "repository" || |
| 78 | value === "repository_path" || |
| 79 | value === "separate" |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | // Grouping overrides are client settings, so they stay editable without project write access. |
| 84 | function CheckoutGroupingSelect({ member }: { member: SidebarProjectGroupMember }) { |
| 85 | const gt = useGT(); |
| 86 | const m = useMessages(); |
| 87 | const overrideKey = derivePhysicalProjectKey(member); |
| 88 | const globalMode = useClientSettings((settings) => settings.sidebarProjectGroupingMode); |
| 89 | const selection = useClientSettings( |
| 90 | (settings) => settings.sidebarProjectGroupingOverrides?.[overrideKey] ?? "inherit", |
| 91 | ); |
| 92 | return ( |
| 93 | <Select |
| 94 | value={selection} |
| 95 | onValueChange={(value) => { |
| 96 | if (!isGroupingSelection(value)) return; |
| 97 | persistClientSettingsUpdate((current) => ({ |
| 98 | ...current, |
| 99 | sidebarProjectGroupingOverrides: withProjectGroupingOverride( |
| 100 | current.sidebarProjectGroupingOverrides, |
| 101 | overrideKey, |
| 102 | value, |
| 103 | ), |
| 104 | })).catch((error) => { |
| 105 | console.error("Failed to save checkout grouping rule", error); |
| 106 | toastManager.add( |
| 107 | stackedThreadToast({ |
| 108 | type: "error", |
| 109 | title: gt("Could not save grouping rule"), |
| 110 | description: |
| 111 | error instanceof Error |
| 112 | ? (thrownErrorMessage(error, resolveMessage) ?? error.message) |
| 113 | : gt("An error occurred."), |
| 114 | }), |
| 115 | ); |
| 116 | }); |
| 117 | }} |
| 118 | > |
| 119 | <SelectTrigger |
| 120 | size="sm" |
| 121 | aria-label={gt("Grouping rule for {path} on {environment}", { |
| 122 | path: member.workspaceRoot, |
| 123 | environment: member.environmentLabel |
| 124 | ? `${member.environmentLabel} (${member.environmentId})` |
| 125 | : member.environmentId, |
| 126 | })} |
| 127 | > |
| 128 | <SelectValue> |
| 129 | {selection === "inherit" |
| 130 | ? gt("Default ({mode})", { mode: m(PROJECT_GROUPING_MODE_LABELS[globalMode]) }) |
| 131 | : m(PROJECT_GROUPING_MODE_LABELS[selection])} |
| 132 | </SelectValue> |
| 133 | </SelectTrigger> |
| 134 | <SelectPopup align="end" alignItemWithTrigger={false}> |
| 135 | <SelectItem hideIndicator value="inherit"> |
| 136 | <T>Use global default</T> |
| 137 | </SelectItem> |
| 138 | <SelectItem hideIndicator value="repository"> |
| 139 | {m(PROJECT_GROUPING_MODE_LABELS.repository)} |
| 140 | </SelectItem> |
| 141 | <SelectItem hideIndicator value="repository_path"> |
| 142 | {m(PROJECT_GROUPING_MODE_LABELS.repository_path)} |
| 143 | </SelectItem> |
| 144 | <SelectItem hideIndicator value="separate"> |
| 145 | {m(PROJECT_GROUPING_MODE_LABELS.separate)} |
| 146 | </SelectItem> |
| 147 | </SelectPopup> |
| 148 | </Select> |
| 149 | ); |
| 150 | } |
| 151 | |
| 152 | export type ProjectSettingsCategory = "general" | "source-control" | "project"; |
| 153 | |
| 154 | interface ProjectSelection { |
| 155 | readonly key: string; |
| 156 | readonly environmentId: EnvironmentId | null; |
| 157 | readonly checkoutKey: string | null; |
| 158 | readonly memberKeys: ReadonlyArray<string>; |
| 159 | } |
| 160 | |
| 161 | function sameProjectSelection(a: ProjectSelection | null, b: ProjectSelection): boolean { |
| 162 | return ( |
| 163 | a !== null && |
| 164 | a.key === b.key && |
| 165 | a.environmentId === b.environmentId && |
| 166 | a.checkoutKey === b.checkoutKey && |
| 167 | a.memberKeys.length === b.memberKeys.length && |
| 168 | a.memberKeys.every((key, index) => key === b.memberKeys[index]) |
| 169 | ); |
| 170 | } |
| 171 | |
| 172 | export function ProjectSettingsPanel({ |
| 173 | projectKey, |
| 174 | environmentId = null, |
| 175 | checkoutKey = null, |
| 176 | unavailable, |
| 177 | }: { |
| 178 | projectKey: string; |
| 179 | environmentId?: EnvironmentId | null; |
| 180 | checkoutKey?: string | null; |
| 181 | unavailable?: ReactNode; |
| 182 | }) { |
| 183 | const gt = useGT(); |
| 184 | const groups = useSettingsProjectGroups(); |
| 185 | const pathname = useLocation({ select: (location) => location.pathname }); |
| 186 | |
| 187 | const selected = groups.find((group) => group.projectKey === projectKey) ?? null; |
| 188 | const members = |
| 189 | selected?.memberProjects.filter( |
| 190 | (member) => |
| 191 | (environmentId === null || member.environmentId === environmentId) && |
| 192 | (checkoutKey === null || member.physicalProjectKey === checkoutKey), |
| 193 | ) ?? []; |
| 194 | |
| 195 | // Retain group members so grouping-rule changes can follow the project to its new group. |
| 196 | const [lastSelection, setLastSelection] = useState<ProjectSelection | null>(null); |
| 197 | if (selected && members.length > 0) { |
| 198 | const current: ProjectSelection = { |
| 199 | key: selected.projectKey, |
| 200 | environmentId, |
| 201 | checkoutKey, |
| 202 | memberKeys: members.map((member) => member.physicalProjectKey), |
| 203 | }; |
| 204 | if (!sameProjectSelection(lastSelection, current)) setLastSelection(current); |
| 205 | } |
| 206 | |
| 207 | const successor = |
| 208 | members.length === 0 && |
| 209 | lastSelection?.key === projectKey && |
| 210 | lastSelection.environmentId === environmentId && |
| 211 | lastSelection.checkoutKey === checkoutKey |
| 212 | ? groups.find((group) => |
| 213 | group.memberProjects.some((member) => |
| 214 | lastSelection.memberKeys.includes(member.physicalProjectKey), |
| 215 | ), |
| 216 | ) |
| 217 | : undefined; |
| 218 | if (successor) { |
| 219 | return ( |
| 220 | <Navigate |
| 221 | to={pathname} |
| 222 | search={{ |
| 223 | project: successor.projectKey, |
| 224 | machine: environmentId ?? undefined, |
| 225 | checkout: checkoutKey ?? undefined, |
| 226 | }} |
| 227 | replace |
| 228 | hashScrollIntoView={false} |
| 229 | /> |
| 230 | ); |
| 231 | } |
| 232 | |
| 233 | if ((!selected || members.length === 0) && unavailable != null) return unavailable; |
| 234 | |
| 235 | if (!selected) { |
| 236 | return ( |
| 237 | <div className="flex flex-1 items-center justify-center p-8 text-sm text-muted-foreground"> |
| 238 | {groups.length === 0 |
| 239 | ? gt("Add a project from the sidebar to configure it here.") |
| 240 | : gt("This project is no longer available.")} |
| 241 | </div> |
| 242 | ); |
| 243 | } |
| 244 | if (members.length === 0) |
| 245 | return ( |
| 246 | <p className="p-8 text-sm text-muted-foreground"> |
| 247 | <T>This checkout is no longer available in the selected project and environment.</T> |
| 248 | </p> |
| 249 | ); |
| 250 | const scopedGroup = scopeProjectSettingsGroup(selected, members); |
| 251 | return ( |
| 252 | <ProjectDetail |
| 253 | key={`${selected.projectKey}:${environmentId ?? "all"}:${checkoutKey ?? "all"}`} |
| 254 | group={scopedGroup} |
| 255 | allMembers={selected.memberProjects} |
| 256 | hasOtherMembers={members.length < selected.memberProjects.length} |
| 257 | /> |
| 258 | ); |
| 259 | } |
| 260 | |
| 261 | function ProjectDetail({ |
| 262 | group, |
| 263 | allMembers, |
| 264 | hasOtherMembers, |
| 265 | }: { |
| 266 | group: SidebarProjectSnapshot; |
| 267 | /** Pin and archive belong to the whole project, even when one machine is picked. */ |
| 268 | allMembers: ReadonlyArray<SidebarProjectGroupMember>; |
| 269 | hasOtherMembers: boolean; |
| 270 | }) { |
| 271 | const gt = useGT(); |
| 272 | const navigate = useNavigate({ from: "/settings" }); |
| 273 | const primaryEnvironmentId = usePrimaryEnvironmentId(); |
| 274 | const { environments } = useEnvironments(); |
| 275 | const environmentById = new Map( |
| 276 | environments.map((environment) => [environment.environmentId, environment]), |
| 277 | ); |
| 278 | const editableIds = useEnvironmentsWithScope(allMembers, AuthOrchestrationOperateScope); |
| 279 | const canEditGroup = group.memberProjects.every((member) => |
| 280 | editableIds.has(member.environmentId), |
| 281 | ); |
| 282 | const filePickerProject = |
| 283 | group.memberProjects.find( |
| 284 | (member) => environmentById.get(member.environmentId)?.serverConfig != null, |
| 285 | ) ?? group.memberProjects[0]!; |
| 286 | const threads = useThreadShells(); |
| 287 | const deleteProject = useOrchestrationCommand(projectEnvironment.delete, { |
| 288 | reportFailure: false, |
| 289 | }); |
| 290 | const projectNameEditedRef = useRef(false); |
| 291 | |
| 292 | const faviconPath = group.faviconPath ?? null; |
| 293 | const projectIcon = group.projectIcon ?? null; |
| 294 | const pickProjectFavicon = |
| 295 | typeof window !== "undefined" && |
| 296 | group.memberProjects.every( |
| 297 | (member) => |
| 298 | member.environmentId === primaryEnvironmentId && |
| 299 | canPickExternalProjectFavicon(member.workspaceRoot, navigator.platform), |
| 300 | ) |
| 301 | ? window.desktopBridge?.pickProjectFavicon |
| 302 | : undefined; |
| 303 | |
| 304 | const { updateProjectGroup, canOrganizeProjectGroup } = useProjectGroupUpdate(); |
| 305 | const updateAllMembers = ( |
| 306 | input: ProjectGroupUpdate | ((member: SidebarProjectGroupMember) => ProjectGroupUpdate), |
| 307 | failureTitle: string, |
| 308 | ) => updateProjectGroup(group.memberProjects, input, failureTitle); |
| 309 | const canOrganize = |
| 310 | allMembers.every((member) => editableIds.has(member.environmentId)) && |
| 311 | canOrganizeProjectGroup(allMembers); |
| 312 | const [isOrganizing, setIsOrganizing] = useState(false); |
| 313 | const organize = async (input: ProjectGroupUpdate, failureTitle: string) => { |
| 314 | setIsOrganizing(true); |
| 315 | await updateProjectGroup(allMembers, input, failureTitle); |
| 316 | setIsOrganizing(false); |
| 317 | }; |
| 318 | |
| 319 | const renameGroup = async (nextTitle: string, wasEdited: boolean) => { |
| 320 | const title = nextTitle.trim(); |
| 321 | if (!title) { |
| 322 | toastManager.add({ type: "warning", title: gt("Project title cannot be empty") }); |
| 323 | return; |
| 324 | } |
| 325 | if (!projectGroupTitleNeedsUpdate(group.memberProjects, title, wasEdited)) return; |
| 326 | await updateAllMembers({ title }, gt("Failed to rename project")); |
| 327 | }; |
| 328 | |
| 329 | const [faviconPickerOpen, setFaviconPickerOpen] = useComposerMenuState(!canEditGroup); |
| 330 | const [iconPickerOpen, setIconPickerOpen] = useComposerMenuState(!canEditGroup); |
| 331 | const [isSavingFavicon, setIsSavingFavicon] = useState(false); |
| 332 | const savingFaviconRef = useRef(false); |
| 333 | const setProjectIcon = async (input: Parameters<typeof updateAllMembers>[0]) => { |
| 334 | if (savingFaviconRef.current) return; |
| 335 | savingFaviconRef.current = true; |
| 336 | setIsSavingFavicon(true); |
| 337 | await updateAllMembers(input, gt("Failed to update project icon")); |
| 338 | for (const member of group.memberProjects) { |
| 339 | const update = typeof input === "function" ? input(member) : input; |
| 340 | if (update.faviconPath === undefined || update.projectIcon) continue; |
| 341 | refreshProjectFaviconUrl({ |
| 342 | environmentId: member.environmentId, |
| 343 | cwd: member.workspaceRoot, |
| 344 | faviconPath: update.faviconPath, |
| 345 | }); |
| 346 | } |
| 347 | savingFaviconRef.current = false; |
| 348 | setIsSavingFavicon(false); |
| 349 | }; |
| 350 | |
| 351 | const hasMultipleCheckouts = group.memberProjects.length > 1; |
| 352 | const canResetScratchTitle = |
| 353 | group.memberProjects.every((member) => member.isScratch) && |
| 354 | group.memberProjects.some((member) => member.title !== SCRATCH_PROJECT_TITLE); |
| 355 | |
| 356 | const removeMembers = async (members: ReadonlyArray<SidebarProjectGroupMember>) => { |
| 357 | if (checkProjectAccess(members, gt("Failed to remove project"))) return; |
| 358 | const api = readLocalApi(); |
| 359 | if (!api) return; |
| 360 | |
| 361 | const { projectThreads, isWholeGroup, confirmationMessage } = planProjectRemoval( |
| 362 | { |
| 363 | members, |
| 364 | groupMemberCount: group.memberProjects.length, |
| 365 | hasOtherMembers, |
| 366 | displayName: group.displayName, |
| 367 | threads, |
| 368 | unloadedThreadCount: readUnloadedThreadCount(members, threads), |
| 369 | }, |
| 370 | resolveMessage, |
| 371 | ); |
| 372 | const confirmed = await settlePromise(() => |
| 373 | api.dialogs.confirm(confirmationMessage, { variant: "destructive" }), |
| 374 | ); |
| 375 | if (confirmed._tag === "Failure" || !confirmed.value) return; |
| 376 | if (checkProjectAccess(members, gt("Failed to remove project"))) return; |
| 377 | |
| 378 | const draftStore = useComposerDraftStore.getState(); |
| 379 | const remainingMember = allMembers.find( |
| 380 | (candidate) => |
| 381 | !members.some( |
| 382 | (member) => |
| 383 | member.environmentId === candidate.environmentId && member.id === candidate.id, |
| 384 | ), |
| 385 | ); |
| 386 | for (const member of members) { |
| 387 | if (checkProjectAccess([member], gt("Failed to remove project"))) return; |
| 388 | const memberThreads = projectThreads.filter( |
| 389 | (thread) => thread.environmentId === member.environmentId && thread.projectId === member.id, |
| 390 | ); |
| 391 | const result = mapAtomCommandResult( |
| 392 | await deleteProject({ |
| 393 | environmentId: member.environmentId, |
| 394 | input: { |
| 395 | projectId: member.id, |
| 396 | force: true, |
| 397 | }, |
| 398 | }), |
| 399 | () => undefined, |
| 400 | ); |
| 401 | if (result._tag === "Failure") { |
| 402 | reportProjectFailure(gt('Failed to remove "{title}"', { title: member.title }), result); |
| 403 | return; |
| 404 | } |
| 405 | const projectRef = scopeProjectRef(member.environmentId, member.id); |
| 406 | await waitForProjectRemoval(projectRef); |
| 407 | releaseProjectDraftUploads( |
| 408 | projectRef, |
| 409 | memberThreads.map((thread) => scopeThreadRef(thread.environmentId, thread.id)), |
| 410 | ); |
| 411 | const projectDraftThread = draftStore.getDraftThreadByProjectRef(projectRef); |
| 412 | if (projectDraftThread && remainingMember) { |
| 413 | draftStore.setDraftThreadContext(projectDraftThread.draftId, { |
| 414 | projectRef: scopeProjectRef(remainingMember.environmentId, remainingMember.id), |
| 415 | environmentSelection: "manual", |
| 416 | loadBalancedEnvironmentId: null, |
| 417 | }); |
| 418 | } else if (projectDraftThread) { |
| 419 | draftStore.clearDraftThread(projectDraftThread.draftId); |
| 420 | } |
| 421 | draftStore.clearProjectDraftThreadId(projectRef); |
| 422 | } |
| 423 | |
| 424 | if (isWholeGroup && !hasOtherMembers) { |
| 425 | void navigate({ |
| 426 | to: "/settings/projects", |
| 427 | search: ({ machine }) => ({ project: undefined, machine, checkout: undefined }), |
| 428 | replace: true, |
| 429 | }); |
| 430 | } |
| 431 | }; |
| 432 | |
| 433 | const checkoutsByEnvironment = new Map<EnvironmentId, SidebarProjectGroupMember[]>(); |
| 434 | for (const member of group.memberProjects) { |
| 435 | const members = checkoutsByEnvironment.get(member.environmentId); |
| 436 | if (members) members.push(member); |
| 437 | else checkoutsByEnvironment.set(member.environmentId, [member]); |
| 438 | } |
| 439 | // A lone checkout is removed from the Danger section, but it still needs its grouping |
| 440 | // rule here so "Keep separate" can be undone. |
| 441 | const checkoutControls = (member: SidebarProjectGroupMember) => ( |
| 442 | <div className="flex w-full min-w-0 items-center gap-2 @min-[32rem]/settings-row:w-auto"> |
| 443 | <div className="min-w-0 flex-1 @min-[32rem]/settings-row:w-72 @min-[32rem]/settings-row:flex-none"> |
| 444 | <CheckoutGroupingSelect member={member} /> |
| 445 | </div> |
| 446 | {hasMultipleCheckouts ? ( |
| 447 | <Button |
| 448 | size="sm" |
| 449 | variant="outline" |
| 450 | disabled={!editableIds.has(member.environmentId)} |
| 451 | onClick={() => void removeMembers([member])} |
| 452 | aria-label={gt("Remove checkout {path}", { path: member.workspaceRoot })} |
| 453 | > |
| 454 | {gt("Remove", { $context: "verb, removes a checkout" })} |
| 455 | </Button> |
| 456 | ) : null} |
| 457 | </div> |
| 458 | ); |
| 459 | const checkoutChoices = ( |
| 460 | <SettingsSection title={gt("Checkouts")}> |
| 461 | <p className="px-3 py-2.5 text-xs text-muted-foreground sm:px-4"> |
| 462 | <T> |
| 463 | Grouping rule decides how each checkout joins project groups in the sidebar. Changing it |
| 464 | can move a checkout to a different project. |
| 465 | </T> |
| 466 | </p> |
| 467 | {Array.from(checkoutsByEnvironment, ([environmentId, members]) => { |
| 468 | if (checkoutsByEnvironment.size === 1) { |
| 469 | return members.map((member) => ( |
| 470 | <SettingsRow |
| 471 | key={member.physicalProjectKey} |
| 472 | title={member.environmentLabel ?? gt("Environment")} |
| 473 | description={member.workspaceRoot} |
| 474 | control={checkoutControls(member)} |
| 475 | /> |
| 476 | )); |
| 477 | } |
| 478 | const firstMember = members[0]!; |
| 479 | const hasMultiple = members.length > 1; |
| 480 | const environment = environmentById.get(environmentId); |
| 481 | const labels = environment |
| 482 | ? settingsScopeEnvironmentLabels(environment, environments) |
| 483 | : { |
| 484 | primary: firstMember.environmentLabel ?? gt("Environment"), |
| 485 | secondary: environmentId, |
| 486 | }; |
| 487 | return ( |
| 488 | <SettingsRow |
| 489 | key={environmentId} |
| 490 | title={labels.primary} |
| 491 | description={ |
| 492 | <> |
| 493 | {labels.secondary ? ( |
| 494 | <span className="block truncate">{labels.secondary}</span> |
| 495 | ) : null} |
| 496 | {!hasMultiple ? ( |
| 497 | <Tooltip> |
| 498 | <TooltipTrigger render={<span className="block truncate" />}> |
| 499 | {firstMember.workspaceRoot} |
| 500 | </TooltipTrigger> |
| 501 | <TooltipPopup>{firstMember.workspaceRoot}</TooltipPopup> |
| 502 | </Tooltip> |
| 503 | ) : null} |
| 504 | </> |
| 505 | } |
| 506 | control={hasMultiple ? undefined : checkoutControls(firstMember)} |
| 507 | > |
| 508 | {hasMultiple ? ( |
| 509 | <div className="space-y-3 pb-2 pt-1"> |
| 510 | {members.map((member) => ( |
| 511 | <div |
| 512 | key={member.physicalProjectKey} |
| 513 | className="flex min-w-0 flex-col gap-1.5 @min-[36rem]/settings-row:flex-row @min-[36rem]/settings-row:items-center @min-[36rem]/settings-row:justify-between @min-[36rem]/settings-row:gap-3" |
| 514 | > |
| 515 | <Tooltip> |
| 516 | <TooltipTrigger |
| 517 | render={ |
| 518 | <span className="min-w-0 max-w-full truncate text-xs text-muted-foreground/80" /> |
| 519 | } |
| 520 | > |
| 521 | {member.workspaceRoot} |
| 522 | </TooltipTrigger> |
| 523 | <TooltipPopup>{member.workspaceRoot}</TooltipPopup> |
| 524 | </Tooltip> |
| 525 | <div className="shrink-0">{checkoutControls(member)}</div> |
| 526 | </div> |
| 527 | ))} |
| 528 | </div> |
| 529 | ) : null} |
| 530 | </SettingsRow> |
| 531 | ); |
| 532 | })} |
| 533 | </SettingsSection> |
| 534 | ); |
| 535 | |
| 536 | return ( |
| 537 | <> |
| 538 | <SettingsPageContainer className="gap-6"> |
| 539 | <Alert variant="info"> |
| 540 | <InfoIcon aria-hidden /> |
| 541 | <AlertDescription> |
| 542 | <T> |
| 543 | Can't find a setting? Keep this project picked above and hop to any other settings |
| 544 | page. |
| 545 | </T> |
| 546 | </AlertDescription> |
| 547 | </Alert> |
| 548 | <SettingsSection id="project-overview" title={gt("Project")} hideTitle> |
| 549 | {!canEditGroup ? ( |
| 550 | <p className="px-3 py-2 text-sm text-muted-foreground sm:px-4"> |
| 551 | {group.memberProjects.length > 1 |
| 552 | ? gt("Shared settings require permission to change every checkout in this group.") |
| 553 | : gt("This connection cannot change this project.")} |
| 554 | </p> |
| 555 | ) : null} |
| 556 | <SettingsRow |
| 557 | title={gt("Name")} |
| 558 | description={gt( |
| 559 | "The shared name for this project group in the sidebar and thread lists.", |
| 560 | )} |
| 561 | resetAction={ |
| 562 | canResetScratchTitle ? ( |
| 563 | <SettingResetButton |
| 564 | ariaLabel={gt("Reset project name to default")} |
| 565 | disabled={!canEditGroup} |
| 566 | onClick={() => |
| 567 | void updateAllMembers( |
| 568 | { title: SCRATCH_PROJECT_TITLE }, |
| 569 | gt("Failed to rename project"), |
| 570 | ) |
| 571 | } |
| 572 | /> |
| 573 | ) : null |
| 574 | } |
| 575 | control={ |
| 576 | <Input |
| 577 | key={`${group.projectKey}:${group.displayName}`} |
| 578 | size="sm" |
| 579 | className="w-full sm:w-64" |
| 580 | aria-label={gt("Project name")} |
| 581 | disabled={!canEditGroup} |
| 582 | defaultValue={group.displayName} |
| 583 | onChange={() => { |
| 584 | projectNameEditedRef.current = true; |
| 585 | }} |
| 586 | onBlur={(event) => { |
| 587 | const wasEdited = projectNameEditedRef.current; |
| 588 | projectNameEditedRef.current = false; |
| 589 | void renameGroup(event.currentTarget.value, wasEdited); |
| 590 | }} |
| 591 | onKeyDown={(event) => { |
| 592 | if (event.nativeEvent.isComposing || event.keyCode === 229) return; |
| 593 | if (event.key === "Enter") event.currentTarget.blur(); |
| 594 | }} |
| 595 | /> |
| 596 | } |
| 597 | /> |
| 598 | <SettingsRow |
| 599 | title={gt("Project icon")} |
| 600 | description={ |
| 601 | projectIcon?.kind === "lucide" |
| 602 | ? `${projectIcon.name} · ${projectIcon.color}` |
| 603 | : projectIcon?.kind === "monogram" |
| 604 | ? `${projectIcon.text} · ${projectIcon.color}` |
| 605 | : projectIcon?.kind === "emoji" |
| 606 | ? projectIcon.emoji |
| 607 | : (faviconPath ?? gt("Automatic")) |
| 608 | } |
| 609 | resetAction={ |
| 610 | group.memberProjects.some((member) => !hasDefaultProjectIcon(member)) ? ( |
| 611 | <SettingResetButton |
| 612 | ariaLabel={gt("Reset project icon to default")} |
| 613 | disabled={isSavingFavicon || !canEditGroup} |
| 614 | onClick={() => void setProjectIcon(defaultProjectIcon)} |
| 615 | /> |
| 616 | ) : null |
| 617 | } |
| 618 | control={ |
| 619 | <div className="flex items-center gap-2"> |
| 620 | <ProjectFavicon project={group} className="size-6" /> |
| 621 | <Button |
| 622 | size="sm" |
| 623 | variant="outline" |
| 624 | type="button" |
| 625 | aria-label={gt("Choose a project icon")} |
| 626 | disabled={isSavingFavicon || !canEditGroup} |
| 627 | onClick={() => setIconPickerOpen(true)} |
| 628 | > |
| 629 | <T>Choose icon</T> |
| 630 | </Button> |
| 631 | <Button |
| 632 | size="sm" |
| 633 | variant="outline" |
| 634 | type="button" |
| 635 | aria-label={gt("Choose a project icon file")} |
| 636 | disabled={isSavingFavicon || !canEditGroup} |
| 637 | onClick={() => setFaviconPickerOpen(true)} |
| 638 | > |
| 639 | <T>Choose file</T> |
| 640 | </Button> |
| 641 | </div> |
| 642 | } |
| 643 | /> |
| 644 | {canOrganize ? ( |
| 645 | <> |
| 646 | <SettingsRow |
| 647 | title={gt("Pin")} |
| 648 | description={gt("Pinned projects come first in project pickers.")} |
| 649 | control={ |
| 650 | <Switch |
| 651 | checked={group.pinned} |
| 652 | disabled={isOrganizing} |
| 653 | onCheckedChange={(checked) => |
| 654 | void organize( |
| 655 | { pinned: Boolean(checked) }, |
| 656 | checked ? gt("Failed to pin project") : gt("Failed to unpin project"), |
| 657 | ) |
| 658 | } |
| 659 | aria-label={gt("Pin project")} |
| 660 | /> |
| 661 | } |
| 662 | /> |
| 663 | <SettingsRow |
| 664 | title={gt("Archive")} |
| 665 | description={ |
| 666 | group.archived |
| 667 | ? gt("Hidden from project pickers. Threads and files are kept.") |
| 668 | : gt("Hides the project from project pickers. Threads and files are kept.") |
| 669 | } |
| 670 | control={ |
| 671 | <Button |
| 672 | size="sm" |
| 673 | variant="outline" |
| 674 | disabled={isOrganizing} |
| 675 | onClick={() => |
| 676 | void organize( |
| 677 | { archived: !group.archived }, |
| 678 | group.archived |
| 679 | ? gt("Failed to unarchive project") |
| 680 | : gt("Failed to archive project"), |
| 681 | ) |
| 682 | } |
| 683 | > |
| 684 | {group.archived |
| 685 | ? gt("Unarchive") |
| 686 | : gt("Archive", { $context: "verb, archives a project" })} |
| 687 | </Button> |
| 688 | } |
| 689 | /> |
| 690 | </> |
| 691 | ) : null} |
| 692 | </SettingsSection> |
| 693 | <ProjectDefaultsSettings category="project" /> |
| 694 | <ProjectActionsSettings /> |
| 695 | {checkoutChoices} |
| 696 | <SettingsSection title={gt("Danger")}> |
| 697 | <SettingsRow |
| 698 | title={ |
| 699 | hasOtherMembers |
| 700 | ? gt("Remove checkout") |
| 701 | : group.memberProjects.length > 1 |
| 702 | ? gt("Remove this project everywhere") |
| 703 | : gt("Remove project") |
| 704 | } |
| 705 | description={ |
| 706 | hasOtherMembers |
| 707 | ? gt( |
| 708 | "Deletes the selected machine's checkout entries and their threads. Other machines and files on disk are not touched.", |
| 709 | ) |
| 710 | : group.memberProjects.length > 1 |
| 711 | ? gt( |
| 712 | "{count, plural, other {Deletes all {count} checkout entries and their threads on every machine. Files on disk are not touched.}}", |
| 713 | { count: group.memberProjects.length }, |
| 714 | ) |
| 715 | : gt("Deletes the project entry and its threads. Files on disk are not touched.") |
| 716 | } |
| 717 | control={ |
| 718 | <Button |
| 719 | size="sm" |
| 720 | variant="destructive-outline" |
| 721 | disabled={!canEditGroup} |
| 722 | onClick={() => void removeMembers(group.memberProjects)} |
| 723 | > |
| 724 | <Trash2Icon /> |
| 725 | {hasOtherMembers |
| 726 | ? gt("Remove checkout") |
| 727 | : group.memberProjects.length > 1 |
| 728 | ? gt("Remove all entries") |
| 729 | : gt("Remove project")} |
| 730 | </Button> |
| 731 | } |
| 732 | /> |
| 733 | </SettingsSection> |
| 734 | </SettingsPageContainer> |
| 735 | |
| 736 | <ProjectFaviconPickerDialog |
| 737 | key={`${filePickerProject.environmentId}:${filePickerProject.workspaceRoot}:${faviconPickerOpen}`} |
| 738 | cwd={filePickerProject.workspaceRoot} |
| 739 | environmentId={filePickerProject.environmentId} |
| 740 | onOpenChange={setFaviconPickerOpen} |
| 741 | {...(pickProjectFavicon |
| 742 | ? { onPickExternal: () => pickProjectFavicon(filePickerProject.workspaceRoot) } |
| 743 | : {})} |
| 744 | onSelect={(path) => void setProjectIcon({ faviconPath: path, projectIcon: null })} |
| 745 | open={faviconPickerOpen && canEditGroup} |
| 746 | projectName={group.displayName} |
| 747 | /> |
| 748 | {iconPickerOpen && canEditGroup ? ( |
| 749 | <Suspense fallback={null}> |
| 750 | <ProjectIconPickerDialog |
| 751 | current={projectIcon} |
| 752 | projectName={group.title} |
| 753 | open |
| 754 | onOpenChange={setIconPickerOpen} |
| 755 | onSelect={(icon) => void setProjectIcon({ faviconPath: null, projectIcon: icon })} |
| 756 | /> |
| 757 | </Suspense> |
| 758 | ) : null} |
| 759 | </> |
| 760 | ); |
| 761 | } |