Skip to content

Commit b304533

Browse files
refactor(web): host presentation and behavior come from client definitions
Web branched on the source control kind for host names, icons, PR vs MR, checkout commands, author profile links, the Forgejo review rule, change request URLs, the clone and publish pickers, and Settings icons. ThreadStatusIndicators read the host off a link with a nested ternary over URL substrings. All of these now read from `sourceControlClients`. Stack merge copy no longer names GitHub for every host: the confirmation, the success toast, the "GitHub stack" tooltip, and the truncated-review note all name the change request's own host. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent efcc177 commit b304533

19 files changed

Lines changed: 228 additions & 516 deletions

‎apps/web/src/components/CommandPalette.tsx‎

Lines changed: 42 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@ import {
1414
getNewProjectGitHubTarget,
1515
getNewProjectPathPreview,
1616
normalizePastedCloneUrl,
17+
addProjectRemoteSourceLabel,
18+
addProjectRemoteSourcePathHint,
19+
addProjectRemoteSourceProvider,
20+
buildAddProjectRemoteSourceReadiness,
21+
sortAddProjectProviderSources,
22+
type AddProjectRemoteSource,
23+
type AddProjectRemoteSourceReadiness,
1724
} from "@t3tools/client-runtime/operations/projects";
25+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
1826
import { connectionStatusText } from "@t3tools/client-runtime/connection";
1927
import { threadSearchMatchKey } from "@t3tools/client-runtime/state/thread-search";
2028
import { resolveThreadReferenceCopyTarget } from "@t3tools/shared/threadReference";
@@ -187,14 +195,8 @@ import {
187195
CommandPaletteVirtualizedResults,
188196
scrollCommandPaletteRowIntoView,
189197
} from "./CommandPaletteResults";
190-
import {
191-
AzureDevOpsIcon,
192-
BitbucketIcon,
193-
GitCafeIcon,
194-
GitHubIcon,
195-
GitLabIcon,
196-
ForgejoIcon,
197-
} from "./Icons";
198+
import { GitHubIcon } from "./Icons";
199+
import { sourceControlIcon } from "~/sourceControlPresentation";
198200
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
199201
import { Checkbox } from "./ui/checkbox";
200202
import { ProjectFavicon } from "./ProjectFavicon";
@@ -257,15 +259,6 @@ interface AddProjectEnvironmentOption {
257259
readonly status: string;
258260
}
259261

260-
type AddProjectRemoteProviderKind =
261-
| "github"
262-
| "gitlab"
263-
| "forgejo"
264-
| "bitbucket"
265-
| "azure-devops"
266-
| "gitcafe";
267-
type AddProjectRemoteSource = AddProjectRemoteProviderKind | "url";
268-
269262
type AddProjectCloneFlow =
270263
| {
271264
readonly step: "repository";
@@ -281,83 +274,10 @@ type AddProjectCloneFlow =
281274
readonly remoteUrl: string;
282275
};
283276

284-
const REMOTE_PROJECT_SOURCES: ReadonlyArray<AddProjectRemoteSource> = [
285-
"url",
286-
"github",
287-
"gitlab",
288-
"forgejo",
289-
"bitbucket",
290-
"azure-devops",
291-
"gitcafe",
292-
];
293-
const REMOTE_PROJECT_PROVIDER_SOURCES: ReadonlyArray<AddProjectRemoteProviderKind> = [
294-
"github",
295-
"gitlab",
296-
"forgejo",
297-
"bitbucket",
298-
"azure-devops",
299-
"gitcafe",
300-
];
301-
302-
function remoteProjectSourceLabel(source: AddProjectRemoteSource): string {
303-
switch (source) {
304-
case "github":
305-
return "GitHub";
306-
case "forgejo":
307-
return "Forgejo / Gitea";
308-
case "gitlab":
309-
return "GitLab";
310-
case "bitbucket":
311-
return "Bitbucket";
312-
case "azure-devops":
313-
return "Azure DevOps";
314-
case "gitcafe":
315-
return "GitCafe";
316-
case "url":
317-
return "Git URL";
318-
}
319-
}
320-
321-
function remoteProjectSourcePathHint(source: AddProjectRemoteSource): string {
322-
switch (source) {
323-
case "forgejo":
324-
case "github":
325-
case "gitcafe":
326-
return "owner/repo";
327-
case "gitlab":
328-
return "group/project";
329-
case "bitbucket":
330-
return "workspace/repository";
331-
case "azure-devops":
332-
return "project/repository";
333-
case "url":
334-
return "URL";
335-
}
336-
}
337-
338-
function remoteProjectSourceProvider(
339-
source: AddProjectRemoteSource,
340-
): AddProjectRemoteProviderKind | null {
341-
return source === "url" ? null : source;
342-
}
343-
344277
function remoteProjectSourceIcon(source: AddProjectRemoteSource, className: string): ReactNode {
345-
switch (source) {
346-
case "github":
347-
return <GitHubIcon className={className} />;
348-
case "forgejo":
349-
return <ForgejoIcon className={className} />;
350-
case "gitlab":
351-
return <GitLabIcon className={className} />;
352-
case "bitbucket":
353-
return <BitbucketIcon className={className} />;
354-
case "azure-devops":
355-
return <AzureDevOpsIcon className={className} />;
356-
case "gitcafe":
357-
return <GitCafeIcon className={className} />;
358-
case "url":
359-
return <LinkIcon className={className} />;
360-
}
278+
if (source === "url") return <LinkIcon className={className} />;
279+
const Icon = sourceControlIcon(sourceControlClients.get(source));
280+
return <Icon className={className} />;
361281
}
362282

363283
function projectFaviconIcon(project: Project): ReactNode {
@@ -370,82 +290,26 @@ function remoteProjectInputPlaceholder(flow: AddProjectCloneFlow | null): string
370290
if (flow.source === "url") {
371291
return "Enter Git clone URL";
372292
}
373-
return `Enter ${remoteProjectSourceLabel(flow.source)} repository (${remoteProjectSourcePathHint(flow.source)})`;
374-
}
375-
376-
function sourceProviderKind(source: AddProjectRemoteSource): AddProjectRemoteProviderKind | null {
377-
return source === "url" ? null : source;
378-
}
379-
380-
function sortAddProjectProviderSources(
381-
readinessBySource: AddProjectRemoteSourceReadiness,
382-
): ReadonlyArray<AddProjectRemoteProviderKind> {
383-
return REMOTE_PROJECT_PROVIDER_SOURCES.toSorted((left, right) => {
384-
const leftReady = readinessBySource[left].ready;
385-
const rightReady = readinessBySource[right].ready;
386-
if (leftReady !== rightReady) {
387-
return leftReady ? -1 : 1;
388-
}
389-
return remoteProjectSourceLabel(left).localeCompare(remoteProjectSourceLabel(right));
390-
});
293+
return `Enter ${addProjectRemoteSourceLabel(flow.source)} repository (${addProjectRemoteSourcePathHint(flow.source)})`;
391294
}
392295

393-
type AddProjectRemoteSourceReadiness = Record<
394-
AddProjectRemoteSource,
395-
{ readonly ready: boolean; readonly hint: string | null }
396-
>;
397-
398-
function buildAddProjectRemoteSourceReadiness(
296+
/** The palette's readiness, pointing at Settings by its menu path. */
297+
function buildPaletteRemoteSourceReadiness(
399298
discovery: SourceControlDiscoveryResult | null,
400299
): AddProjectRemoteSourceReadiness {
401-
const unavailable = {
402-
ready: false,
403-
hint: "Provider status unavailable. Open Settings -> Source Control and rescan.",
404-
} as const;
405-
const defaultReadiness: AddProjectRemoteSourceReadiness = {
406-
url: { ready: true, hint: null },
407-
github: unavailable,
408-
gitlab: unavailable,
409-
forgejo: unavailable,
410-
bitbucket: unavailable,
411-
"azure-devops": unavailable,
412-
gitcafe: unavailable,
300+
const readiness = buildAddProjectRemoteSourceReadiness(discovery);
301+
return (source) => {
302+
const entry = readiness(source);
303+
return entry.hint === null
304+
? entry
305+
: {
306+
...entry,
307+
hint: entry.hint.replace(
308+
"Open Source Control settings",
309+
"Open Settings -> Source Control",
310+
),
311+
};
413312
};
414-
415-
if (!discovery) {
416-
return defaultReadiness;
417-
}
418-
419-
const providerByKind = new Map(
420-
discovery.sourceControlProviders.map((provider) => [provider.kind, provider]),
421-
);
422-
const readiness = { ...defaultReadiness };
423-
424-
for (const source of REMOTE_PROJECT_SOURCES) {
425-
const kind = sourceProviderKind(source);
426-
if (!kind) continue;
427-
const provider = providerByKind.get(SourceControlProviderKind.make(kind));
428-
if (!provider) {
429-
readiness[source] = unavailable;
430-
continue;
431-
}
432-
if (provider.status !== "available") {
433-
readiness[source] = { ready: false, hint: provider.installHint };
434-
continue;
435-
}
436-
if (provider.auth.status === "unauthenticated") {
437-
readiness[source] = {
438-
ready: false,
439-
hint:
440-
Option.getOrNull(provider.auth.detail) ??
441-
`${provider.label} is not authenticated. Open Settings -> Source Control for setup guidance.`,
442-
};
443-
continue;
444-
}
445-
readiness[source] = { ready: true, hint: null };
446-
}
447-
448-
return readiness;
449313
}
450314

451315
function errorMessage(error: unknown): string {
@@ -1673,13 +1537,13 @@ function OpenCommandPaletteDialog(props: {
16731537
];
16741538

16751539
for (const source of orderedSources) {
1676-
const label = remoteProjectSourceLabel(source);
1540+
const label = addProjectRemoteSourceLabel(source);
16771541
const title = source === "url" ? "Git URL" : `${label} repository`;
16781542
const description =
16791543
source === "url"
16801544
? "Clone from a remote URL"
1681-
: `Clone ${label} ${remoteProjectSourcePathHint(source)}`;
1682-
const readiness = readinessBySource[source];
1545+
: `Clone ${label} ${addProjectRemoteSourcePathHint(source)}`;
1546+
const readiness = readinessBySource(source);
16831547
const disabledHint = readiness.hint;
16841548

16851549
const titleTrailingContent = readiness.ready ? undefined : (
@@ -1767,7 +1631,7 @@ function OpenCommandPaletteDialog(props: {
17671631
addonIcon: <FolderPlusIcon className={ADDON_ICON_CLASS} />,
17681632
groups: buildAddProjectSourceGroups(
17691633
environmentId,
1770-
buildAddProjectRemoteSourceReadiness(
1634+
buildPaletteRemoteSourceReadiness(
17711635
browseEnvironmentId === environmentId ? sourceControlDiscovery.data : null,
17721636
),
17731637
),
@@ -2105,13 +1969,13 @@ function OpenCommandPaletteDialog(props: {
21051969
"repository",
21061970
"repo",
21071971
"git",
2108-
"github",
2109-
"gitlab",
2110-
"forgejo",
2111-
"bitbucket",
2112-
"azure",
2113-
"devops",
2114-
"gitcafe",
1972+
// Every host's name, spelled as a word: "azure devops" searches as `azure` and `devops`.
1973+
...sourceControlClients.definitions.flatMap((definition) =>
1974+
definition.pickerLabel
1975+
.toLowerCase()
1976+
.split(/[^a-z0-9]+/u)
1977+
.filter(Boolean),
1978+
),
21151979
"url",
21161980
"environment",
21171981
],
@@ -2356,7 +2220,7 @@ function OpenCommandPaletteDialog(props: {
23562220
currentView.groups[0]?.value === sourceSelectionViewValue
23572221
? buildAddProjectSourceGroups(
23582222
addProjectEnvironmentId,
2359-
buildAddProjectRemoteSourceReadiness(sourceControlDiscovery.data),
2223+
buildPaletteRemoteSourceReadiness(sourceControlDiscovery.data),
23602224
)
23612225
: currentView?.groups[0]?.value === "themes"
23622226
? changeThemeItem.groups
@@ -2606,7 +2470,7 @@ function OpenCommandPaletteDialog(props: {
26062470
return;
26072471
}
26082472

2609-
const provider = remoteProjectSourceProvider(addProjectCloneFlow.source);
2473+
const provider = addProjectRemoteSourceProvider(addProjectCloneFlow.source);
26102474
if (!provider) {
26112475
const destinationPath = getCloneDestinationPath(
26122476
getDefaultCloneParentPath(addProjectCloneFlow.environmentId),
@@ -2631,7 +2495,7 @@ function OpenCommandPaletteDialog(props: {
26312495
const lookupResult = await lookupRepository({
26322496
environmentId: addProjectCloneFlow.environmentId,
26332497
input: {
2634-
provider: SourceControlProviderKind.make(provider),
2498+
provider,
26352499
repository: rawRepository,
26362500
},
26372501
});

‎apps/web/src/components/GitActionsControl.logic.ts‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@ import type {
44
VcsStatusResult,
55
} from "@t3tools/contracts";
66
import { isTemporaryWorktreeBranch } from "@t3tools/shared/git";
7-
import {
8-
DEFAULT_CHANGE_REQUEST_TERMINOLOGY,
9-
getChangeRequestTerminology,
10-
type ChangeRequestTerminology,
11-
} from "../sourceControlPresentation";
7+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
8+
import type { ChangeRequestTerminology } from "@t3tools/client-runtime/source-control-clients";
129

1310
export type GitActionIconName = "commit" | "push" | "pr";
1411

@@ -68,9 +65,7 @@ export function resolveGitActionResultToastTiming(
6865
function resolveChangeRequestTerminology(
6966
gitStatus: VcsStatusResult | null,
7067
): ChangeRequestTerminology {
71-
return gitStatus?.sourceControlProvider
72-
? getChangeRequestTerminology(gitStatus.sourceControlProvider)
73-
: DEFAULT_CHANGE_REQUEST_TERMINOLOGY;
68+
return sourceControlClients.get(gitStatus?.sourceControlProvider?.kind).changeRequest;
7469
}
7570

7671
export function resolveGitActionProgressPresentation(input: {
@@ -129,7 +124,7 @@ export function buildGitActionProgressStages(input: {
129124
shouldPushBeforePr?: boolean;
130125
terminology?: ChangeRequestTerminology;
131126
}): string[] {
132-
const terminology = input.terminology ?? DEFAULT_CHANGE_REQUEST_TERMINOLOGY;
127+
const terminology = input.terminology ?? sourceControlClients.get(undefined).changeRequest;
133128
const branchStages = input.featureBranch ? ["Preparing feature ref..."] : [];
134129
const pushStage = input.pushTarget ? `Pushing to ${input.pushTarget}...` : "Pushing...";
135130
const prStages = [
@@ -406,7 +401,7 @@ export function resolveDefaultBranchActionDialogCopy(input: {
406401
}): DefaultBranchActionDialogCopy {
407402
const branchLabel = input.branchName;
408403
const suffix = ` on "${branchLabel}". You can continue on this ref or create a feature ref and run the same action there.`;
409-
const terminology = input.terminology ?? DEFAULT_CHANGE_REQUEST_TERMINOLOGY;
404+
const terminology = input.terminology ?? sourceControlClients.get(undefined).changeRequest;
410405

411406
if (input.action === "push" || input.action === "commit_push") {
412407
if (input.includesCommit) {

0 commit comments

Comments
 (0)