|
1 | 1 | import { resolveEnvironmentMachineKind } from "@t3tools/contracts"; |
| 2 | +import { fileBasename } from "@t3tools/shared/path"; |
2 | 3 | import { useLocation } from "@tanstack/react-router"; |
3 | | -import { CheckIcon, ChevronDownIcon, LayersIcon } from "lucide-react"; |
| 4 | +import { CheckIcon, ChevronDownIcon, FolderIcon, LayersIcon } from "lucide-react"; |
4 | 5 | import { Fragment, useState, type ReactNode } from "react"; |
5 | 6 |
|
6 | 7 | import type { SidebarProjectSnapshot } from "../../sidebarProjectGrouping"; |
@@ -29,13 +30,17 @@ import { |
29 | 30 | import { useOptionalSettingsScope } from "./SettingsScopeContext"; |
30 | 31 | import { resolveSettingsScope, type SettingsScopeSearch } from "./settingsScope"; |
31 | 32 | import { |
| 33 | + ALL_CHECKOUTS_VALUE, |
32 | 34 | ALL_ENVIRONMENTS_VALUE, |
33 | 35 | ALL_PROJECTS_VALUE, |
34 | 36 | environmentAxisValue, |
35 | 37 | projectAxisValue, |
36 | 38 | projectScopeMenuGroups, |
| 39 | + selectCheckoutAxis, |
37 | 40 | selectEnvironmentAxis, |
38 | 41 | selectProjectAxis, |
| 42 | + settingsScopeCheckoutChoices, |
| 43 | + settingsScopeCheckoutLabel, |
39 | 44 | settingsScopeEnvironmentAddress, |
40 | 45 | settingsScopeEnvironmentLabel, |
41 | 46 | settingsScopeEnvironmentLabels, |
@@ -86,6 +91,7 @@ export function SettingsScopeSentence() { |
86 | 91 | </span> |
87 | 92 | <EnvironmentScopeMenu {...props} /> |
88 | 93 | </span> |
| 94 | + <CheckoutScopeMenu {...props} /> |
89 | 95 | </p> |
90 | 96 | ); |
91 | 97 | } |
@@ -303,6 +309,45 @@ function EnvironmentScopeMenu({ |
303 | 309 | ); |
304 | 310 | } |
305 | 311 |
|
| 312 | +function CheckoutScopeMenu({ value, groups, onChange }: SettingsScopeMenuProps) { |
| 313 | + const group = groups.find((candidate) => candidate.projectKey === value.project); |
| 314 | + const checkouts = group ? settingsScopeCheckoutChoices(group, value) : []; |
| 315 | + if (checkouts.length === 0) return null; |
| 316 | + const selected = checkouts.find((member) => member.physicalProjectKey === value.checkout); |
| 317 | + return ( |
| 318 | + <span className="flex min-w-0 items-center gap-1.5"> |
| 319 | + <span className="shrink-0">in</span> |
| 320 | + <ScopeMenu |
| 321 | + ariaLabel="Checkout scope" |
| 322 | + icon={<FolderIcon aria-hidden className="size-3.5 shrink-0" />} |
| 323 | + label={ |
| 324 | + selected |
| 325 | + ? settingsScopeCheckoutLabel(selected, checkouts) |
| 326 | + : value.checkout |
| 327 | + ? "Unavailable checkout" |
| 328 | + : "All checkouts" |
| 329 | + } |
| 330 | + value={value.checkout ?? ALL_CHECKOUTS_VALUE} |
| 331 | + onChange={(next) => |
| 332 | + onChange( |
| 333 | + selectCheckoutAxis( |
| 334 | + value, |
| 335 | + checkouts.find((member) => member.physicalProjectKey === next) ?? null, |
| 336 | + ), |
| 337 | + ) |
| 338 | + } |
| 339 | + searchLabel="Search checkouts" |
| 340 | + allOption={{ value: ALL_CHECKOUTS_VALUE, label: "All checkouts" }} |
| 341 | + options={checkouts.map((member) => ({ |
| 342 | + value: member.physicalProjectKey, |
| 343 | + label: fileBasename(member.workspaceRoot), |
| 344 | + secondary: member.workspaceRoot, |
| 345 | + }))} |
| 346 | + /> |
| 347 | + </span> |
| 348 | + ); |
| 349 | +} |
| 350 | + |
306 | 351 | function ProjectScopeMenu({ value, groups, environments, onChange }: SettingsScopeMenuProps) { |
307 | 352 | const selected = groups.find((group) => group.projectKey === value.project); |
308 | 353 | const projects = projectScopeMenuGroups(groups, value).map((group) => ({ |
|
0 commit comments