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

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

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

78.95
/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 { connect } 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 } from '../constants/appConstants';
26
import { onboardingSteps } from '../constants/onboardingConstants';
27
import { getDocsVersion, getFeatures, getOnboardingState, getTenantCapabilities, getUserCapabilities } from '../selectors';
28
import { getOnboardingComponentFor } from '../utils/onboardingmanager';
29

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

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

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

61
const VersionInfo = ({ isHosted, setSnackbar, setVersionInfo, versionInformation }) => {
3✔
62
  const [clicks, setClicks] = useState(0);
365✔
63
  const timer = useRef();
365✔
64
  const { classes } = useStyles();
365✔
65

66
  useEffect(() => {
365✔
67
    return () => {
7✔
68
      clearTimeout(timer.current);
7✔
69
    };
70
  }, []);
71

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

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

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

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

126
export const LeftNav = ({ docsVersion, isHosted, onboardingState, setSnackbar, setVersionInfo, tenantCapabilities, userCapabilities, versionInformation }) => {
3✔
127
  const releasesRef = useRef();
365✔
128
  const { classes } = useStyles();
365✔
129

130
  // eslint-disable-next-line no-unused-vars
131
  const { latestRelease, ...versionInfo } = versionInformation;
365✔
132

133
  const licenseLink = (
134
    <a
365✔
135
      className={classes.licenseLink}
136
      href={`https://docs.mender.io/${docsVersion}release-information/open-source-licenses`}
137
      rel="noopener noreferrer"
138
      target="_blank"
139
    >
140
      License information
141
    </a>
142
  );
143

144
  let onboardingComponent;
145
  if (releasesRef.current) {
365✔
146
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.APPLICATION_UPDATE_REMINDER_TIP, onboardingState, {
66✔
147
      anchor: {
148
        left: releasesRef.current.offsetWidth - 48,
149
        top: releasesRef.current.offsetTop + releasesRef.current.offsetHeight / 2
150
      },
151
      place: 'right'
152
    });
153
  }
154
  return (
365✔
155
    <div className={`leftFixed leftNav ${classes.list}`}>
156
      <List style={{ padding: 0 }}>
157
        {listItems.reduce((accu, item, index) => {
158
          if (!item.canAccess({ tenantCapabilities, userCapabilities })) {
1,825✔
159
            return accu;
1,238✔
160
          }
161
          accu.push(
587✔
162
            <ListItem
163
              className={`navLink leftNav ${classes.navLink}`}
164
              component={NavLink}
165
              end={item.route === '/'}
166
              key={index}
167
              ref={item.route === '/releases' ? releasesRef : null}
587✔
168
              to={item.route}
169
            >
170
              <ListItemText primary={item.text} style={{ textTransform: 'uppercase' }} />
171
            </ListItem>
172
          );
173
          return accu;
587✔
174
        }, [])}
175
      </List>
176
      {onboardingComponent ? onboardingComponent : null}
365!
177
      <List className={classes.infoList}>
178
        <ListItem className={`navLink leftNav ${classes.listItem}`} component={Link} to="/help">
179
          <ListItemText primary="Help & support" />
180
        </ListItem>
181
        <ListItem className={classes.listItem}>
182
          <ListItemText
183
            primary={<VersionInfo isHosted={isHosted} setSnackbar={setSnackbar} setVersionInfo={setVersionInfo} versionInformation={versionInfo} />}
184
            secondary={licenseLink}
185
          />
186
        </ListItem>
187
      </List>
188
    </div>
189
  );
190
};
191

192
const actionCreators = { setSnackbar, setVersionInfo };
3✔
193

194
const mapStateToProps = state => {
3✔
195
  const { isHosted } = getFeatures(state);
432✔
196
  return {
432✔
197
    docsVersion: getDocsVersion(state),
198
    isHosted,
199
    onboardingState: getOnboardingState(state),
200
    userCapabilities: getUserCapabilities(state),
201
    tenantCapabilities: getTenantCapabilities(state),
202
    versionInformation: state.app.versionInformation
203
  };
204
};
205

206
export default connect(mapStateToProps, actionCreators)(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