11import { RefreshIcon } from "~/components/ui/refresh-icon" ;
22import { ChevronDownIcon } from "lucide-react" ;
3+ import { useAtomValue } from "@effect/atom-react" ;
34import * as Option from "effect/Option" ;
45import { useState , type ReactNode } from "react" ;
56import type {
@@ -13,7 +14,9 @@ import { useSettingsScope } from "./SettingsScopeContext";
1314import { ProjectDefaultsSettings } from "./ProjectDefaultsSettings" ;
1415import { cn } from "../../lib/utils" ;
1516import { useEnvironmentQuery } from "../../state/query" ;
17+ import { serverEnvironment } from "../../state/server" ;
1618import { sourceControlEnvironment } from "../../state/sourceControl" ;
19+ import { useAtomCommand } from "../../state/use-atom-command" ;
1720import { Badge } from "../ui/badge" ;
1821import { Button } from "../ui/button" ;
1922import { Collapsible , CollapsibleContent } from "../ui/collapsible" ;
@@ -44,6 +47,7 @@ import {
4447} from "./settingsLayout" ;
4548import { searchableSetting , sourceControlHostSettingsSearchId } from "./settingsSearch" ;
4649import { PullRequestGlyph } from "~/components/pullRequest/pullRequestIcons" ;
50+ import { isSourceControlProviderOffered } from "@t3tools/client-runtime/operations/projects" ;
4751import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients" ;
4852import { sourceControlIcon } from "~/sourceControlPresentation" ;
4953
@@ -207,15 +211,19 @@ function itemSummary({
207211
208212function 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 ) ) }
0 commit comments