Skip to content

Commit dc032d7

Browse files
t3dotggclaude
andauthored
feat(web,mobile): Add project lists only GitHub until you turn other hosts on (#34978)
Co-authored-by: Claude Fable 5.2 <[email protected]>
1 parent 2de3370 commit dc032d7

9 files changed

Lines changed: 177 additions & 36 deletions

File tree

‎apps/mobile/src/features/projects/AddProjectScreen.tsx‎

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
parseAddProjectRemoteSource,
3131
resolveAddProjectPath,
3232
sortAddProjectProviderSources,
33+
type OfferedSourceControlProviders,
3334
type AddProjectRemoteSource,
3435
} from "@t3tools/client-runtime/operations/projects";
3536
import {
@@ -118,6 +119,7 @@ interface EnvironmentOption {
118119
readonly connectionError: string | null;
119120
readonly connectionErrorTraceId: string | null;
120121
readonly ghqCloneLayout: boolean;
122+
readonly offeredSourceControlProviders: OfferedSourceControlProviders | undefined;
121123
}
122124

123125
const environmentOptionOrder = Order.mapInput(
@@ -413,6 +415,7 @@ function useEnvironmentOptions(
413415
connectionError: runtime?.connectionError ?? null,
414416
connectionErrorTraceId: runtime?.connectionErrorTraceId ?? null,
415417
ghqCloneLayout: config?.settings.ghqCloneLayout === true,
418+
offeredSourceControlProviders: config?.settings.offeredSourceControlProviders,
416419
};
417420
});
418421
return Arr.sort(
@@ -649,24 +652,30 @@ export function AddProjectSourceScreen(props: { readonly environmentId?: string
649652
)
650653
}
651654
/>
652-
{(["url", ...sortAddProjectProviderSources(readiness)] as AddProjectRemoteSource[]).map(
653-
(candidate) => (
654-
<SourceControlRow
655-
key={candidate}
656-
source={candidate}
657-
selectedEnvironmentId={selectedEnvironment.environmentId}
658-
ready={canCloneProject && readiness(candidate).ready}
659-
hint={
660-
!canCloneProject
661-
? "This connection cannot clone projects."
662-
: readiness(candidate).ready
663-
? addProjectRemoteSourcePathHint(candidate)
664-
: (readiness(candidate).hint ?? "")
665-
}
666-
isFirst={false}
667-
/>
668-
),
669-
)}
655+
{(
656+
[
657+
"url",
658+
...sortAddProjectProviderSources(
659+
readiness,
660+
selectedEnvironment.offeredSourceControlProviders,
661+
),
662+
] as AddProjectRemoteSource[]
663+
).map((candidate) => (
664+
<SourceControlRow
665+
key={candidate}
666+
source={candidate}
667+
selectedEnvironmentId={selectedEnvironment.environmentId}
668+
ready={canCloneProject && readiness(candidate).ready}
669+
hint={
670+
!canCloneProject
671+
? "This connection cannot clone projects."
672+
: readiness(candidate).ready
673+
? addProjectRemoteSourcePathHint(candidate)
674+
: (readiness(candidate).hint ?? "")
675+
}
676+
isFirst={false}
677+
/>
678+
))}
670679
</ListSection>
671680
{discoveryState.isPending ? (
672681
<AppActivityIndicator colorClassName="accent-icon-muted" />
@@ -1055,7 +1064,10 @@ export function AddProjectNewScreen(props: { readonly environmentId?: string | s
10551064
input: {},
10561065
}),
10571066
);
1058-
const publishTargets = getNewProjectPublishTargets(discoveryState.data);
1067+
const publishTargets = getNewProjectPublishTargets(
1068+
discoveryState.data,
1069+
environment?.offeredSourceControlProviders,
1070+
);
10591071
const [name, setName] = useState("");
10601072
const [publishes, setPublishes] = useState(false);
10611073
const [publishKind, setPublishKind] = useState<SourceControlProviderKind | null>(null);

‎apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ import {
4343
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
4444
import { AutoSettleSettingsRows } from "./ThreadSettingsSections";
4545
import { supportsSharedSettingsSync } from "@t3tools/client-runtime/state/shared-settings";
46+
import { isSourceControlProviderOffered } from "@t3tools/client-runtime/operations/projects";
47+
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
4648

4749
type SettingsPage = "threads" | "source-control" | "worktrees" | "maintenance";
4850

@@ -406,6 +408,31 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
406408
canWrite={(environmentId) => writableEnvironments.has(environmentId)}
407409
/>
408410
)}
411+
{projectSelected ? null : (
412+
<SettingsSection title="Project sources">
413+
{sourceControlClients.definitions.map((definition) => {
414+
const offered = displayTargets.map((target) =>
415+
isSourceControlProviderOffered(
416+
target.settings.offeredSourceControlProviders,
417+
definition.kind,
418+
),
419+
);
420+
return (
421+
<SettingsSwitchRow
422+
key={definition.kind}
423+
label={definition.pickerLabel}
424+
value={
425+
offered.every((value) => value === offered[0]) ? offered[0]! : null
426+
}
427+
disabled={disabledFor("offeredSourceControlProviders")}
428+
onValueChange={(value) =>
429+
write({ offeredSourceControlProviders: { [definition.kind]: value } })
430+
}
431+
/>
432+
);
433+
})}
434+
</SettingsSection>
435+
)}
409436
<SettingsSection title="Pull requests">
410437
<SettingsSwitchRow
411438
icon={PullRequestGlyph.merged}

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,10 @@ function OpenCommandPaletteDialog(props: {
10171017
environments.find((environment) => environment.environmentId === environmentId)?.serverConfig
10181018
?.newProjectsRoot ?? null;
10191019

1020+
const offeredProvidersFor = (environmentId: EnvironmentId | null) =>
1021+
environments.find((environment) => environment.environmentId === environmentId)?.serverConfig
1022+
?.settings.offeredSourceControlProviders;
1023+
10201024
const startNewProject = (
10211025
environmentId: EnvironmentId,
10221026
sourcesEnvironmentId: EnvironmentId | null,
@@ -1073,7 +1077,7 @@ function OpenCommandPaletteDialog(props: {
10731077

10741078
const orderedSources: ReadonlyArray<AddProjectRemoteSource> = [
10751079
"url",
1076-
...sortAddProjectProviderSources(readinessBySource),
1080+
...sortAddProjectProviderSources(readinessBySource, offeredProvidersFor(environmentId)),
10771081
];
10781082

10791083
for (const source of orderedSources) {
@@ -2001,7 +2005,12 @@ function OpenCommandPaletteDialog(props: {
20012005
};
20022006

20032007
const newProjectPublishTargets =
2004-
newProjectFlow === null ? [] : getNewProjectPublishTargets(sourceControlDiscovery.data ?? null);
2008+
newProjectFlow === null
2009+
? []
2010+
: getNewProjectPublishTargets(
2011+
sourceControlDiscovery.data ?? null,
2012+
offeredProvidersFor(newProjectFlow.environmentId),
2013+
);
20052014
const newProjectPublishTarget = getNewProjectPublishTarget(
20062015
newProjectPublishTargets,
20072016
newProjectPublishKind,

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ import {
119119
THREAD_DETAILS_PANEL_SPLIT_SEPARATOR_CLASS,
120120
} from "./chat/threadDetailsPanelStyles";
121121
import { getSourceControlPresentation, sourceControlIcon } from "~/sourceControlPresentation";
122+
import {
123+
isSourceControlProviderOffered,
124+
type OfferedSourceControlProviders,
125+
} from "@t3tools/client-runtime/operations/projects";
122126
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
123127
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
124128
import { useOpenLink } from "~/browser/useOpenLink";
@@ -437,6 +441,7 @@ interface PublishRepositoryDialogProps {
437441
readonly environmentId: ScopedThreadRef["environmentId"] | null;
438442
readonly threadRef: ScopedThreadRef | null;
439443
readonly gitCwd: string;
444+
readonly offeredProviders: OfferedSourceControlProviders | undefined;
440445
}
441446

442447
function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
@@ -484,10 +489,13 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
484489
);
485490
const publishProviderReadiness = (provider: SourceControlProviderKind) =>
486491
publishReadinessByProvider.get(provider) ?? { ready: false, hint: null };
487-
const hasReadyPublishProvider = PUBLISH_PROVIDER_OPTIONS.some(
492+
const offeredPublishProviderOptions = PUBLISH_PROVIDER_OPTIONS.filter((option) =>
493+
isSourceControlProviderOffered(props.offeredProviders, option.value),
494+
);
495+
const hasReadyPublishProvider = offeredPublishProviderOptions.some(
488496
(option) => publishProviderReadiness(option.value).ready,
489497
);
490-
const sortedPublishProviderOptions = PUBLISH_PROVIDER_OPTIONS.toSorted((left, right) => {
498+
const sortedPublishProviderOptions = offeredPublishProviderOptions.toSorted((left, right) => {
491499
const leftReady = publishProviderReadiness(left.value).ready;
492500
const rightReady = publishProviderReadiness(right.value).ready;
493501
if (leftReady !== rightReady) {
@@ -498,12 +506,16 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
498506
const firstReadyPublishProvider = sortedPublishProviderOptions.find(
499507
(option) => publishProviderReadiness(option.value).ready,
500508
)?.value;
501-
const publishProvider =
502-
selectedPublishProvider !== null && publishProviderReadiness(selectedPublishProvider).ready
509+
// The dialog stays mounted, so a host turned off after it was picked must not stay selected.
510+
const offeredSelection =
511+
selectedPublishProvider !== null &&
512+
isSourceControlProviderOffered(props.offeredProviders, selectedPublishProvider)
503513
? selectedPublishProvider
504-
: (firstReadyPublishProvider ??
505-
selectedPublishProvider ??
506-
sourceControlClients.get(undefined).kind);
514+
: null;
515+
const publishProvider =
516+
offeredSelection !== null && publishProviderReadiness(offeredSelection).ready
517+
? offeredSelection
518+
: (firstReadyPublishProvider ?? offeredSelection ?? sourceControlClients.get(undefined).kind);
507519
const selectedPublishProviderReadiness = publishProviderReadiness(publishProvider);
508520
const publishAccount = publishAccountByProvider.get(publishProvider) ?? null;
509521
const publishRepositoryPrefill = publishAccount ? `${publishAccount}/` : "";
@@ -530,6 +542,7 @@ function PublishRepositoryDialog(props: PublishRepositoryDialogProps) {
530542
const publishRepositoryName = publishRepositoryParts.slice(1).join("/").trim();
531543
const canSubmitPublishRepository =
532544
publishRepositoryAction.isAllowed &&
545+
hasReadyPublishProvider &&
533546
selectedPublishProviderReadiness.ready &&
534547
!publishRepositoryAction.isPending &&
535548
publishRepositoryOwner.length > 0 &&
@@ -1936,6 +1949,7 @@ export default function GitActionsControl({
19361949
environmentId={activeEnvironmentId}
19371950
threadRef={activeThreadRef}
19381951
gitCwd={gitCwd}
1952+
offeredProviders={serverConfig?.settings.offeredSourceControlProviders}
19391953
/>
19401954
) : null}
19411955

‎apps/web/src/components/settings/SourceControlSettings.tsx‎

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { RefreshIcon } from "~/components/ui/refresh-icon";
22
import { ChevronDownIcon } from "lucide-react";
3+
import { useAtomValue } from "@effect/atom-react";
34
import * as Option from "effect/Option";
45
import { useState, type ReactNode } from "react";
56
import type {
@@ -13,7 +14,9 @@ import { useSettingsScope } from "./SettingsScopeContext";
1314
import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings";
1415
import { cn } from "../../lib/utils";
1516
import { useEnvironmentQuery } from "../../state/query";
17+
import { serverEnvironment } from "../../state/server";
1618
import { sourceControlEnvironment } from "../../state/sourceControl";
19+
import { useAtomCommand } from "../../state/use-atom-command";
1720
import { Badge } from "../ui/badge";
1821
import { Button } from "../ui/button";
1922
import { Collapsible, CollapsibleContent } from "../ui/collapsible";
@@ -44,6 +47,7 @@ import {
4447
} from "./settingsLayout";
4548
import { searchableSetting, sourceControlHostSettingsSearchId } from "./settingsSearch";
4649
import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons";
50+
import { isSourceControlProviderOffered } from "@t3tools/client-runtime/operations/projects";
4751
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
4852
import { sourceControlIcon } from "~/sourceControlPresentation";
4953

@@ -207,15 +211,19 @@ function itemSummary({
207211

208212
function DiscoveryItemRow({
209213
item,
214+
offered,
210215
children,
211216
}: {
212217
readonly item: VcsDiscoveryItem | SourceControlProviderDiscoveryItem;
218+
/** A provider's switch chooses whether the project pickers offer it; a VCS switch only reports. */
219+
readonly offered?: {
220+
readonly checked: boolean;
221+
readonly disabled: boolean;
222+
readonly onChange: (checked: boolean) => void;
223+
};
213224
readonly children?: ReactNode;
214225
}) {
215226
const version = optionLabel(item.version);
216-
const enabled = isProviderDiscoveryItem(item)
217-
? item.status === "available" && item.auth.status === "authenticated"
218-
: item.status === "available" && item.implemented;
219227
const auth = isProviderDiscoveryItem(item) ? item.auth : null;
220228
const authStatus = auth ? authPresentation(auth) : null;
221229
const authAccount = auth ? optionLabel(auth.account) : null;
@@ -272,8 +280,26 @@ function DiscoveryItemRow({
272280
/>
273281
</Button>
274282
) : null}
275-
{!isVcsNotReady(item) ? (
276-
<Switch checked={enabled} disabled aria-label={`${item.label} availability`} />
283+
{offered ? (
284+
<Tooltip>
285+
<TooltipTrigger
286+
render={
287+
<Switch
288+
checked={offered.checked}
289+
disabled={offered.disabled}
290+
onCheckedChange={offered.onChange}
291+
aria-label={`Offer ${item.label} when adding or publishing a project`}
292+
/>
293+
}
294+
/>
295+
<TooltipPopup side="top">Offer when adding or publishing a project</TooltipPopup>
296+
</Tooltip>
297+
) : !isVcsNotReady(item) ? (
298+
<Switch
299+
checked={item.status === "available"}
300+
disabled
301+
aria-label={`${item.label} availability`}
302+
/>
277303
) : null}
278304
</div>
279305
</div>
@@ -388,6 +414,13 @@ export function SourceControlSettingsPanel() {
388414
const handleScan = () => {
389415
discovery.refresh();
390416
};
417+
const offeredProviders = environment?.serverConfig?.settings.offeredSourceControlProviders;
418+
const updateSettings = useAtomCommand(serverEnvironment.updateSettings, {
419+
label: "save source control providers",
420+
});
421+
const canUpdateSettings = useAtomValue(
422+
serverEnvironment.updateSettings.permissionAtom(environmentId),
423+
);
391424
const hostSettingsPanel = (item: SourceControlProviderDiscoveryItem) => {
392425
const definition = sourceControlClients.find(item.kind);
393426
if (!definition?.settings || environmentId === null) return undefined;
@@ -506,7 +539,21 @@ export function SourceControlSettingsPanel() {
506539
headerAction={hasVersionControlSystems ? null : scanButton}
507540
>
508541
{result.sourceControlProviders.map((item) => (
509-
<DiscoveryItemRow key={`provider:${item.kind}`} item={item}>
542+
<DiscoveryItemRow
543+
key={`provider:${item.kind}`}
544+
item={item}
545+
offered={{
546+
checked: isSourceControlProviderOffered(offeredProviders, item.kind),
547+
disabled: !canUpdateSettings,
548+
onChange: (checked) =>
549+
void updateSettings({
550+
environmentId,
551+
input: {
552+
patch: { offeredSourceControlProviders: { [item.kind]: checked } },
553+
},
554+
}),
555+
}}
556+
>
510557
{hostSettingsPanel(item)}
511558
</DiscoveryItemRow>
512559
))}

‎docs/user/source-control.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,9 @@ publish it. If Git has no name or email on that machine, the project is created
155155
first commit.
156156

157157
Use **Add Project** in the command palette (`Cmd/Ctrl+K`) to clone a repository. Choose a hosting
158-
provider or paste a Git URL, then choose where to save it. A branch or file page copied from GitHub,
158+
provider or paste a Git URL, then choose where to save it. Only GitHub is listed at first. To list
159+
another provider here and in **Publish Repository**, turn on its switch under
160+
**Settings → Source control**. A branch or file page copied from GitHub,
159161
GitLab, GitCafe, Codeberg or Bitbucket also works: T3 Code clones that repository's default branch.
160162
On other hosts, paste the repository's clone URL. The project opens right away while the
161163
clone runs in the background: you can write your first prompt, and sending waits until the files

‎packages/client-runtime/src/operations/projects.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ import {
1212
getDefaultCloneUrl,
1313
githubIncompleteOwnerRepositoryMessage,
1414
normalizePastedCloneUrl,
15+
sortAddProjectProviderSources,
1516
} from "./projects.ts";
1617
import type { EnvironmentProject } from "../state/models.ts";
1718

1819
describe("add project shared logic", () => {
20+
it("offers only GitHub until other hosts are turned on", () => {
21+
const ready = () => ({ ready: true, hint: null });
22+
expect(sortAddProjectProviderSources(ready, {})).toEqual(["github"]);
23+
expect(sortAddProjectProviderSources(ready, { gitlab: true, github: false })).toEqual([
24+
"gitlab",
25+
]);
26+
});
27+
1928
it("asks for a repository name when GitHub input is only an owner path", () => {
2029
const github = SourceControlProviderKind.make("github");
2130
expect(githubIncompleteOwnerRepositoryMessage(github, "pingdotgg/")).toBe(

0 commit comments

Comments
 (0)