mirror of
https://github.com/Unleash/unleash.git
synced 2024-10-18 20:09:08 +02:00
3959e846e8
* refactor: update test deps * refactor: remove unused ts-expect-error annotations * refactor: add missing arg and return types * refactor: the loading prop is optional * refactor: add missing arg and return types * reafactor: fix value arg type * refactor: fix missing array type * refactor: the parameters field is an array * refactor: use undefined instead of null in state * refactor: add missing params type * refactor: add missing children prop * refactor: add missing array type * refactor: add missing React imports * refactor: use correct IProjectEnvironment type * refactor: type errors as unknown * refactor: the index prop is required * refactor: fix date prop type * refactor: fix tooltip placement prop type * refactor: fix environments state type * refactor: add missing arg types * refactor: add guard for undefined field * refactor: fix ChangePassword prop types * refactor: fix MUI import paths * refactor: add missing arg type * refactor: fix showDialog prop type * refactor: remove unused openUpdateDialog prop * refactor: add missing non-null assertion * refactor: remove unused types prop * refactor: stricten API error handler types * refactor: add missing undefined check * refactor: add missing IProject id field * refactor: fix ConditionallyRender condition prop types * refactor: remove unused args * refactor: add AddVariant prop types * refactor: add types to UIContext * refactor: fix event arg type * refactor: add missing default impressionData field * refactor: fix handleDeleteEnvironment prop args * refactor: fix IFeatureMetrics field requirements * refactor: add missing element types to ConditionallyRender * refactor: remove unused ProjectAccess projectId prop * refactor: add missing undefined check * refactor: fix getCreateTogglePath arg type * refactor: add missing IStrategyPayload import * refactor: remove unused user arg * refactor: add missing event arg type * refactor: add missing style object types * refactor: improve userApiErrors prop type * refactor: the Dialogue onClose prop is optional * refactor: fix the AddonEvents setEventValue prop type
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { IconButton, Tooltip } from '@material-ui/core';
|
|
import React, { useContext } from 'react';
|
|
import AccessContext from '../../../contexts/AccessContext';
|
|
|
|
interface IPermissionIconButtonProps
|
|
extends React.DetailedHTMLProps<
|
|
React.HTMLAttributes<HTMLButtonElement>,
|
|
HTMLButtonElement
|
|
> {
|
|
permission: string;
|
|
Icon?: React.ElementType;
|
|
tooltip?: string;
|
|
onClick?: (e: any) => void;
|
|
projectId?: string;
|
|
environmentId?: string;
|
|
edge?: string;
|
|
className?: string;
|
|
title?: string;
|
|
}
|
|
|
|
const PermissionIconButton: React.FC<IPermissionIconButtonProps> = ({
|
|
permission,
|
|
Icon,
|
|
tooltip,
|
|
onClick,
|
|
projectId,
|
|
children,
|
|
environmentId,
|
|
...rest
|
|
}) => {
|
|
const { hasAccess } = useContext(AccessContext);
|
|
let access;
|
|
|
|
if (projectId && environmentId) {
|
|
access = hasAccess(permission, projectId, environmentId);
|
|
} else if (projectId) {
|
|
access = hasAccess(permission, projectId);
|
|
} else {
|
|
access = hasAccess(permission);
|
|
}
|
|
|
|
const tooltipText = access
|
|
? tooltip || ''
|
|
: "You don't have access to perform this operation";
|
|
|
|
return (
|
|
<Tooltip title={tooltipText} arrow>
|
|
<span>
|
|
<IconButton onClick={onClick} disabled={!access} {...rest}>
|
|
{children}
|
|
</IconButton>
|
|
</span>
|
|
</Tooltip>
|
|
);
|
|
};
|
|
|
|
export default PermissionIconButton;
|