• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alkem-io / client-web / #9533

05 Dec 2024 02:27PM UTC coverage: 5.947%. First build
#9533

Pull #7254

travis-ci

Pull Request #7254: In-app Notifications v1 for Beta Testers

194 of 10628 branches covered (1.83%)

Branch coverage included in aggregate %.

40 of 177 new or added lines in 15 files covered. (22.6%)

1532 of 18394 relevant lines covered (8.33%)

0.19 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/core/ui/card/ActionsMenu.tsx
1
import MoreVertIcon from '@mui/icons-material/MoreVert';
2
import { ClickAwayListener, IconButton, Menu } from '@mui/material';
3
import { Children, MouseEvent, PropsWithChildren, cloneElement, isValidElement, useCallback, useState } from 'react';
4
import { useTranslation } from 'react-i18next';
5

6
type ClickableProps = {
×
7
  onClick?: (e: MouseEvent<HTMLElement>) => void;
×
8
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
×
9
  [key: string]: any;
×
10
};
11

NEW
12
const ActionsMenu = ({ children }: PropsWithChildren) => {
×
13
  const { t } = useTranslation();
×
14
  const [settingsAnchorEl, setSettingsAnchorEl] = useState<null | HTMLElement>(null);
×
15
  const settingsOpened = Boolean(settingsAnchorEl);
×
16

17
  // prevent the redirection of Link components when clicking on the ActionsMenu
NEW
18
  const onMenuClick = useCallback((event: MouseEvent<HTMLButtonElement>) => {
×
19
    event.preventDefault();
×
20
    event.stopPropagation();
21
    setSettingsAnchorEl(event.currentTarget);
22
  }, []);
NEW
23

×
NEW
24
  const handleClose = useCallback(() => {
×
NEW
25
    setSettingsAnchorEl(null);
×
26
  }, [setSettingsAnchorEl]);
NEW
27

×
NEW
28
  // close the menu on every item click
×
29
  const clonedChildren = Children.map(children, child => {
NEW
30
    if (isValidElement<ClickableProps>(child)) {
×
31
      return cloneElement(child, {
32
        onClick: (event: React.MouseEvent<HTMLElement>) => {
33
          child.props.onClick?.(event);
34
          handleClose();
NEW
35
        },
×
36
      });
37
    }
38

×
39
    return child;
×
40
  });
41

42
  return (
43
    <div onClick={e => e.stopPropagation()}>
×
44
      <IconButton
×
45
        aria-label={t('common.settings')}
46
        aria-haspopup="true"
47
        aria-controls={settingsOpened ? 'settings-menu' : undefined}
48
        aria-expanded={settingsOpened ? 'true' : undefined}
49
        onClick={onMenuClick}
50
      >
51
        <MoreVertIcon color="primary" />
52
      </IconButton>
53
      <ClickAwayListener onClickAway={handleClose}>
54
        <Menu
55
          aria-labelledby="settings-button"
56
          anchorEl={settingsAnchorEl}
57
          open={settingsOpened}
58
          onClose={handleClose}
59
          anchorOrigin={{
60
            vertical: 'top',
61
            horizontal: 'right',
62
          }}
63
        >
64
          {clonedChildren}
65
        </Menu>
66
      </ClickAwayListener>
67
    </div>
68
  );
69
};
70

71
export default ActionsMenu;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc