MCPcopy Index your code
hub / github.com/OpenPipe/OpenPipe / ConditionallyEnable

Function ConditionallyEnable

app/src/components/ConditionallyEnable.tsx:18–56  ·  view source on GitHub ↗
(
  props: {
    accessRequired?: AccessCheck;
    accessDeniedText?: string;
    checks?: [boolean, string][];
    hideTooltip?: boolean;
  } & TooltipProps,
)

Source from the content-addressed store, hash-verified

16};
17
18const 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
58export default ConditionallyEnable;

Callers

nothing calls this directly

Calls 2

useSelectedProjectFunction · 0.90
useAccessCheckFunction · 0.85

Tested by

no test coverage detected