• 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

78.57
/src/js/components/helptips/onboardingcompletetip.js
1
// Copyright 2019 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

17
import { CheckCircle as CheckCircleIcon } from '@mui/icons-material';
18
import { Button } from '@mui/material';
19
import { withStyles } from 'tss-react/mui';
20

21
import { getDeviceById, getDevicesByStatus } from '../../actions/deviceActions';
22
import { setOnboardingComplete } from '../../actions/onboardingActions';
23
import * as DeviceConstants from '../../constants/deviceConstants';
24
import { onboardingSteps } from '../../constants/onboardingConstants';
25
import { getDemoDeviceAddress } from '../../selectors';
26
import Loader from '../common/loader';
27
import { MenderTooltipClickable } from '../common/mendertooltip';
28

29
export const CompletionButton = withStyles(Button, ({ palette }) => ({
183✔
30
  root: {
31
    backgroundColor: palette.background.default,
32
    '&:hover': {
33
      backgroundColor: palette.background.default
34
    }
35
  }
36
}));
37

38
export const OnboardingCompleteTip = ({ anchor, targetUrl }) => {
183✔
39
  const timer = useRef();
1✔
40
  const dispatch = useDispatch();
1✔
41
  const url = useSelector(getDemoDeviceAddress) || targetUrl;
1!
42

43
  useEffect(() => {
1✔
44
    dispatch(getDevicesByStatus(DeviceConstants.DEVICE_STATES.accepted))
1✔
45
      .then(tasks => {
46
        return Promise.all(tasks[tasks.length - 1].deviceAccu.ids.map(id => dispatch(getDeviceById(id))));
×
47
      })
48
      .finally(() => {
49
        timer.current = setTimeout(() => dispatch(setOnboardingComplete(true)), 120000);
×
50
      });
51
    return () => {
1✔
52
      dispatch(setOnboardingComplete(true));
1✔
53
      clearTimeout(timer.current);
1✔
54
    };
55
  }, [dispatch]);
56

57
  return (
1✔
58
    <MenderTooltipClickable
59
      className="tooltip onboard-icon onboard-tip"
60
      id={onboardingSteps.DEPLOYMENTS_PAST_COMPLETED}
61
      onboarding
62
      startOpen
63
      style={anchor}
64
      PopperProps={{ style: { marginLeft: -30, marginTop: -20 } }}
65
      title={
66
        <div className="content">
67
          <b>
68
            <p>Fantastic! You completed your first deployment!</p>
69
            <p>Your deployment is finished and your device is now running the updated software.</p>
70
          </b>
71
          <div className="margin-bottom-small margin-top-small">
72
            {!url ? (
1!
73
              <Loader show={true} />
74
            ) : (
75
              <CompletionButton className="button" variant="text" href={`${url}/index.html?source=${encodeURIComponent(window.location)}`} target="_blank">
76
                {`Go to ${url}`}
77
              </CompletionButton>
78
            )}
79
            <br />
80
            and you should see the demo web application actually being run on the device.
81
          </div>
82
          <p>NOTE: if you have local network restrictions, you may need to check them if you have difficulty loading the page.</p>
83
          <div className="flexbox">
84
            <div style={{ flexGrow: 1 }} />
85
            <Button variant="contained" color="secondary" onClick={() => dispatch(setOnboardingComplete(true))}>
×
86
              Close
87
            </Button>
88
          </div>
89
        </div>
90
      }
91
    >
92
      <CheckCircleIcon />
93
    </MenderTooltipClickable>
94
  );
95
};
96

97
export default OnboardingCompleteTip;
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