-
Notifications
You must be signed in to change notification settings - Fork 498
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix switcher component * Fix header styles * Add popover component in header
- Loading branch information
Showing
20 changed files
with
420 additions
and
268 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
35 changes: 0 additions & 35 deletions
35
src/fireedge/src/public/components/Header/FilterPoolSelect.js
This file was deleted.
Oops, something went wrong.
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,80 @@ | ||
import React from 'react'; | ||
|
||
import { Button } from '@material-ui/core'; | ||
import FilterIcon from '@material-ui/icons/FilterDrama'; | ||
import SelectedIcon from '@material-ui/icons/FilterVintage'; | ||
|
||
import useAuth from 'client/hooks/useAuth'; | ||
import useOpennebula from 'client/hooks/useOpennebula'; | ||
import Search from 'client/components/Search'; | ||
|
||
import { FILTER_POOL } from 'client/constants'; | ||
import HeaderPopover from 'client/components/Header/Popover'; | ||
import headerStyles from 'client/components/Header/styles'; | ||
|
||
const { ALL_RESOURCES, PRIMARY_GROUP_RESOURCES } = FILTER_POOL; | ||
|
||
const Group = () => { | ||
const classes = headerStyles(); | ||
const { authUser, filterPool, setPrimaryGroup } = useAuth(); | ||
const { groups } = useOpennebula(); | ||
|
||
const handleChangeGroup = group => { | ||
group && setPrimaryGroup({ group }); | ||
}; | ||
|
||
const filterSearch = ({ NAME }, search) => | ||
NAME?.toLowerCase().includes(search); | ||
|
||
const renderResult = ({ ID, NAME }, handleClose) => { | ||
const isSelected = | ||
(filterPool === ALL_RESOURCES && ALL_RESOURCES === ID) || | ||
(filterPool === PRIMARY_GROUP_RESOURCES && authUser?.GID === ID); | ||
|
||
return ( | ||
<Button | ||
key={`term-${ID}`} | ||
fullWidth | ||
className={classes.groupButton} | ||
onClick={() => { | ||
handleChangeGroup(ID); | ||
handleClose(); | ||
}} | ||
> | ||
{NAME} | ||
{isSelected && <SelectedIcon className={classes.groupSelectedIcon} />} | ||
</Button> | ||
); | ||
}; | ||
|
||
const sortMainGroupFirst = groups | ||
?.concat({ ID: ALL_RESOURCES, NAME: 'Show All' }) | ||
?.sort((a, b) => { | ||
if (a.ID === authUser?.GUID) { | ||
return -1; | ||
} else if (b.ID === authUser?.GUID) { | ||
return 1; | ||
} | ||
return 0; | ||
}); | ||
|
||
return ( | ||
<HeaderPopover | ||
id="group-list" | ||
icon={<FilterIcon />} | ||
IconProps={{ 'data-cy': 'header-group-button' }} | ||
headerTitle="Switch group" | ||
> | ||
{({ handleClose }) => ( | ||
<Search | ||
list={sortMainGroupFirst} | ||
maxResults={5} | ||
filterSearch={filterSearch} | ||
renderResult={group => renderResult(group, handleClose)} | ||
/> | ||
)} | ||
</HeaderPopover> | ||
); | ||
}; | ||
|
||
export default Group; |
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,124 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { | ||
Box, | ||
IconButton, | ||
useMediaQuery, | ||
Popover, | ||
Typography, | ||
Button | ||
} from '@material-ui/core'; | ||
import CloseIcon from '@material-ui/icons/Close'; | ||
|
||
import { Tr } from 'client/components/HOC'; | ||
|
||
import headerStyles from 'client/components/Header/styles'; | ||
import clsx from 'clsx'; | ||
|
||
const typeButton = { | ||
button: Button, | ||
iconButton: IconButton | ||
}; | ||
|
||
const HeaderPopover = ({ | ||
id, | ||
icon, | ||
buttonLabel, | ||
IconProps, | ||
headerTitle, | ||
disablePadding, | ||
children | ||
}) => { | ||
const classes = headerStyles(); | ||
const isMobile = useMediaQuery(theme => theme.breakpoints.only('xs')); | ||
|
||
const [anchorEl, setAnchorEl] = useState(null); | ||
|
||
const handleOpen = event => setAnchorEl(event.currentTarget); | ||
const handleClose = () => setAnchorEl(null); | ||
|
||
const open = Boolean(anchorEl); | ||
const anchorId = open ? id : undefined; | ||
|
||
const ButtonComponent = React.useMemo( | ||
() => (buttonLabel ? typeButton.button : typeButton.iconButton), | ||
[buttonLabel] | ||
); | ||
|
||
return ( | ||
<> | ||
<ButtonComponent | ||
color="inherit" | ||
aria-controls={anchorId} | ||
aria-describedby={anchorId} | ||
aria-haspopup="true" | ||
onClick={handleOpen} | ||
{...IconProps} | ||
> | ||
{icon} | ||
{buttonLabel && ( | ||
<span className={classes.buttonLabel}>{buttonLabel}</span> | ||
)} | ||
</ButtonComponent> | ||
<Popover | ||
BackdropProps={{ invisible: !isMobile }} | ||
PaperProps={{ | ||
className: clsx(classes.paper, { | ||
[classes.padding]: !disablePadding | ||
}) | ||
}} | ||
id={anchorId} | ||
open={open} | ||
anchorEl={anchorEl} | ||
onClose={handleClose} | ||
anchorOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'right' | ||
}} | ||
transformOrigin={{ | ||
vertical: 'top', | ||
horizontal: 'right' | ||
}} | ||
> | ||
{(headerTitle || isMobile) && ( | ||
<Box className={classes.header}> | ||
{headerTitle && ( | ||
<Typography className={classes.title} variant="body1"> | ||
{Tr(headerTitle)} | ||
</Typography> | ||
)} | ||
{isMobile && ( | ||
<IconButton onClick={handleClose}> | ||
<CloseIcon /> | ||
</IconButton> | ||
)} | ||
</Box> | ||
)} | ||
{children({ handleClose })} | ||
</Popover> | ||
</> | ||
); | ||
}; | ||
|
||
HeaderPopover.propTypes = { | ||
id: PropTypes.string, | ||
icon: PropTypes.node, | ||
buttonLabel: PropTypes.string, | ||
IconProps: PropTypes.objectOf(PropTypes.object), | ||
headerTitle: PropTypes.string, | ||
disablePadding: PropTypes.bool, | ||
children: PropTypes.func | ||
}; | ||
|
||
HeaderPopover.defaultProps = { | ||
id: 'id-popover', | ||
icon: null, | ||
buttonLabel: undefined, | ||
IconProps: {}, | ||
headerTitle: null, | ||
disablePadding: false, | ||
children: () => undefined | ||
}; | ||
|
||
export default HeaderPopover; |
Oops, something went wrong.