mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-01 13:47:27 +02:00
* fix: wait for api call before refetching * fix: set active environment from feature instead of cache * fix: remove console logs * fix: add permission icon button to project card * fix: remove project button * fix: empty tooltip if it is not passed * fix: add refresh interval * fix: permission buttons * fix: project permission buttons * fix: remove unused imports * fix: add projectId
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { Button, Tooltip } from '@material-ui/core';
|
|
import { OverridableComponent } from '@material-ui/core/OverridableComponent';
|
|
import { Lock } from '@material-ui/icons';
|
|
import { useContext } from 'react';
|
|
import AccessContext from '../../../contexts/AccessContext';
|
|
import ConditionallyRender from '../ConditionallyRender';
|
|
|
|
interface IPermissionIconButtonProps extends OverridableComponent<any> {
|
|
permission: string;
|
|
tooltip: string;
|
|
onClick?: (e: any) => void;
|
|
disabled?: boolean;
|
|
projectId?: string;
|
|
}
|
|
|
|
const PermissionButton: React.FC<IPermissionIconButtonProps> = ({
|
|
permission,
|
|
tooltip = 'Click to perform action',
|
|
onClick,
|
|
children,
|
|
disabled,
|
|
projectId,
|
|
...rest
|
|
}) => {
|
|
const { hasAccess } = useContext(AccessContext);
|
|
|
|
const access = projectId
|
|
? hasAccess(permission, projectId)
|
|
: hasAccess(permission);
|
|
|
|
const tooltipText = access
|
|
? tooltip
|
|
: "You don't have access to perform this operation";
|
|
|
|
return (
|
|
<Tooltip title={tooltipText} arrow>
|
|
<span>
|
|
<Button
|
|
onClick={onClick}
|
|
disabled={disabled || !access}
|
|
variant="contained"
|
|
color="primary"
|
|
{...rest}
|
|
endIcon={
|
|
<ConditionallyRender
|
|
condition={!access}
|
|
show={<Lock />}
|
|
/>
|
|
}
|
|
>
|
|
{children}
|
|
</Button>
|
|
</span>
|
|
</Tooltip>
|
|
);
|
|
};
|
|
|
|
export default PermissionButton;
|