The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | AuthSettingsWriteScope, |
| 3 | ENVIRONMENT_MACHINE_KINDS, |
| 4 | isEnvironmentMachineKind, |
| 5 | resolveEnvironmentMachineKind, |
| 6 | type EnvironmentId, |
| 7 | type ServerConfig, |
| 8 | } from "@t3tools/contracts"; |
| 9 | import { msg, T, useGT, useMessages } from "gt-react"; |
| 10 | |
| 11 | import { m, type MessageResolver } from "../../i18n/messages"; |
| 12 | import { useUpdateEnvironmentSettings } from "../../hooks/useSettings"; |
| 13 | import { useEnvironmentScope } from "../../state/session"; |
| 14 | import { ENVIRONMENT_MACHINE_KIND_LABELS, EnvironmentMachineIcon } from "../EnvironmentMachineIcon"; |
| 15 | import { |
| 16 | MenuItem, |
| 17 | MenuRadioGroup, |
| 18 | MenuRadioItem, |
| 19 | MenuSeparator, |
| 20 | MenuSub, |
| 21 | MenuSubPopup, |
| 22 | MenuSubTrigger, |
| 23 | } from "../ui/menu"; |
| 24 | |
| 25 | export function resolveEnvironmentIconPickerLock( |
| 26 | input: { |
| 27 | readonly serverConfig: Pick<ServerConfig, "environment"> | null; |
| 28 | readonly operateAccess: "granted" | "denied" | "pending"; |
| 29 | }, |
| 30 | resolve: MessageResolver = m, |
| 31 | ): string | null { |
| 32 | if (input.serverConfig === null) { |
| 33 | return resolve(msg("Connect to this environment to change its icon.")); |
| 34 | } |
| 35 | if (input.operateAccess !== "granted") { |
| 36 | return resolve(msg("Your session on this environment cannot change its settings.")); |
| 37 | } |
| 38 | return null; |
| 39 | } |
| 40 | |
| 41 | export function EnvironmentIconMenu({ |
| 42 | environmentId, |
| 43 | serverConfig, |
| 44 | }: { |
| 45 | readonly environmentId: EnvironmentId; |
| 46 | readonly serverConfig: Pick<ServerConfig, "environment"> | null; |
| 47 | }) { |
| 48 | const gt = useGT(); |
| 49 | const resolve = useMessages(); |
| 50 | const updateSettings = useUpdateEnvironmentSettings(environmentId); |
| 51 | const operateAccess = useEnvironmentScope(environmentId, AuthSettingsWriteScope) |
| 52 | ? "granted" |
| 53 | : "denied"; |
| 54 | const lock = resolveEnvironmentIconPickerLock({ serverConfig, operateAccess }, resolve); |
| 55 | const detected = serverConfig?.environment.platform.machine ?? "server"; |
| 56 | const resolved = resolveEnvironmentMachineKind(serverConfig); |
| 57 | |
| 58 | return ( |
| 59 | <MenuSub> |
| 60 | <MenuSubTrigger> |
| 61 | <EnvironmentMachineIcon kind={resolved} /> |
| 62 | <T>Icon</T> |
| 63 | </MenuSubTrigger> |
| 64 | <MenuSubPopup> |
| 65 | {lock !== null ? ( |
| 66 | <> |
| 67 | <MenuItem disabled className="whitespace-normal"> |
| 68 | {lock} |
| 69 | </MenuItem> |
| 70 | <MenuSeparator /> |
| 71 | </> |
| 72 | ) : null} |
| 73 | <MenuRadioGroup |
| 74 | value={resolved} |
| 75 | onValueChange={(next) => { |
| 76 | if (lock !== null || !isEnvironmentMachineKind(next)) return; |
| 77 | updateSettings({ environmentIcon: next === detected ? null : next }); |
| 78 | }} |
| 79 | > |
| 80 | {ENVIRONMENT_MACHINE_KINDS.map((kind) => ( |
| 81 | <MenuRadioItem key={kind} value={kind} disabled={lock !== null}> |
| 82 | <span className="flex min-w-0 items-center gap-2"> |
| 83 | <EnvironmentMachineIcon kind={kind} className="size-3.5 shrink-0" /> |
| 84 | <span className="min-w-0 flex-1 truncate"> |
| 85 | {resolve(ENVIRONMENT_MACHINE_KIND_LABELS[kind])} |
| 86 | </span> |
| 87 | {kind === detected ? ( |
| 88 | <span className="shrink-0 text-xs text-muted-foreground"> |
| 89 | {serverConfig?.environment.platform.machine |
| 90 | ? gt("detected", { $context: "machine kind detected automatically" }) |
| 91 | : gt("default", { $context: "machine kind used when none is detected" })} |
| 92 | </span> |
| 93 | ) : null} |
| 94 | </span> |
| 95 | </MenuRadioItem> |
| 96 | ))} |
| 97 | </MenuRadioGroup> |
| 98 | </MenuSubPopup> |
| 99 | </MenuSub> |
| 100 | ); |
| 101 | } |