-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: lucferbux <[email protected]>
- Loading branch information
Showing
5 changed files
with
109 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import React from 'react'; | ||
import { | ||
Dropdown, | ||
DropdownItem, | ||
DropdownList, | ||
Masthead, | ||
MastheadContent, | ||
MastheadMain, | ||
MenuToggle, | ||
MenuToggleElement, | ||
Toolbar, | ||
ToolbarContent, | ||
ToolbarGroup, | ||
ToolbarItem, | ||
} from '@patternfly/react-core'; | ||
import { SimpleSelect, SimpleSelectOption } from '@patternfly/react-templates'; | ||
|
||
interface NavBarProps { | ||
username?: string; | ||
onLogout: () => void; | ||
} | ||
|
||
const Options: SimpleSelectOption[] = [{ content: 'All Namespaces', value: 'All' }]; | ||
|
||
const NavBar: React.FC<NavBarProps> = ({ username, onLogout }) => { | ||
const [selected, setSelected] = React.useState<string | undefined>('All'); | ||
const [userMenuOpen, setUserMenuOpen] = React.useState(false); | ||
|
||
const initialOptions = React.useMemo<SimpleSelectOption[]>( | ||
() => Options.map((o) => ({ ...o, selected: o.value === selected })), | ||
[selected], | ||
); | ||
|
||
const handleLogout = () => { | ||
setUserMenuOpen(false); | ||
onLogout(); | ||
}; | ||
|
||
const userMenuItems = [ | ||
<DropdownItem key="logout" onClick={handleLogout}> | ||
Log out | ||
</DropdownItem>, | ||
]; | ||
|
||
return ( | ||
<Masthead> | ||
<MastheadMain /> | ||
<MastheadContent> | ||
<Toolbar> | ||
<ToolbarContent> | ||
<ToolbarGroup variant="action-group-plain" align={{ default: 'alignStart' }}> | ||
<ToolbarItem> | ||
<SimpleSelect | ||
isDisabled | ||
initialOptions={initialOptions} | ||
onSelect={(_ev, selection) => setSelected(String(selection))} | ||
/> | ||
</ToolbarItem> | ||
</ToolbarGroup> | ||
{username && ( | ||
<ToolbarGroup variant="action-group-plain" align={{ default: 'alignEnd' }}> | ||
<ToolbarItem> | ||
<Dropdown | ||
popperProps={{ position: 'right' }} | ||
onOpenChange={(isOpen) => setUserMenuOpen(isOpen)} | ||
toggle={(toggleRef: React.Ref<MenuToggleElement>) => ( | ||
<MenuToggle | ||
aria-label="User menu" | ||
id="user-menu-toggle" | ||
ref={toggleRef} | ||
onClick={() => setUserMenuOpen(!userMenuOpen)} | ||
isExpanded={userMenuOpen} | ||
> | ||
{username} | ||
</MenuToggle> | ||
)} | ||
isOpen={userMenuOpen} | ||
> | ||
<DropdownList>{userMenuItems}</DropdownList> | ||
</Dropdown> | ||
</ToolbarItem> | ||
</ToolbarGroup> | ||
)} | ||
</ToolbarContent> | ||
</Toolbar> | ||
</MastheadContent> | ||
</Masthead> | ||
); | ||
}; | ||
|
||
export default NavBar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,5 @@ export const fetchConfig = async (): Promise<ConfigSettings> => ({ | |
// TODO: [Auth-enablement] replace with the actual call once we have the endpoint | ||
export const fetchUser = async (): Promise<UserSettings> => ({ | ||
username: '[email protected]', | ||
isAdmin: true, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters