Open History to see the last commit
1import {
2 type AddProjectRemoteSource,
3 type NewProjectPublishTarget,
4} from "@t3tools/client-runtime/operations/projects";
5import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
6import type { SourceControlProviderKind } from "@t3tools/contracts";
7import { FolderGit2Icon, LinkIcon } from "lucide-react";
8import { type ReactNode, useState } from "react";
9
10import { sourceControlIcon } from "~/sourceControlPresentation";
11import { ITEM_ICON_CLASS } from "./CommandPalette.logic";
12import { CommandPaletteTitleIcon } from "./CommandPaletteResults";
13import { Button } from "./ui/button";
14import { Kbd, KbdGroup } from "./ui/kbd";
15import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "./ui/select";
16import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
17
18export function remoteProjectSourceIcon(
19 source: AddProjectRemoteSource,
20 className: string,
21): ReactNode {
22 if (source === "url") return <LinkIcon className={className} />;
23 const Icon = sourceControlIcon(sourceControlClients.get(source));
24 return <Icon className={className} />;
25}
26
27export function sourceControlHostIcon(
28 definition: NewProjectPublishTarget["definition"],
29 className: string,
30): ReactNode {
31 const Icon = sourceControlIcon(definition);
32 return <Icon className={className} />;
33}
34
35/** The input's trailing submit button for the add-project, clone, and new-project flows. */
36export function CommandPaletteSubmitButton(props: {
37 readonly label: ReactNode;
38 readonly shortcutLabel: string;
39 readonly ariaLabel: string;
40 readonly tooltip: ReactNode;
41 readonly disabled: boolean;
42 readonly onSubmit: () => void;
43}) {
44 return (
45 <Tooltip>
46 <TooltipTrigger
47 render={
48 <Button
49 variant="outline"
50 size="xs"
51 tabIndex={-1}
52 className="absolute inset-e-2.5 top-1/2 -translate-y-1/2"
53 aria-label={props.ariaLabel}
54 disabled={props.disabled}
55 onMouseDown={(event) => {
56 event.preventDefault();
57 }}
58 onClick={props.onSubmit}
59 />
60 }
61 >
62 <span>{props.label}</span>
63 <KbdGroup className="pointer-events-none -me-0.5">
64 <Kbd>{props.shortcutLabel}</Kbd>
65 </KbdGroup>
66 </TooltipTrigger>
67 <TooltipPopup side="top">{props.tooltip}</TooltipPopup>
68 </Tooltip>
69 );
70}
71
72/**
73 * Picks which host a new project publishes to. The row it sits in toggles on click, so the
74 * picker keeps its clicks to itself. The row also cancels pointerdown to keep focus in the
75 * input, which drops the mousedown Select opens on, so the picker opens on click instead.
76 */
77export function NewProjectPublishHostPicker(props: {
78 readonly disabled: boolean;
79 readonly targets: ReadonlyArray<NewProjectPublishTarget>;
80 readonly value: SourceControlProviderKind;
81 readonly onValueChange: (kind: SourceControlProviderKind) => void;
82}) {
83 const [open, setOpen] = useState(false);
84 return (
85 <span
86 className="flex"
87 onClick={(event) => {
88 event.stopPropagation();
89 // React bubbles the popup's clicks here through its portal; only the
90 // trigger opens the picker.
91 if (!event.currentTarget.contains(event.target as Node)) return;
92 if (!props.disabled) setOpen(true);
93 }}
94 >
95 <Select
96 disabled={props.disabled}
97 open={open}
98 onOpenChange={setOpen}
99 value={props.value}
100 onValueChange={(kind) => {
101 if (kind !== null) props.onValueChange(kind);
102 }}
103 >
104 <SelectTrigger size="xs" variant="ghost" aria-label="Host for the new repository">
105 <SelectValue>
106 {(kind: SourceControlProviderKind) => sourceControlClients.get(kind).label}
107 </SelectValue>
108 </SelectTrigger>
109 <SelectPopup align="end" alignItemWithTrigger={false}>
110 {props.targets.map((target) => (
111 <SelectItem key={target.definition.kind} hideIndicator value={target.definition.kind}>
112 <span className="inline-flex items-center gap-1.5">
113 {sourceControlHostIcon(target.definition, "size-3.5")}
114 {target.definition.label}
115 </span>
116 </SelectItem>
117 ))}
118 </SelectPopup>
119 </Select>
120 </span>
121 );
122}
123
124export function NewProjectSummary(props: {
125 readonly name: string;
126 readonly pathPreview: string;
127 readonly projectsRoot: string | null;
128 readonly environmentLabel: string | null;
129}) {
130 return (
131 <div className="p-2 pb-0">
132 <div className="flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5">
133 <CommandPaletteTitleIcon>
134 <FolderGit2Icon className={ITEM_ICON_CLASS} />
135 </CommandPaletteTitleIcon>
136 <span className="flex min-w-0 flex-1 flex-col">
137 <span className="truncate text-foreground text-sm">
138 {props.name.length > 0 ? props.name : "New project"}
139 </span>
140 <span className="truncate text-muted-foreground/85 text-xs">
141 {props.name.length > 0
142 ? `Creates ${props.pathPreview}`
143 : `Goes in ${props.projectsRoot}`}
144 {props.environmentLabel === null ? null : ` on ${props.environmentLabel}`}
145 </span>
146 </span>
147 </div>
148 </div>
149 );
150}
151
152export function RemoteRepositorySummary(props: {
153 readonly source: AddProjectRemoteSource;
154 readonly title: string;
155 readonly description: string;
156}) {
157 return (
158 <div className="shrink-0 p-2 pb-0">
159 <div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">Repository</div>
160 <div className="flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5">
161 <CommandPaletteTitleIcon>
162 {remoteProjectSourceIcon(props.source, ITEM_ICON_CLASS)}
163 </CommandPaletteTitleIcon>
164 <span className="flex min-w-0 flex-1 flex-col">
165 <span className="truncate text-foreground text-sm">{props.title}</span>
166 <span className="truncate text-muted-foreground/85 text-xs">{props.description}</span>
167 </span>
168 </div>
169 </div>
170 );
171}