forked from Unleash/unleash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: rebrand feature toggle list as search (Unleash#5675)
- Loading branch information
Showing
7 changed files
with
195 additions
and
41 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...omponent/feature/FeatureToggleList/FeatureToggleListActions/FeatureToggleActions.test.tsx
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,23 @@ | ||
import { screen } from '@testing-library/react'; | ||
import { render } from 'utils/testRenderer'; | ||
import { FeatureToggleListActions } from './FeatureToggleListActions'; | ||
import userEvent from '@testing-library/user-event'; | ||
import { testServerRoute, testServerSetup } from 'utils/testServer'; | ||
|
||
const server = testServerSetup(); | ||
test('all options are drawn', async () => { | ||
testServerRoute(server, '/api/admin/ui-config', { | ||
flags: { | ||
featuresExportImport: true, | ||
}, | ||
}); | ||
|
||
render(<FeatureToggleListActions onExportClick={() => {}} />); | ||
|
||
const batchReviveButton = await screen.findByTitle('Group actions'); | ||
|
||
await userEvent.click(batchReviveButton!); | ||
|
||
await screen.findByText('New feature toggle'); | ||
await screen.findByText('Export'); | ||
}); |
134 changes: 134 additions & 0 deletions
134
...component/feature/FeatureToggleList/FeatureToggleListActions/FeatureToggleListActions.tsx
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,134 @@ | ||
import { FC, useState } from 'react'; | ||
import { | ||
IconButton, | ||
ListItemIcon, | ||
ListItemText, | ||
MenuItem, | ||
MenuList, | ||
Popover, | ||
styled, | ||
Tooltip, | ||
Typography, | ||
} from '@mui/material'; | ||
import { Add, FileDownload, MoreVert } from '@mui/icons-material'; | ||
import { Link } from 'react-router-dom'; | ||
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; | ||
import { useUiFlag } from 'hooks/useUiFlag'; | ||
import { CREATE_FEATURE } from 'component/providers/AccessProvider/permissions'; | ||
import { PermissionHOC } from 'component/common/PermissionHOC/PermissionHOC'; | ||
import { useCreateFeaturePath } from 'component/feature/CreateFeatureButton/useCreateFeaturePath'; | ||
|
||
const StyledActions = styled('div')(({ theme }) => ({ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
})); | ||
|
||
const StyledPopover = styled(Popover)(({ theme }) => ({ | ||
borderRadius: theme.shape.borderRadiusLarge, | ||
padding: theme.spacing(1, 1.5), | ||
})); | ||
|
||
interface IFeatureToggleListActions { | ||
onExportClick: () => void; | ||
} | ||
|
||
export const FeatureToggleListActions: FC<IFeatureToggleListActions> = ({ | ||
onExportClick, | ||
}: IFeatureToggleListActions) => { | ||
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null); | ||
const featuresExportImport = useUiFlag('featuresExportImport'); | ||
const createFeature = useCreateFeaturePath({ | ||
query: '', | ||
project: 'default', | ||
}); | ||
|
||
const open = Boolean(anchorEl); | ||
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const id = `feature-toggle-list-actions`; | ||
const menuId = `${id}-menu`; | ||
|
||
return ( | ||
<StyledActions | ||
onClick={(e) => { | ||
e.preventDefault(); | ||
e.stopPropagation(); | ||
}} | ||
> | ||
<Tooltip title='Group actions' arrow describeChild> | ||
<IconButton | ||
id={id} | ||
aria-controls={open ? menuId : undefined} | ||
aria-haspopup='true' | ||
aria-expanded={open ? 'true' : undefined} | ||
onClick={handleClick} | ||
type='button' | ||
> | ||
<MoreVert /> | ||
</IconButton> | ||
</Tooltip> | ||
<StyledPopover | ||
id={menuId} | ||
anchorEl={anchorEl} | ||
open={open} | ||
onClose={handleClose} | ||
transformOrigin={{ | ||
horizontal: 'right', | ||
vertical: 'top', | ||
}} | ||
anchorOrigin={{ | ||
horizontal: 'right', | ||
vertical: 'bottom', | ||
}} | ||
disableScrollLock={true} | ||
> | ||
<MenuList aria-labelledby={id}> | ||
<PermissionHOC permission={CREATE_FEATURE}> | ||
{({ hasAccess }) => ( | ||
<MenuItem | ||
onClick={handleClose} | ||
component={Link} | ||
disabled={!hasAccess} | ||
to={createFeature!.path} | ||
> | ||
<ListItemIcon> | ||
<Add /> | ||
</ListItemIcon> | ||
<ListItemText> | ||
<Typography variant='body2'> | ||
New feature toggle | ||
</Typography> | ||
</ListItemText> | ||
</MenuItem> | ||
)} | ||
</PermissionHOC> | ||
<ConditionallyRender | ||
condition={featuresExportImport} | ||
show={ | ||
<MenuItem | ||
onClick={() => { | ||
onExportClick(); | ||
handleClose(); | ||
}} | ||
> | ||
<ListItemIcon> | ||
<FileDownload /> | ||
</ListItemIcon> | ||
<ListItemText> | ||
<Typography variant='body2'> | ||
Export | ||
</Typography> | ||
</ListItemText> | ||
</MenuItem> | ||
} | ||
/> | ||
</MenuList> | ||
</StyledPopover> | ||
</StyledActions> | ||
); | ||
}; |
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
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