• 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

91.67
/src/js/components/dashboard/deployments.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, useState } from 'react';
15
import { connect } from 'react-redux';
16
import { Link } from 'react-router-dom';
17

18
import { setSnackbar } from '../../actions/appActions';
19
import { getDeploymentsByStatus } from '../../actions/deploymentActions';
20
import { DEPLOYMENT_ROUTES, DEPLOYMENT_STATES, deploymentDisplayStates } from '../../constants/deploymentConstants';
21
import { onboardingSteps } from '../../constants/onboardingConstants';
22
import { DEPLOYMENT_CUTOFF, getIdAttribute, getOnboardingState, getRecentDeployments, getUserCapabilities } from '../../selectors';
23
import { getOnboardingComponentFor } from '../../utils/onboardingmanager';
24
import useWindowSize from '../../utils/resizehook';
25
import { clearAllRetryTimers, setRetryTimer } from '../../utils/retrytimer';
26
import Loader from '../common/loader';
27
import { BaseDeploymentsWidget, CompletedDeployments } from './widgets/deployments';
28
import RedirectionWidget from './widgets/redirectionwidget';
29

30
const refreshDeploymentsLength = 30000;
5✔
31

32
// we need to exclude the scheduled state here as the os version is not able to process these and would prevent the dashboard from loading
33
const stateMap = {
5✔
34
  [DEPLOYMENT_STATES.pending]: BaseDeploymentsWidget,
35
  [DEPLOYMENT_STATES.inprogress]: BaseDeploymentsWidget,
36
  [DEPLOYMENT_STATES.finished]: CompletedDeployments
37
};
38

39
export const Deployments = ({
5✔
40
  canDeploy,
41
  className = '',
1✔
42
  clickHandle,
43
  deployments,
44
  deploymentsCount,
45
  devicesById,
46
  getDeploymentsByStatus,
47
  idAttribute,
48
  onboardingState,
49
  setSnackbar
50
}) => {
51
  const [loading, setLoading] = useState(!deploymentsCount);
313✔
52
  // eslint-disable-next-line no-unused-vars
53
  const size = useWindowSize();
313✔
54
  const deploymentsRef = useRef();
313✔
55
  const timer = useRef();
313✔
56

57
  useEffect(() => {
313✔
58
    clearAllRetryTimers(setSnackbar);
10✔
59
    clearInterval(timer.current);
10✔
60
    timer.current = setInterval(getDeployments, refreshDeploymentsLength);
10✔
61
    getDeployments();
10✔
62
    return () => {
10✔
63
      clearInterval(timer.current);
10✔
64
      clearAllRetryTimers(setSnackbar);
10✔
65
    };
66
  }, []);
67

68
  const getDeployments = () =>
313✔
69
    Promise.all(Object.keys(stateMap).map(status => getDeploymentsByStatus(status, 1, DEPLOYMENT_CUTOFF)))
210✔
70
      .catch(err => setRetryTimer(err, 'deployments', `Couldn't load deployments.`, refreshDeploymentsLength, setSnackbar))
×
71
      .finally(() => setLoading(false));
69✔
72

73
  let onboardingComponent;
74
  if (deploymentsRef.current) {
313✔
75
    const anchor = {
246✔
76
      top: deploymentsRef.current.offsetTop + deploymentsRef.current.offsetHeight,
77
      left: deploymentsRef.current.offsetLeft + deploymentsRef.current.offsetWidth / 2
78
    };
79
    onboardingComponent = getOnboardingComponentFor(onboardingSteps.DEPLOYMENTS_PAST_COMPLETED, onboardingState, { anchor });
246✔
80
  }
81
  return (
313✔
82
    <div className={`${className} deployments`}>
83
      {loading ? (
313✔
84
        <Loader show={loading} fade={true} />
85
      ) : (
86
        <div className="dashboard flexbox column" ref={deploymentsRef} style={{ gridTemplateColumns: '1fr', rowGap: 10 }}>
87
          <h4 className={`${deploymentsCount ? 'margin-bottom-none' : 'margin-top-none'} margin-left-small`}>
259✔
88
            {deploymentsCount ? 'Recent deployments' : 'Deployments'}
259✔
89
          </h4>
90
          {deploymentsCount ? (
259✔
91
            <>
92
              {Object.entries(stateMap).reduce((accu, [key, Component]) => {
93
                if (!deployments[key]) {
771!
94
                  return accu;
×
95
                }
96
                accu.push(
771✔
97
                  <React.Fragment key={key}>
98
                    <h5 className="margin-bottom-none">{deploymentDisplayStates[key]}</h5>
99
                    <Component deployments={deployments[key]} devicesById={devicesById} idAttribute={idAttribute} state={key} onClick={clickHandle} />
100
                  </React.Fragment>
101
                );
102
                return accu;
771✔
103
              }, [])}
104
              <Link className="margin-top" to="/deployments">
105
                See all deployments
106
              </Link>
107
            </>
108
          ) : (
109
            canDeploy && (
4✔
110
              <RedirectionWidget
111
                content="Create a new deployment to update a group of devices"
112
                onClick={() => clickHandle({ route: `${DEPLOYMENT_ROUTES.active.route}?open=true` })}
×
113
              />
114
            )
115
          )}
116
        </div>
117
      )}
118
      {onboardingComponent}
119
    </div>
120
  );
121
};
122

123
const actionCreators = { getDeploymentsByStatus, setSnackbar };
5✔
124

125
const mapStateToProps = state => {
5✔
126
  const { canDeploy } = getUserCapabilities(state);
151✔
127
  const { total: deploymentsCount, ...deployments } = getRecentDeployments(state);
151✔
128
  return {
151✔
129
    canDeploy,
130
    deploymentsCount,
131
    deployments,
132
    devicesById: state.devices.byId,
133
    idAttribute: getIdAttribute(state),
134
    onboardingState: getOnboardingState(state)
135
  };
136
};
137

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