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";
9import { T, useGT } from "gt-react";
10
11import { sourceControlIcon } from "~/sourceControlPresentation";
12import { ITEM_ICON_CLASS } from "./CommandPalette.logic";
13import { CommandPaletteTitleIcon } from "./CommandPaletteResults";
14import { Button } from "./ui/button";
15import { Kbd, KbdGroup } from "./ui/kbd";
16import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "./ui/select";
17import { SharedTooltipTrigger } from "./ui/shared-tooltip";
18
19export function remoteProjectSourceIcon(
20 source: AddProjectRemoteSource,
21 className: string,
22): ReactNode {
23 if (source === "url") return <LinkIcon className={className} />;
24 const Icon = sourceControlIcon(sourceControlClients.get(source));
25 return <Icon className={className} />;
26}
27
28export function sourceControlHostIcon(
29 definition: NewProjectPublishTarget["definition"],
30 className: string,
31): ReactNode {
32 const Icon = sourceControlIcon(definition);
33 return <Icon className={className} />;
34}
35
36/** The input's trailing submit button for the add-project, clone, and new-project flows. */
37export function CommandPaletteSubmitButton(props: {
38 readonly id: string;
39 readonly label: ReactNode;
40 readonly shortcutLabel: string;
41 readonly ariaLabel: string;
42 readonly tooltip: ReactNode;
43 readonly disabled: boolean;
44 readonly onSubmit: () => void;
45}) {
46 return (
47 <SharedTooltipTrigger
48 render={
49 <Button
50 id={props.id}
51 variant="outline"
52 size="xs"
53 className="absolute inset-e-2.5 top-1/2 -translate-y-1/2"
54 aria-label={props.ariaLabel}
55 disabled={props.disabled}
56 onMouseDown={(event) => {
57 event.preventDefault();
58 }}
59 onClick={props.onSubmit}
60 />
61 }
62 label={props.tooltip}
63 >
64 <span>{props.label}</span>
65 <KbdGroup className="pointer-events-none -me-0.5">
66 <Kbd>{props.shortcutLabel}</Kbd>
67 </KbdGroup>
68 </SharedTooltipTrigger>
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 gt = useGT();
84 const [open, setOpen] = useState(false);
85 return (
86 <span
87 className="flex"
88 onClick={(event) => {
89 event.stopPropagation();
90 // React bubbles the popup's clicks here through its portal; only the
91 // trigger opens the picker.
92 if (!event.currentTarget.contains(event.target as Node)) return;
93 if (!props.disabled) setOpen(true);
94 }}
95 >
96 <Select
97 disabled={props.disabled}
98 open={open}
99 onOpenChange={setOpen}
100 value={props.value}
101 onValueChange={(kind) => {
102 if (kind !== null) props.onValueChange(kind);
103 }}
104 >
105 <SelectTrigger size="xs" variant="ghost" aria-label={gt("Host for the new repository")}>
106 <SelectValue>
107 {(kind: SourceControlProviderKind) => sourceControlClients.get(kind).label}
108 </SelectValue>
109 </SelectTrigger>
110 <SelectPopup align="end" alignItemWithTrigger={false}>
111 {props.targets.map((target) => (
112 <SelectItem key={target.definition.kind} hideIndicator value={target.definition.kind}>
113 <span className="inline-flex items-center gap-1.5">
114 {sourceControlHostIcon(target.definition, "size-3.5")}
115 {target.definition.label}
116 </span>
117 </SelectItem>
118 ))}
119 </SelectPopup>
120 </Select>
121 </span>
122 );
123}
124
125export function NewProjectSummary(props: {
126 readonly name: string;
127 readonly pathPreview: string;
128 readonly projectsRoot: string | null;
129 readonly environmentLabel: string | null;
130}) {
131 const gt = useGT();
132 const environment = props.environmentLabel;
133 return (
134 <div className="p-2 pb-0">
135 <div className="flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5">
136 <CommandPaletteTitleIcon>
137 <FolderGit2Icon className={ITEM_ICON_CLASS} />
138 </CommandPaletteTitleIcon>
139 <span className="flex min-w-0 flex-1 flex-col">
140 <span className="truncate text-foreground text-sm">
141 {props.name.length > 0 ? props.name : gt("New project")}
142 </span>
143 <span className="truncate text-muted-foreground/85 text-xs">
144 {props.name.length > 0
145 ? environment === null
146 ? gt("Creates {path}", { path: props.pathPreview })
147 : gt("Creates {path} on {environment}", { path: props.pathPreview, environment })
148 : environment === null
149 ? gt("Goes in {root}", { root: String(props.projectsRoot) })
150 : gt("Goes in {root} on {environment}", {
151 root: String(props.projectsRoot),
152 environment,
153 })}
154 </span>
155 </span>
156 </div>
157 </div>
158 );
159}
160
161export function RemoteRepositorySummary(props: {
162 readonly source: AddProjectRemoteSource;
163 readonly title: string;
164 readonly description: string;
165}) {
166 return (
167 <div className="shrink-0 p-2 pb-0">
168 <div className="px-2 py-1.5 font-medium text-muted-foreground text-xs">
169 <T>Repository</T>
170 </div>
171 <div className="flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5">
172 <CommandPaletteTitleIcon>
173 {remoteProjectSourceIcon(props.source, ITEM_ICON_CLASS)}
174 </CommandPaletteTitleIcon>
175 <span className="flex min-w-0 flex-1 flex-col">
176 <span className="truncate text-foreground text-sm">{props.title}</span>
177 <span className="truncate text-muted-foreground/85 text-xs">{props.description}</span>
178 </span>
179 </div>
180 </div>
181 );
182}