mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-28 17:55:15 +02:00
* feat: toggle overview accordions * feat: accordion metrics * feat: result * add permission button * fix: remove feature environment container from strategies tab * chore: delete unused code * fix: remove console log * fix: remove unused code * fix: cleanup * fix: refactor * fix: add empty states * fix: loading * feat: mobile accordions * fix: button * fix: strategies * fix: cleanup * fix: remove unused params * fix: strategy button container * fix: alter gradual rollout id * fix: update userid strategy item * fix: string truncator * fix: strategy link * fix: strategies tab * fix: remove unused imports * fix: visual improvements * fix: add border
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { Switch, Tooltip } from '@material-ui/core';
|
|
import { OverridableComponent } from '@material-ui/core/OverridableComponent';
|
|
import AccessContext from '../../../contexts/AccessContext';
|
|
import React, { useContext } from 'react';
|
|
|
|
interface IPermissionSwitchProps extends OverridableComponent<any> {
|
|
permission: string;
|
|
tooltip: string;
|
|
onChange?: (e: any) => void;
|
|
disabled?: boolean;
|
|
projectId?: string;
|
|
checked: boolean;
|
|
}
|
|
|
|
const PermissionSwitch: React.FC<IPermissionSwitchProps> = ({
|
|
permission,
|
|
tooltip = '',
|
|
disabled,
|
|
projectId,
|
|
checked,
|
|
onChange,
|
|
...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 data-loading>
|
|
<Switch
|
|
onChange={onChange}
|
|
disabled={disabled || !access}
|
|
checked={checked}
|
|
{...rest}
|
|
/>
|
|
</span>
|
|
</Tooltip>
|
|
);
|
|
};
|
|
|
|
export default PermissionSwitch;
|