(
props: {
accessRequired?: AccessCheck;
accessDeniedText?: string;
checks?: [boolean, string][];
hideTooltip?: boolean;
} & TooltipProps,
)
| 16 | }; |
| 17 | |
| 18 | const ConditionallyEnable = ( |
| 19 | props: { |
| 20 | accessRequired?: AccessCheck; |
| 21 | accessDeniedText?: string; |
| 22 | checks?: [boolean, string][]; |
| 23 | hideTooltip?: boolean; |
| 24 | } & TooltipProps, |
| 25 | ) => { |
| 26 | const { |
| 27 | accessRequired = "requireNothing", |
| 28 | accessDeniedText, |
| 29 | checks = [], |
| 30 | hideTooltip, |
| 31 | children, |
| 32 | ...rest |
| 33 | } = props; |
| 34 | |
| 35 | const accessCheck = useAccessCheck(accessRequired); |
| 36 | const selectedProjectNotHidden = useSelectedProject().data?.isHidden !== true; |
| 37 | const failingCheck = [ |
| 38 | [selectedProjectNotHidden, "This project is archived. No further changes can be made."], |
| 39 | ...checks, |
| 40 | ]?.find(([check]) => !check); |
| 41 | |
| 42 | const disableChildren = !accessCheck.access || !!failingCheck; |
| 43 | const tooltipText = !accessCheck.access |
| 44 | ? accessDeniedText ?? accessCheck.message |
| 45 | : failingCheck?.[1] ?? ""; |
| 46 | |
| 47 | return ( |
| 48 | <Tooltip label={tooltipText} isDisabled={!disableChildren || hideTooltip} hasArrow {...rest}> |
| 49 | <ButtonGroup isDisabled={disableChildren} w={rest.w}> |
| 50 | <FormControl isDisabled={disableChildren} w={rest.w}> |
| 51 | {children} |
| 52 | </FormControl> |
| 53 | </ButtonGroup> |
| 54 | </Tooltip> |
| 55 | ); |
| 56 | }; |
| 57 | |
| 58 | export default ConditionallyEnable; |
nothing calls this directly
no test coverage detected