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

mendersoftware / gui / 963002358

pending completion
963002358

Pull #3870

gitlab-ci

mzedel
chore: cleaned up left over onboarding tooltips & aligned with updated design

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3870: MEN-5413

4348 of 6319 branches covered (68.81%)

95 of 122 new or added lines in 24 files covered. (77.87%)

1734 existing lines in 160 files now uncovered.

8174 of 9951 relevant lines covered (82.14%)

178.12 hits per line

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

77.94
/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, getTenantCapabilities, getUserCapabilities, getVersionInformation } from '../selectors';
27
import DocsLink from './common/docslink';
28

29
const listItems = [
3✔
30
  { route: '/', text: 'Dashboard', canAccess },
31
  { route: '/devices', text: 'Devices', canAccess: ({ userCapabilities: { canReadDevices } }) => canReadDevices },
29✔
32
  { route: '/releases', text: 'Releases', canAccess: ({ userCapabilities: { canReadReleases, canUploadReleases } }) => canReadReleases || canUploadReleases },
29✔
33
  { route: '/deployments', text: 'Deployments', canAccess: ({ userCapabilities: { canDeploy, canReadDeployments } }) => canReadDeployments || canDeploy },
29✔
34
  {
35
    route: '/auditlog',
36
    text: 'Audit log',
37
    canAccess: ({ tenantCapabilities: { hasAuditlogs }, userCapabilities: { canAuditlog } }) => hasAuditlogs && canAuditlog
29!
38
  }
39
];
40

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

53
const linkables = {
3✔
54
  'Integration': 'integration',
55
  'Mender-Client': 'mender',
56
  'Mender-Artifact': 'mender-artifact',
57
  'GUI': 'gui'
58
};
59

60
const VersionInfo = () => {
3✔
61
  const [clicks, setClicks] = useState(0);
31✔
62
  const timer = useRef();
31✔
63
  const { classes } = useStyles();
31✔
64

65
  const dispatch = useDispatch();
31✔
66
  const { isHosted } = useSelector(getFeatures);
31✔
67
  // eslint-disable-next-line no-unused-vars
68
  const { latestRelease, ...versionInformation } = useSelector(getVersionInformation);
31✔
69

70
  useEffect(() => {
31✔
71
    return () => {
4✔
72
      clearTimeout(timer.current);
4✔
73
    };
74
  }, []);
75

76
  const onVersionClick = () => {
31✔
UNCOV
77
    copy(JSON.stringify(versionInformation));
×
UNCOV
78
    dispatch(setSnackbar('Version information copied to clipboard'));
×
79
  };
80

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

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

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

130
export const LeftNav = () => {
3✔
131
  const releasesRef = useRef();
29✔
132
  const { classes } = useStyles();
29✔
133

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

173
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