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

mendersoftware / gui / 1081664682

22 Nov 2023 02:11PM UTC coverage: 82.798% (-17.2%) from 99.964%
1081664682

Pull #4214

gitlab-ci

tranchitella
fix: Fixed the infinite page redirects when the back button is pressed

Remove the location and navigate from the useLocationParams.setValue callback
dependencies as they change the set function that is presented in other
useEffect dependencies. This happens when the back button is clicked, which
leads to the location changing infinitely.

Changelog: Title
Ticket: MEN-6847
Ticket: MEN-6796

Signed-off-by: Ihor Aleksandrychiev <ihor.aleksandrychiev@northern.tech>
Signed-off-by: Fabio Tranchitella <fabio.tranchitella@northern.tech>
Pull Request #4214: fix: Fixed the infinite page redirects when the back button is pressed

4319 of 6292 branches covered (0.0%)

8332 of 10063 relevant lines covered (82.8%)

191.0 hits per line

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

81.48
/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 { useDispatch, useSelector } 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 { getCurrentUser, 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 => ({
8✔
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 = () => {
3✔
68
  const timer = useRef();
9✔
69
  const { classes } = useStyles();
8✔
70
  const navigate = useNavigate();
8✔
71
  const dispatch = useDispatch();
8✔
72
  const currentUser = useSelector(getCurrentUser);
8✔
73
  const onboardingState = useSelector(getOnboardingState);
8✔
74

75
  useEffect(() => {
8✔
76
    if (!currentUser || !onboardingState.showTips) {
6!
77
      return;
6✔
78
    }
79
    clearTimeout(timer.current);
×
80
    timer.current = setTimeout(() => {
×
81
      const notification = getOnboardingComponentFor(onboardingSteps.ONBOARDING_START, onboardingState, {
×
82
        setSnackbar: (...args) => dispatch(setSnackbar(...args))
×
83
      });
84
      !!notification && dispatch(setSnackbar('open', TIMEOUTS.refreshDefault, '', notification, () => {}, true));
×
85
    }, TIMEOUTS.debounceDefault);
86
    // eslint-disable-next-line react-hooks/exhaustive-deps
87
  }, [currentUser, dispatch, JSON.stringify(onboardingState)]);
88

89
  useEffect(() => {
8✔
90
    return () => {
6✔
91
      clearTimeout(timer.current);
6✔
92
    };
93
  }, []);
94

95
  const handleClick = params => {
8✔
96
    let redirect = params.route;
3✔
97
    if (params.route === 'deployments') {
3✔
98
      let query = params.open ? ['open=true'] : [];
1!
99
      params.id ? query.push(`id=${params.id}`) : undefined;
1!
100
      redirect = `/deployments/${params.tab || DEPLOYMENT_ROUTES.active.key}?${query.join('&')}`;
1✔
101
    }
102
    navigate(redirect);
3✔
103
  };
104

105
  return (
8✔
106
    <>
107
      <h4 className="margin-left-small">Dashboard</h4>
108
      {currentUser ? (
8!
109
        <div className={classes.board}>
110
          <div className={classes.left}>
111
            <Devices clickHandle={handleClick} />
112
            <SoftwareDistribution />
113
          </div>
114
          <Deployments className={classes.right} clickHandle={handleClick} />
115
        </div>
116
      ) : (
117
        <div className="flexbox centered" style={{ height: '75%' }}>
118
          <Loader show={true} />
119
        </div>
120
      )}
121
    </>
122
  );
123
};
124

125
export default 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