@@ -31,38 +31,12 @@ import { StandaloneMenu } from './menu';
3131import { Paths , formatPath } from './paths' ;
3232import { useUserContext } from './user-context' ;
3333
34- export const StandaloneLayout = ( { children } : { children : ReactNode } ) => {
35- const [ aboutModalVisible , setAboutModalVisible ] = useState < boolean > ( false ) ;
36- const { getUsername, clearCredentials } = useUserContext ( ) ;
37-
38- const userName = getUsername ( ) ;
39- let aboutModal = null ;
40- let docsDropdownItems = [ ] ;
41- let userDropdownItems = [ ] ;
42-
43- if ( userName ) {
44- userDropdownItems = [
45- < DropdownItem isDisabled key = 'username' >
46- < Trans > Username: { userName } </ Trans >
47- </ DropdownItem > ,
48- < DropdownSeparator key = 'separator' /> ,
49- < DropdownItem
50- key = 'profile'
51- component = {
52- < Link to = { formatPath ( Paths . core . user . profile ) } > { t `My profile` } </ Link >
53- }
54- /> ,
55-
56- < DropdownItem
57- key = 'logout'
58- aria-label = { 'logout' }
59- onClick = { ( ) => clearCredentials ( ) }
60- >
61- { t `Logout` }
62- </ DropdownItem > ,
63- ] ;
64-
65- docsDropdownItems = [
34+ const DocsDropdown = ( { showAbout } : { showAbout : ( ) => void } ) => (
35+ < StatefulDropdown
36+ ariaLabel = { t `Docs dropdown` }
37+ data-cy = 'docs-dropdown'
38+ defaultText = { < QuestionCircleIcon /> }
39+ items = { [
6640 < DropdownItem
6741 key = 'documentation'
6842 component = {
@@ -72,19 +46,56 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
7246 > { t `Documentation` } </ ExternalLink >
7347 }
7448 /> ,
75- < DropdownItem key = 'about' onClick = { ( ) => setAboutModalVisible ( true ) } >
49+ < DropdownItem key = 'about' onClick = { ( ) => showAbout ( ) } >
7650 { t `About` }
7751 </ DropdownItem > ,
78- ] . filter ( Boolean ) ;
52+ ] }
53+ toggleType = 'icon'
54+ />
55+ ) ;
7956
80- aboutModal = (
81- < PulpAboutModal
82- isOpen = { aboutModalVisible }
83- onClose = { ( ) => setAboutModalVisible ( false ) }
84- userName = { userName }
85- />
86- ) ;
87- }
57+ const UserDropdown = ( {
58+ username,
59+ clearCredentials,
60+ } : {
61+ username ?: string ;
62+ clearCredentials : ( ) => void ;
63+ } ) =>
64+ username ? (
65+ < StatefulDropdown
66+ ariaLabel = { t `User dropdown` }
67+ data-cy = 'user-dropdown'
68+ defaultText = { username }
69+ items = { [
70+ < DropdownItem isDisabled key = 'username' >
71+ < Trans > Username: { username } </ Trans >
72+ </ DropdownItem > ,
73+ < DropdownSeparator key = 'separator' /> ,
74+ < DropdownItem
75+ key = 'profile'
76+ component = {
77+ < Link
78+ to = { formatPath ( Paths . core . user . profile ) }
79+ > { t `My profile` } </ Link >
80+ }
81+ /> ,
82+ < DropdownItem
83+ key = 'logout'
84+ aria-label = { 'logout' }
85+ onClick = { ( ) => clearCredentials ( ) }
86+ >
87+ { t `Logout` }
88+ </ DropdownItem > ,
89+ ] }
90+ toggleType = 'dropdown'
91+ />
92+ ) : null ;
93+
94+ export const StandaloneLayout = ( { children } : { children : ReactNode } ) => {
95+ const [ aboutModalVisible , setAboutModalVisible ] = useState < boolean > ( false ) ;
96+ const { getUsername, clearCredentials } = useUserContext ( ) ;
97+
98+ const username = getUsername ( ) ;
8899
89100 const Header = (
90101 < Masthead >
@@ -103,33 +114,22 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
103114 padding : '9px 0 0 4px' ,
104115 } }
105116 >
106- Pulp UI
117+ { APPLICATION_NAME }
107118 </ span >
108119 </ MastheadBrand >
109120 </ MastheadMain >
110121 < MastheadContent >
111122 < span style = { { flexGrow : 1 } } />
112123 < DarkmodeSwitcher />
113124 < LanguageSwitcher />
114- { credentials ? (
115- < StatefulDropdown
116- ariaLabel = { t `Docs dropdown` }
117- data-cy = 'docs-dropdown'
118- defaultText = { < QuestionCircleIcon /> }
119- items = { docsDropdownItems }
120- toggleType = 'icon'
125+ < DocsDropdown showAbout = { ( ) => setAboutModalVisible ( true ) } />
126+ { username ? (
127+ < UserDropdown
128+ clearCredentials = { clearCredentials }
129+ username = { username }
121130 />
122- ) : null }
123- { ! credentials ? (
124- < LoginLink />
125131 ) : (
126- < StatefulDropdown
127- ariaLabel = { t `User dropdown` }
128- data-cy = 'user-dropdown'
129- defaultText = { userName }
130- items = { userDropdownItems }
131- toggleType = 'dropdown'
132- />
132+ < LoginLink />
133133 ) }
134134 </ MastheadContent >
135135 </ Masthead >
@@ -146,7 +146,13 @@ export const StandaloneLayout = ({ children }: { children: ReactNode }) => {
146146 return (
147147 < Page isManagedSidebar header = { Header } sidebar = { Sidebar } >
148148 { children }
149- { aboutModalVisible && aboutModal }
149+ { aboutModalVisible ? (
150+ < PulpAboutModal
151+ isOpen
152+ onClose = { ( ) => setAboutModalVisible ( false ) }
153+ username = { username }
154+ />
155+ ) : null }
150156 </ Page >
151157 ) ;
152158} ;
0 commit comments