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

mendersoftware / gui / 1308041585

28 May 2024 07:57AM UTC coverage: 83.386% (-16.6%) from 99.964%
1308041585

Pull #4424

gitlab-ci

mzedel
feat: restructured account menu & added option to switch tenant in supporting setups

Ticket: MEN-6906
Changelog: Title
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4424: MEN-6906 - tenant switching - wip

4464 of 6369 branches covered (70.09%)

24 of 28 new or added lines in 2 files covered. (85.71%)

1670 existing lines in 164 files now uncovered.

8477 of 10166 relevant lines covered (83.39%)

140.8 hits per line

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

77.78
/src/js/components/leftnav.js
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 { Link, 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 copy from 'copy-to-clipboard';
23

24
import { setSnackbar, setVersionInfo } from '../actions/appActions';
25
import { TIMEOUTS, canAccess } from '../constants/appConstants';
26
import { getFeatures, getUserCapabilities, getVersionInformation } from '../selectors';
27
import DocsLink from './common/docslink';
28

29
const listItems = [
2✔
30
  { route: '/', text: 'Dashboard', canAccess },
31
  { route: '/devices', text: 'Devices', canAccess: ({ userCapabilities: { canReadDevices } }) => canReadDevices },
11✔
32
  { route: '/releases', text: 'Releases', canAccess: ({ userCapabilities: { canReadReleases, canUploadReleases } }) => canReadReleases || canUploadReleases },
11✔
33
  { route: '/deployments', text: 'Deployments', canAccess: ({ userCapabilities: { canDeploy, canReadDeployments } }) => canReadDeployments || canDeploy },
11✔
34
  { route: '/auditlog', text: 'Audit log', canAccess: ({ userCapabilities: { canAuditlog } }) => canAuditlog },
11✔
35
  { route: '/settings/global-settings', text: 'Settings', canAccess }
36
];
37

38
const useStyles = makeStyles()(theme => ({
22✔
39
  licenseLink: { fontSize: '13px', position: 'relative', top: '6px', color: theme.palette.primary.main },
40
  infoList: { padding: 0, position: 'absolute', bottom: 30, left: 0, right: 0 },
41
  list: {
42
    backgroundColor: theme.palette.background.lightgrey,
43
    borderRight: `1px solid ${theme.palette.grey[300]}`
44
  },
45
  navLink: { padding: '22px 16px 22px 42px' },
46
  listItem: { padding: '16px 16px 16px 42px' },
47
  versions: { display: 'grid', gridTemplateColumns: 'max-content 60px', columnGap: theme.spacing(), '>a': { color: theme.palette.grey[100] } }
48
}));
49

50
const linkables = {
2✔
51
  'Integration': 'integration',
52
  'Mender-Client': 'mender',
53
  'Mender-Artifact': 'mender-artifact',
54
  'GUI': 'gui'
55
};
56

57
const VersionInfo = () => {
2✔
58
  const [clicks, setClicks] = useState(0);
11✔
59
  const timer = useRef();
11✔
60
  const { classes } = useStyles();
11✔
61

62
  const dispatch = useDispatch();
11✔
63
  const { isHosted } = useSelector(getFeatures);
11✔
64
  // eslint-disable-next-line no-unused-vars
65
  const { latestRelease, ...versionInformation } = useSelector(getVersionInformation);
11✔
66

67
  useEffect(() => {
11✔
68
    return () => {
5✔
69
      clearTimeout(timer.current);
5✔
70
    };
71
  }, []);
72

73
  const onVersionClick = () => {
11✔
UNCOV
74
    copy(JSON.stringify(versionInformation));
×
UNCOV
75
    dispatch(setSnackbar('Version information copied to clipboard'));
×
76
  };
77

78
  const versions = (
79
    <div className={classes.versions}>
11✔
80
      {Object.entries(versionInformation).reduce((accu, [key, version]) => {
81
        if (version) {
67✔
82
          accu.push(
28✔
83
            <React.Fragment key={key}>
84
              {linkables[key] ? (
28✔
85
                <a href={`https://github.com/mendersoftware/${linkables[key]}/tree/${version}`} target="_blank" rel="noopener noreferrer">
86
                  {key}
87
                </a>
88
              ) : (
89
                <div>{key}</div>
90
              )}
91
              <div className="align-right text-overflow" title={version}>
92
                {version}
93
              </div>
94
            </React.Fragment>
95
          );
96
        }
97
        return accu;
67✔
98
      }, [])}
99
    </div>
100
  );
101

102
  const onClick = () => {
11✔
UNCOV
103
    setClicks(clicks + 1);
×
UNCOV
104
    clearTimeout(timer.current);
×
UNCOV
105
    timer.current = setTimeout(() => {
×
UNCOV
106
      setClicks(0);
×
107
    }, TIMEOUTS.threeSeconds);
UNCOV
108
    if (clicks > 5) {
×
UNCOV
109
      dispatch(setVersionInfo({ Integration: 'next' }));
×
110
    }
UNCOV
111
    onVersionClick();
×
112
  };
113

114
  let title = versionInformation.Integration ? `Version: ${versionInformation.Integration}` : '';
11✔
115
  if (isHosted && versionInformation.Integration !== 'next') {
11!
UNCOV
116
    title = 'Version: latest';
×
117
  }
118
  return (
11✔
119
    <Tooltip title={versions} placement="top">
120
      <div className="clickable slightly-smaller" onClick={onClick}>
121
        {title}
122
      </div>
123
    </Tooltip>
124
  );
125
};
126

127
export const LeftNav = () => {
2✔
128
  const releasesRef = useRef();
11✔
129
  const { classes } = useStyles();
11✔
130

131
  const userCapabilities = useSelector(getUserCapabilities);
11✔
132
  return (
11✔
133
    <div className={`leftFixed leftNav ${classes.list}`}>
134
      <List style={{ padding: 0 }}>
135
        {listItems.reduce((accu, item, index) => {
136
          if (!item.canAccess({ userCapabilities })) {
66✔
137
            return accu;
8✔
138
          }
139
          accu.push(
58✔
140
            <ListItem
141
              className={`navLink leftNav ${classes.navLink}`}
142
              component={NavLink}
143
              end={item.route === '/'}
144
              key={index}
145
              ref={item.route === '/releases' ? releasesRef : null}
58✔
146
              to={item.route}
147
            >
148
              <ListItemText primary={item.text} style={{ textTransform: 'uppercase' }} />
149
            </ListItem>
150
          );
151
          return accu;
58✔
152
        }, [])}
153
      </List>
154
      <List className={classes.infoList}>
155
        <ListItem className={`navLink leftNav ${classes.listItem}`} component={Link} to="/help">
156
          <ListItemText primary="Help & support" />
157
        </ListItem>
158
        <ListItem className={classes.listItem}>
159
          <ListItemText
160
            primary={<VersionInfo />}
161
            secondary={<DocsLink className={classes.licenseLink} path="release-information/open-source-licenses" title="License information" />}
162
          />
163
        </ListItem>
164
      </List>
165
    </div>
166
  );
167
};
168

169
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