• 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

85.71
/src/js/components/dashboard/dashboard.js
1
// Copyright 2015 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 } from 'react';
15
import { connect } from 'react-redux';
16
import { useNavigate } from 'react-router-dom';
17

18
import { makeStyles } from 'tss-react/mui';
19

20
import { setSnackbar } from '../../actions/appActions';
21
import { TIMEOUTS } from '../../constants/appConstants';
22
import { DEPLOYMENT_ROUTES } from '../../constants/deploymentConstants';
23
import { onboardingSteps } from '../../constants/onboardingConstants';
24
import { getOnboardingState } from '../../selectors';
25
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
26
import Loader from '../common/loader';
27
import Deployments from './deployments';
28
import Devices from './devices';
29
import SoftwareDistribution from './software-distribution';
30

31
const useStyles = makeStyles()(theme => ({
53✔
32
  board: {
33
    columnGap: theme.spacing(6),
34
    display: 'flex',
35
    flexWrap: 'wrap',
36
    minHeight: '80vh'
37
  },
38
  left: {
39
    flexGrow: 1,
40
    flexBasis: 0,
41
    minWidth: '60vw',
42
    display: 'flex',
43
    position: 'relative',
44
    rowGap: theme.spacing(6),
45
    flexDirection: 'column',
46
    [theme.breakpoints.up('xl')]: { minWidth: '50vw' }
47
  },
48
  right: {
49
    flexGrow: 1,
50
    minWidth: 400,
51
    border: 'none',
52
    paddingLeft: 0,
53
    paddingTop: 0,
54
    '.deployments .dashboard > h4': { marginTop: theme.spacing(6) },
55
    '.deployments .dashboard > h4.margin-top-none': { marginTop: 0 },
56
    [theme.breakpoints.up('xl')]: {
57
      borderLeft: `1px solid ${theme.palette.grey[500]}`,
58
      marginTop: theme.spacing(-2),
59
      paddingLeft: theme.spacing(6),
60
      paddingTop: theme.spacing(2),
61
      '.deployments .dashboard > h4': { marginTop: 0 }
62
    }
63
  },
64
  row: { flexWrap: 'wrap', maxWidth: '85vw' }
65
}));
66

67
export const Dashboard = ({ currentUser, onboardingState, setSnackbar }) => {
4✔
68
  const timer = useRef();
85✔
69
  const { classes } = useStyles();
85✔
70
  const navigate = useNavigate();
85✔
71

72
  useEffect(() => {
85✔
73
    if (!currentUser || !onboardingState.showTips) {
17✔
74
      return;
15✔
75
    }
76
    clearTimeout(timer.current);
2✔
77
    timer.current = setTimeout(() => {
2✔
78
      const notification = getOnboardingComponentFor(onboardingSteps.ONBOARDING_START, onboardingState, { setSnackbar });
×
79
      !!notification && setSnackbar('open', TIMEOUTS.refreshDefault, '', notification, () => {}, true);
×
80
    }, 400);
81
  }, [currentUser, JSON.stringify(onboardingState)]);
82
  useEffect(() => {
85✔
83
    return () => {
10✔
84
      clearTimeout(timer.current);
10✔
85
    };
86
  }, []);
87

88
  const handleClick = params => {
85✔
89
    let redirect = params.route;
3✔
90
    if (params.route === 'deployments') {
3✔
91
      let query = params.open ? ['open=true'] : [];
1!
92
      params.id ? query.push(`id=${params.id}`) : undefined;
1!
93
      redirect = `/deployments/${params.tab || DEPLOYMENT_ROUTES.active.key}?${query.join('&')}`;
1✔
94
    }
95
    navigate(redirect);
3✔
96
  };
97

98
  return (
85✔
99
    <>
100
      <h4 className="margin-left-small">Dashboard</h4>
101
      {currentUser ? (
85✔
102
        <div className={classes.board}>
103
          <div className={classes.left}>
104
            <Devices clickHandle={handleClick} />
105
            <SoftwareDistribution />
106
          </div>
107
          <Deployments className={classes.right} clickHandle={handleClick} />
108
        </div>
109
      ) : (
110
        <div className="flexbox centered" style={{ height: '75%' }}>
111
          <Loader show={true} />
112
        </div>
113
      )}
114
    </>
115
  );
116
};
117

118
const actionCreators = { setSnackbar };
4✔
119

120
const mapStateToProps = state => {
4✔
121
  return {
435✔
122
    currentUser: state.users.currentUser,
123
    onboardingState: getOnboardingState(state)
124
  };
125
};
126

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