1
- import React , { PropsWithChildren } from 'react' ;
1
+ import React , { PropsWithChildren , useState } from 'react' ;
2
2
import { styled } from '@mui/material/styles' ;
3
3
import Home from '@mui/icons-material/Home' ;
4
4
import CreateComponent from '@mui/icons-material/AddCircleOutline' ;
@@ -19,6 +19,7 @@ import {
19
19
SidebarSpace ,
20
20
useSidebarOpenState ,
21
21
Link ,
22
+ SidebarExpandButton ,
22
23
} from '@backstage/core-components' ;
23
24
import MenuIcon from '@mui/icons-material/Menu' ;
24
25
import SearchIcon from '@mui/icons-material/Search' ;
@@ -31,6 +32,10 @@ import MonitorHeartRoundedIcon from '@mui/icons-material/MonitorHeartRounded';
31
32
import ScoreRoundedIcon from '@mui/icons-material/ScoreRounded' ;
32
33
import { IconComponent } from '@backstage/core-plugin-api' ;
33
34
35
+ export enum LocalStorageKeys {
36
+ SIDEBAR_PIN_STATE = 'sidebarPinState' ,
37
+ }
38
+
34
39
const SidebarLogoRoot = styled ( 'div' ) ( ( ) => ( {
35
40
width : sidebarConfig . drawerWidthClosed ,
36
41
height : 3 * sidebarConfig . logoHeight ,
@@ -57,64 +62,76 @@ const SidebarLogo = () => {
57
62
) ;
58
63
} ;
59
64
60
- export const Root = ( { children } : PropsWithChildren < { } > ) => (
61
- < SidebarPage >
62
- < Sidebar >
63
- < SidebarLogo />
64
- < SidebarGroup label = "Search" icon = { < SearchIcon /> } to = "/search" >
65
- < SidebarSearchModal />
66
- </ SidebarGroup >
67
- < SidebarDivider />
68
- < SidebarGroup label = "Menu" icon = { < MenuIcon /> } >
69
- { /* Global nav, not org-specific */ }
70
- < SidebarItem icon = { Home as IconComponent } to = "/" text = "Home" />
71
- < SidebarItem
72
- icon = { MenuBookRoundedIcon as IconComponent }
73
- to = "catalog"
74
- text = "Catalog"
75
- />
65
+ export const Root = ( { children } : PropsWithChildren < { } > ) => {
66
+ if (
67
+ window . localStorage . getItem ( LocalStorageKeys . SIDEBAR_PIN_STATE ) === null
68
+ ) {
69
+ window . localStorage . setItem (
70
+ LocalStorageKeys . SIDEBAR_PIN_STATE ,
71
+ JSON . stringify ( false ) ,
72
+ ) ;
73
+ }
74
+
75
+ return (
76
+ < SidebarPage >
77
+ < Sidebar disableExpandOnHover = { false } >
78
+ < SidebarLogo />
79
+ < SidebarGroup label = "Search" icon = { < SearchIcon /> } to = "/search" >
80
+ < SidebarSearchModal />
81
+ </ SidebarGroup >
82
+ < SidebarDivider />
83
+ < SidebarGroup label = "Menu" icon = { < MenuIcon /> } >
84
+ { /* Global nav, not org-specific */ }
85
+ < SidebarItem icon = { Home as IconComponent } to = "/" text = "Home" />
86
+ < SidebarItem
87
+ icon = { MenuBookRoundedIcon as IconComponent }
88
+ to = "catalog"
89
+ text = "Catalog"
90
+ />
91
+ < SidebarItem
92
+ icon = { ExtensionRoundedIcon as IconComponent }
93
+ to = "api-docs"
94
+ text = "APIs"
95
+ />
96
+ < SidebarItem
97
+ icon = { LocalLibraryRoundedIcon as IconComponent }
98
+ to = "docs"
99
+ text = "Docs"
100
+ />
101
+ < SidebarItem
102
+ icon = { TouchAppRoundedIcon as IconComponent }
103
+ to = "self-service"
104
+ text = "Self-Service"
105
+ />
106
+ </ SidebarGroup >
107
+ < SidebarDivider />
76
108
< SidebarItem
77
- icon = { ExtensionRoundedIcon as IconComponent }
78
- to = "api-docs "
79
- text = "APIs "
109
+ icon = { ScoreRoundedIcon as IconComponent }
110
+ to = "scorecard "
111
+ text = "Scorecard "
80
112
/>
81
113
< SidebarItem
82
- icon = { LocalLibraryRoundedIcon as IconComponent }
83
- to = "docs "
84
- text = "Docs "
114
+ icon = { MonitorHeartRoundedIcon as IconComponent }
115
+ to = "pulse-check "
116
+ text = "Pulse Check "
85
117
/>
86
118
< SidebarItem
87
- icon = { TouchAppRoundedIcon as IconComponent }
88
- to = "self-service "
89
- text = "Self-Service "
119
+ icon = { AutoAwesomeRoundedIcon as IconComponent }
120
+ to = "explore "
121
+ text = "Explore "
90
122
/>
91
- </ SidebarGroup >
92
- < SidebarDivider />
93
- < SidebarItem
94
- icon = { ScoreRoundedIcon as IconComponent }
95
- to = "scorecard"
96
- text = "Scorecard"
97
- />
98
- < SidebarItem
99
- icon = { MonitorHeartRoundedIcon as IconComponent }
100
- to = "pulse-check"
101
- text = "Pulse Check"
102
- />
103
- < SidebarItem
104
- icon = { AutoAwesomeRoundedIcon as IconComponent }
105
- to = "explore"
106
- text = "Explore"
107
- />
108
- < SidebarSpace />
109
- < SidebarDivider />
110
- < SidebarGroup
111
- label = "Settings"
112
- icon = { < UserSettingsSignInAvatar /> }
113
- to = "/settings"
114
- >
115
- < SidebarSettings />
116
- </ SidebarGroup >
117
- </ Sidebar >
118
- { children }
119
- </ SidebarPage >
120
- ) ;
123
+ < SidebarSpace />
124
+ < SidebarDivider />
125
+ < SidebarGroup
126
+ label = "Settings"
127
+ icon = { < UserSettingsSignInAvatar /> }
128
+ to = "/settings"
129
+ >
130
+ < SidebarSettings />
131
+ </ SidebarGroup >
132
+ < SidebarExpandButton />
133
+ </ Sidebar >
134
+ { children }
135
+ </ SidebarPage >
136
+ ) ;
137
+ } ;
0 commit comments