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

mendersoftware / mender-server / 1648176235

30 Jan 2025 09:44AM UTC coverage: 77.589% (+1.0%) from 76.604%
1648176235

Pull #390

gitlab-ci

mzedel
fix(gui): made tenant creation form also work with unset SP device limits

Ticket: None
Changelog: None
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #390: MEN-7961 - SP config fixes

4329 of 6285 branches covered (68.88%)

Branch coverage included in aggregate %.

26 of 34 new or added lines in 6 files covered. (76.47%)

2 existing lines in 1 file now uncovered.

42773 of 54422 relevant lines covered (78.6%)

21.58 hits per line

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

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

18
// material ui
19
import { List, ListItem, ListItemText, Tooltip } from '@mui/material';
20
import { makeStyles } from 'tss-react/mui';
21

22
import DocsLink from '@northern.tech/common-ui/DocsLink';
23
import storeActions from '@northern.tech/store/actions';
24
import { TIMEOUTS } from '@northern.tech/store/constants';
25
import { getFeatures, getUserCapabilities, getVersionInformation } from '@northern.tech/store/selectors';
26
import copy from 'copy-to-clipboard';
27

28
import { routeConfigs } from '../config/routes';
29

30
const { setSnackbar, setVersionInformation } = storeActions;
2✔
31

32
const listItems = [
2✔
33
  { ...routeConfigs.dashboard, canAccess: ({ userCapabilities: { SPTenant } }) => !SPTenant },
22✔
34
  { ...routeConfigs.devices, canAccess: ({ userCapabilities: { canReadDevices, SPTenant } }) => canReadDevices && !SPTenant },
22✔
35
  {
36
    ...routeConfigs.releases,
37
    canAccess: ({ userCapabilities: { canReadReleases, canUploadReleases, SPTenant } }) => (canReadReleases || canUploadReleases) && !SPTenant
22✔
38
  },
39
  {
40
    ...routeConfigs.deployments,
41
    canAccess: ({ userCapabilities: { canDeploy, canReadDeployments, SPTenant } }) => (canReadDeployments || canDeploy) && !SPTenant
22✔
42
  },
43
  { ...routeConfigs.tenants, canAccess: ({ userCapabilities: { SPTenant } }) => SPTenant },
22✔
44
  { ...routeConfigs.auditlog, canAccess: ({ userCapabilities: { canAuditlog } }) => canAuditlog }
22✔
45
];
46

47
const useStyles = makeStyles()(theme => ({
36✔
48
  licenseLink: { fontSize: '13px', position: 'relative', top: '6px', color: theme.palette.primary.main },
49
  infoList: { padding: 0, position: 'absolute', bottom: 30, left: 0, right: 0 },
50
  list: {
51
    backgroundColor: theme.palette.background.lightgrey,
52
    borderRight: `1px solid ${theme.palette.grey[300]}`
53
  },
54
  navLink: { padding: '22px 16px 22px 42px' },
55
  listItem: { padding: '16px 16px 16px 42px' },
56
  versions: { display: 'grid', gridTemplateColumns: 'max-content 60px', columnGap: theme.spacing(), '>a': { color: theme.palette.grey[100] } }
57
}));
58

59
const linkables = {
2✔
60
  'Integration': 'integration',
61
  'Mender-Client': 'mender',
62
  'Mender-Artifact': 'mender-artifact',
63
  'GUI': 'gui'
64
};
65

66
const VersionInfo = () => {
2✔
67
  const [clicks, setClicks] = useState(0);
22✔
68
  const timer = useRef();
22✔
69
  const { classes } = useStyles();
22✔
70

71
  const dispatch = useDispatch();
22✔
72
  const { isHosted } = useSelector(getFeatures);
22✔
73
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
74
  const { latestRelease, ...versionInformation } = useSelector(getVersionInformation);
22✔
75

76
  useEffect(() => {
22✔
77
    return () => {
6✔
78
      clearTimeout(timer.current);
6✔
79
    };
80
  }, []);
81

82
  const onVersionClick = () => {
22✔
83
    copy(JSON.stringify(versionInformation));
×
84
    dispatch(setSnackbar('Version information copied to clipboard'));
×
85
  };
86

87
  const versions = (
88
    <div className={classes.versions}>
22✔
89
      {Object.entries(versionInformation).reduce((accu, [key, version]) => {
90
        if (version) {
164✔
91
          accu.push(
69✔
92
            <React.Fragment key={key}>
93
              {linkables[key] ? (
69✔
94
                <a href={`https://github.com/mendersoftware/${linkables[key]}/tree/${version}`} target="_blank" rel="noopener noreferrer">
95
                  {key}
96
                </a>
97
              ) : (
98
                <div>{key}</div>
99
              )}
100
              <div className="align-right text-overflow" title={version}>
101
                {version}
102
              </div>
103
            </React.Fragment>
104
          );
105
        }
106
        return accu;
164✔
107
      }, [])}
108
    </div>
109
  );
110

111
  const onClick = () => {
22✔
112
    setClicks(clicks + 1);
×
113
    clearTimeout(timer.current);
×
NEW
114
    timer.current = setTimeout(() => setClicks(0), TIMEOUTS.threeSeconds);
×
115
    if (clicks > 5) {
×
116
      dispatch(setVersionInformation({ Integration: 'next' }));
×
117
    }
118
    onVersionClick();
×
119
  };
120

121
  let title = versionInformation.Integration ? `Version: ${versionInformation.Integration}` : '';
22✔
122
  if (isHosted && versionInformation.Integration !== 'next') {
22!
123
    title = 'Version: latest';
×
124
  }
125
  return (
22✔
126
    <Tooltip title={versions} placement="top">
127
      <div className="clickable slightly-smaller" onClick={onClick}>
128
        {title}
129
      </div>
130
    </Tooltip>
131
  );
132
};
133

134
export const LeftNav = () => {
2✔
135
  const releasesRef = useRef();
22✔
136
  const { classes } = useStyles();
22✔
137

138
  const userCapabilities = useSelector(getUserCapabilities);
22✔
139

140
  return (
22✔
141
    <div className={`leftFixed leftNav ${classes.list}`}>
142
      <List style={{ padding: 0 }}>
143
        {listItems.reduce((accu, item, index) => {
144
          if (!item.canAccess({ userCapabilities })) {
132✔
145
            return accu;
38✔
146
          }
147
          accu.push(
94✔
148
            <ListItem
149
              className={`navLink leftNav ${classes.navLink}`}
150
              component={NavLink}
151
              end={item.path === ''}
152
              key={index}
153
              ref={item.path === routeConfigs.releases.path ? releasesRef : null}
94✔
154
              to={`/${item.path}`}
155
            >
156
              <ListItemText primary={item.title} style={{ textTransform: 'uppercase' }} />
157
            </ListItem>
158
          );
159
          return accu;
94✔
160
        }, [])}
161
      </List>
162
      <List className={classes.infoList}>
163
        <ListItem className={`navLink leftNav ${classes.listItem}`} component={NavLink} to={`/${routeConfigs.help.path}`}>
164
          <ListItemText primary={routeConfigs.help.title} />
165
        </ListItem>
166
        <ListItem className={classes.listItem}>
167
          <ListItemText
168
            primary={<VersionInfo />}
169
            secondary={<DocsLink className={classes.licenseLink} path="release-information/open-source-licenses" title="License information" />}
170
          />
171
        </ListItem>
172
      </List>
173
    </div>
174
  );
175
};
176

177
export default LeftNav;
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