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

mendersoftware / gui / 944676341

pending completion
944676341

Pull #3875

gitlab-ci

mzedel
chore: aligned snapshots with updated design

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

4469 of 6446 branches covered (69.33%)

230 of 266 new or added lines in 43 files covered. (86.47%)

1712 existing lines in 161 files now uncovered.

8406 of 10170 relevant lines covered (82.65%)

196.7 hits per line

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

79.17
/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 { onboardingSteps } from '../constants/onboardingConstants';
27
import { getFeatures, getOnboardingState, getUserCapabilities, getVersionInformation } from '../selectors';
28
import { getOnboardingComponentFor } from '../utils/onboardingmanager';
29
import DocsLink from './common/docslink';
30

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

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

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

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

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

68
  useEffect(() => {
53✔
69
    return () => {
4✔
70
      clearTimeout(timer.current);
4✔
71
    };
72
  }, []);
73

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

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

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

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

128
export const LeftNav = () => {
3✔
129
  const releasesRef = useRef();
51✔
130
  const { classes } = useStyles();
51✔
131

132
  const onboardingState = useSelector(getOnboardingState);
51✔
133
  const userCapabilities = useSelector(getUserCapabilities);
51✔
134

135
  let onboardingComponent;
136
  if (releasesRef.current) {
51✔
137
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.APPLICATION_UPDATE_REMINDER_TIP, onboardingState, {
43✔
138
      anchor: {
139
        left: releasesRef.current.offsetWidth - 48,
140
        top: releasesRef.current.offsetTop + releasesRef.current.offsetHeight / 2
141
      },
142
      place: 'right'
143
    });
144
  }
145
  return (
51✔
146
    <div className={`leftFixed leftNav ${classes.list}`}>
147
      <List style={{ padding: 0 }}>
148
        {listItems.reduce((accu, item, index) => {
149
          if (!item.canAccess({ userCapabilities })) {
255✔
150
            return accu;
16✔
151
          }
152
          accu.push(
239✔
153
            <ListItem
154
              className={`navLink leftNav ${classes.navLink}`}
155
              component={NavLink}
156
              end={item.route === '/'}
157
              key={index}
158
              ref={item.route === '/releases' ? releasesRef : null}
239✔
159
              to={item.route}
160
            >
161
              <ListItemText primary={item.text} style={{ textTransform: 'uppercase' }} />
162
            </ListItem>
163
          );
164
          return accu;
239✔
165
        }, [])}
166
      </List>
167
      {onboardingComponent ? onboardingComponent : null}
51!
168
      <List className={classes.infoList}>
169
        <ListItem className={`navLink leftNav ${classes.listItem}`} component={Link} to="/help">
170
          <ListItemText primary="Help & support" />
171
        </ListItem>
172
        <ListItem className={classes.listItem}>
173
          <ListItemText
174
            primary={<VersionInfo />}
175
            secondary={<DocsLink className={classes.licenseLink} path="release-information/open-source-licenses" title="License information" />}
176
          />
177
        </ListItem>
178
      </List>
179
    </div>
180
  );
181
};
182

183
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