@@ -4,15 +4,25 @@ import { Button } from "reactstrap";
44import { usePanelSideBarContext } from "./Context/PanelSideBarContext" ;
55import { PanelItem } from "./Definitions/PanelSideBarMenuItem" ;
66import { PanelSideBarItem } from "./PanelSideBarItem" ;
7-
7+ import { useState } from "react" ;
88interface PanelSideBarProps {
99 localItems ?: PanelItem [ ] ;
1010}
1111
1212export const PanelSideBar = ( props : PanelSideBarProps ) => {
1313 const { localItems = [ ] } = props ;
1414
15- const { activePanelId, globalItems, LinkRenderer, setActivePanel, toggledMenuItemIds, toggleMenuItem } = usePanelSideBarContext ( ) ;
15+ const { globalItems, LinkRenderer, toggledMenuItemIds, toggleMenuItem } = usePanelSideBarContext ( ) ;
16+
17+ let initialActivePanel : string ;
18+ if ( localItems . length > 0 ) {
19+ const [ firstLocalItem ] = localItems ;
20+ initialActivePanel = firstLocalItem . id ;
21+ } else {
22+ initialActivePanel = globalItems . find ( ( x ) => x . id ) ?. id ?? "" ;
23+ }
24+
25+ const [ activePanelId , setActivePanelId ] = useState < string > ( initialActivePanel ) ;
1626
1727 const activePanel : PanelItem = globalItems . find ( ( x ) => x . id === activePanelId ) ;
1828 const localActivePanel : PanelItem | undefined = localItems ?. find ( ( x ) => x . id === activePanelId ) ;
@@ -24,7 +34,7 @@ export const PanelSideBar = (props: PanelSideBarProps) => {
2434 color = "primary"
2535 outline
2636 className = { classNames ( "tile" , { active : activePanelId === id } ) }
27- onClick = { ( ) => setActivePanel ( id ) }
37+ onClick = { ( ) => setActivePanelId ( id ) }
2838 title = { title }
2939 disabled = { disabled }
3040 >
0 commit comments