1+ import { useEffect } from "react" ;
2+ import { useLocation } from "react-router-dom" ;
3+ import { useSystemConfig } from "@/hooks/queries/system-queries" ;
14import {
25 usePluginSlots ,
36 type PluginSettingsSectionSlot ,
@@ -8,15 +11,32 @@ import {
811 ResourceDetailConfigurationSection ,
912} from "@bb/shared-ui/resource-list" ;
1013
14+ const CONNECT_PLUGIN_ID = "connect" ;
15+ const CLOUD_AI_SECTION_ID = "cloud-ai" ;
16+
17+ function isSettingsSectionVisible (
18+ section : PluginSettingsSectionSlot ,
19+ cloudAiEnabled : boolean ,
20+ ) : boolean {
21+ return ! (
22+ section . pluginId === CONNECT_PLUGIN_ID &&
23+ section . id === CLOUD_AI_SECTION_ID &&
24+ ! cloudAiEnabled
25+ ) ;
26+ }
27+
1128/**
1229 * Plugin `settingsSection` slot mounts, rendered on that plugin's canonical
1330 * Plugins detail page below the host-rendered declarative form.
1431 * Each section is contained in its own per-plugin error boundary.
1532 */
1633export function PluginSettingsSections ( { pluginId } : { pluginId : string } ) {
1734 const { settingsSections } = usePluginSlots ( ) ;
35+ const cloudAiEnabled = useSystemConfig ( ) . data ?. experiments ?. cloudAi === true ;
1836 const sections = settingsSections . filter (
19- ( section ) => section . pluginId === pluginId ,
37+ ( section ) =>
38+ section . pluginId === pluginId &&
39+ isSettingsSectionVisible ( section , cloudAiEnabled ) ,
2040 ) ;
2141 if ( sections . length === 0 ) return null ;
2242 return < PluginSettingsSectionList sections = { sections } /> ;
@@ -27,16 +47,34 @@ function PluginSettingsSectionList({
2747} : {
2848 sections : readonly PluginSettingsSectionSlot [ ] ;
2949} ) {
50+ const location = useLocation ( ) ;
51+
52+ useEffect ( ( ) => {
53+ if ( location . hash . length <= 1 ) return ;
54+ let sectionId : string ;
55+ try {
56+ sectionId = decodeURIComponent ( location . hash . slice ( 1 ) ) ;
57+ } catch {
58+ return ;
59+ }
60+ if ( ! sections . some ( ( section ) => section . id === sectionId ) ) return ;
61+ document . getElementById ( sectionId ) ?. scrollIntoView ( { block : "start" } ) ;
62+ } , [ location . hash , location . key , sections ] ) ;
63+
3064 return (
3165 < div className = "space-y-6" data-testid = "plugin-settings-sections" >
3266 { sections . map ( ( section ) => {
3367 const key = `${ section . pluginId } /${ section . id } /${ section . generation } ` ;
34- return section . title === undefined ? (
35- < PluginSettingsSectionPanel key = { key } section = { section } />
36- ) : (
37- < ResourceDetailConfigurationSection key = { key } label = { section . title } >
38- < PluginSettingsSectionPanel section = { section } />
39- </ ResourceDetailConfigurationSection >
68+ return (
69+ < div key = { key } id = { section . id } className = "scroll-mt-4" >
70+ { section . title === undefined ? (
71+ < PluginSettingsSectionPanel section = { section } />
72+ ) : (
73+ < ResourceDetailConfigurationSection label = { section . title } >
74+ < PluginSettingsSectionPanel section = { section } />
75+ </ ResourceDetailConfigurationSection >
76+ ) }
77+ </ div >
4078 ) ;
4179 } ) }
4280 </ div >
0 commit comments