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

mendersoftware / mender-server / 10423

11 Nov 2025 04:53PM UTC coverage: 74.435% (-0.1%) from 74.562%
10423

push

gitlab-ci

web-flow
Merge pull request #1071 from mendersoftware/dependabot/npm_and_yarn/frontend/main/development-dependencies-92732187be

3868 of 5393 branches covered (71.72%)

Branch coverage included in aggregate %.

5 of 5 new or added lines in 2 files covered. (100.0%)

176 existing lines in 95 files now uncovered.

64605 of 86597 relevant lines covered (74.6%)

7.74 hits per line

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

98.08
/frontend/src/js/components/devices/widgets/DeviceAdditionWidget.tsx
1
// Copyright 2021 Northern.tech AS
2✔
2
//
2✔
3
//    Licensed under the Apache License, Version 2.0 (the "License");
2✔
4
//    you may not use this file except in compliance with the License.
2✔
5
//    You may obtain a copy of the License at
2✔
6
//
2✔
7
//        http://www.apache.org/licenses/LICENSE-2.0
2✔
8
//
2✔
9
//    Unless required by applicable law or agreed to in writing, software
2✔
10
//    distributed under the License is distributed on an "AS IS" BASIS,
2✔
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2✔
12
//    See the License for the specific language governing permissions and
2✔
13
//    limitations under the License.
2✔
14
import { useState } from 'react';
2✔
15

2✔
16
import { ArrowDropDown as ArrowDropDownIcon, Launch as LaunchIcon } from '@mui/icons-material';
2✔
17
import { Button, ButtonGroup, Menu, MenuItem } from '@mui/material';
2✔
18
import { makeStyles } from 'tss-react/mui';
2✔
19

2✔
20
import DocsLink from '@northern.tech/common-ui/DocsLink';
2✔
21
import { canAccess } from '@northern.tech/store/constants';
2✔
22

2✔
23
const useStyles = makeStyles()(() => ({
7✔
24
  buttonStyle: { textTransform: 'none' }
2✔
25
}));
2✔
26

2✔
27
export const DeviceAdditionWidget = ({ features, innerRef, onConnectClick, onMakeGatewayClick, onPreauthClick, tenantCapabilities }) => {
7✔
28
  const [anchorEl, setAnchorEl] = useState();
13✔
29
  const [selectedIndex, setSelectedIndex] = useState(0);
13✔
30
  const { classes } = useStyles();
13✔
31

2✔
32
  const options = [
13✔
33
    { action: onConnectClick, title: 'Connect a new device', value: 'connect', canAccess },
2✔
34
    { action: onPreauthClick, title: 'Preauthorize a device', value: 'preauth', canAccess },
2✔
35
    {
2✔
36
      action: onMakeGatewayClick,
2✔
37
      title: 'Promote a device to gateway',
2✔
38
      value: 'makegateway',
2✔
39
      canAccess: ({ features, tenantCapabilities }) => features.isHosted && tenantCapabilities.isEnterprise
13✔
40
    },
2✔
41
    {
2✔
42
      component: DocsLink,
2✔
43
      path: 'client-installation/overview',
2✔
44
      title: 'Learn how to connect devices',
2✔
45
      value: 'learntoconnect',
2✔
46
      canAccess
2✔
47
    }
2✔
48
  ];
2✔
49

2✔
50
  const handleToggle = event => {
13✔
51
    const anchor = anchorEl ? null : event?.currentTarget.parentElement;
2!
52
    setAnchorEl(anchor);
2✔
53
  };
2✔
54

2✔
55
  const handleSelection = index => {
13✔
56
    setSelectedIndex(index);
2✔
57
    handleToggle();
2✔
58
    options[index].action(true);
2✔
59
  };
2✔
60

2✔
61
  return (
13✔
62
    <>
2✔
63
      <ButtonGroup className="muted device-addition-widget" ref={innerRef} style={{ height: 'max-content' }}>
2✔
64
        <Button className={classes.buttonStyle} onClick={options[selectedIndex].action} variant="text">
2✔
65
          {options[selectedIndex].title}
2✔
66
        </Button>
2✔
67
        <Button className={classes.buttonStyle} size="small" onClick={handleToggle} variant="text">
2✔
68
          <ArrowDropDownIcon />
2✔
69
        </Button>
2✔
70
      </ButtonGroup>
2✔
71
      <Menu id="device-connection-menu" anchorEl={anchorEl} keepMounted open={Boolean(anchorEl)} onClose={handleToggle} variant="menu">
2✔
72
        {options.reduce((accu, option, index) => {
2✔
73
          if (!option.canAccess({ features, tenantCapabilities })) {
46✔
74
            return accu;
13✔
75
          }
2✔
76
          // eslint-disable-next-line @typescript-eslint/no-unused-vars
2✔
77
          const { canAccess, component, title, value, ...optionProps } = option;
35✔
78
          const item = component ? (
35✔
79
            <MenuItem {...optionProps} key={value} component={component}>
2✔
80
              {title}
2✔
81
              <LaunchIcon style={{ fontSize: '10pt' }} />
2✔
82
            </MenuItem>
2✔
83
          ) : (
2✔
UNCOV
84
            <MenuItem className={classes.buttonStyle} key={value} onClick={() => handleSelection(index)}>
2✔
85
              {title}
2✔
86
            </MenuItem>
2✔
87
          );
2✔
88
          accu.push(item);
46✔
89
          return accu;
46✔
90
        }, [])}
2✔
91
      </Menu>
2✔
92
    </>
2✔
93
  );
2✔
94
};
2✔
95

2✔
96
export default DeviceAdditionWidget;
2✔
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