11import { createContext , ReactNode , use , useCallback , useMemo , useState } from 'react' ;
2+ import { ApiConfigProvider } from '../Shared/k8s' ;
3+ import { ApiConfig } from '../../lib/api/types/apiConfig.ts' ;
24
35interface SplitterContextType {
46 isAsideVisible : boolean ;
57 asideContent : ReactNode ;
68 closeAside : ( ) => void ;
79 openInAside : ( content : ReactNode ) => void ;
10+ openInAsideWithApiConfig : ( content : ReactNode , apiConfig : ApiConfig ) => void ;
811}
912
1013const SplitterContext = createContext < SplitterContextType | null > ( null ) ;
@@ -18,14 +21,37 @@ export function SplitterProvider({ children }: { children: ReactNode }) {
1821 setIsAsideVisible ( true ) ;
1922 } , [ ] ) ;
2023
24+ const openInAsideWithApiConfig = useCallback ( ( node : ReactNode , apiConfig : ApiConfig ) => {
25+ const projectName = apiConfig . mcpConfig ?. projectName ?? '' ;
26+ const workspaceName = apiConfig . mcpConfig ?. workspaceName ?? '' ;
27+ const controlPlaneName = apiConfig . mcpConfig ?. controlPlaneName ?? '' ;
28+ setAsideContent (
29+ < ApiConfigProvider
30+ apiConfig = { {
31+ mcpConfig :
32+ projectName && workspaceName && controlPlaneName
33+ ? {
34+ projectName : apiConfig . mcpConfig ?. projectName ?? '' ,
35+ workspaceName : apiConfig . mcpConfig ?. workspaceName ?? '' ,
36+ controlPlaneName : apiConfig . mcpConfig ?. controlPlaneName ?? '' ,
37+ }
38+ : undefined ,
39+ } }
40+ >
41+ { node }
42+ </ ApiConfigProvider > ,
43+ ) ;
44+ setIsAsideVisible ( true ) ;
45+ } , [ ] ) ;
46+
2147 const closeAside = useCallback ( ( ) => {
2248 setIsAsideVisible ( false ) ;
2349 setAsideContent ( null ) ;
2450 } , [ ] ) ;
2551
2652 const value = useMemo ( ( ) => {
27- return { isAsideVisible, asideContent, closeAside, openInAside } ;
28- } , [ isAsideVisible , asideContent , closeAside , openInAside ] ) ;
53+ return { isAsideVisible, asideContent, closeAside, openInAside, openInAsideWithApiConfig } ;
54+ } , [ isAsideVisible , asideContent , closeAside , openInAside , openInAsideWithApiConfig ] ) ;
2955
3056 return < SplitterContext value = { value } > { children } </ SplitterContext > ;
3157}
0 commit comments