• 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

80.0
/src/js/components/devices/device-details/authstatus.js
1
// Copyright 2021 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, { useRef } from 'react';
15
import { useSelector } from 'react-redux';
16

17
import { Block as BlockIcon, CheckCircle as CheckCircleIcon, Check as CheckIcon } from '@mui/icons-material';
18
import { Chip, Icon } from '@mui/material';
19

20
import pendingIcon from '../../../../assets/img/pending_status.png';
21
import { DEVICE_STATES } from '../../../constants/deviceConstants';
22
import { onboardingSteps } from '../../../constants/onboardingConstants';
23
import { getOnboardingState } from '../../../selectors';
24
import { getOnboardingComponentFor } from '../../../utils/onboardingmanager';
25
import { HELPTOOLTIPS, MenderHelpTooltip } from '../../helptips/helptooltips';
26
import Authsets from './authsets/authsets';
27
import DeviceDataCollapse from './devicedatacollapse';
28

29
const iconStyle = { margin: 12 };
10✔
30

31
const states = {
10✔
32
  default: <Icon style={iconStyle} component="img" src={pendingIcon} />,
33
  pending: <Icon style={iconStyle} component="img" src={pendingIcon} />,
34
  accepted: <CheckCircleIcon className="green" style={iconStyle} />,
35
  rejected: <BlockIcon className="red" style={iconStyle} />,
36
  preauthorized: <CheckIcon style={iconStyle} />
37
};
38

39
export const AuthStatus = ({ decommission, device }) => {
10✔
40
  const listRef = useRef();
2✔
41
  const statusRef = useRef();
2✔
42
  const onboardingState = useSelector(getOnboardingState);
2✔
43
  const { auth_sets = [], status = DEVICE_STATES.accepted } = device;
2!
44

45
  let hasPending = '';
2✔
46
  if (status === DEVICE_STATES.accepted && auth_sets.length > 1) {
2✔
47
    hasPending = auth_sets.reduce((accu, set) => {
1✔
48
      return set.status === DEVICE_STATES.pending ? 'This device has a pending authentication set' : accu;
2✔
49
    }, hasPending);
50
  }
51

52
  const statusIcon = states[status] ? states[status] : states.default;
2!
53
  const requestNotification = !!hasPending && <Chip size="small" label="new request" color="primary" />;
2✔
54
  let onboardingComponent;
55
  if (listRef.current?.querySelector('.action-buttons')) {
2!
56
    const anchor = {
×
57
      top: listRef.current.offsetTop + listRef.current.offsetHeight,
58
      left: listRef.current.offsetLeft + listRef.current.querySelector('.action-buttons').offsetLeft + 15
59
    };
60
    onboardingComponent = getOnboardingComponentFor(
×
61
      onboardingSteps.DEVICES_PENDING_ACCEPTING_ONBOARDING,
62
      onboardingState,
63
      { anchor, place: 'top' },
64
      onboardingComponent
65
    );
66
  }
67
  if (statusRef.current) {
2!
68
    const anchor = {
×
69
      top: statusRef.current.offsetTop + statusRef.current.offsetHeight,
70
      left: statusRef.current.offsetLeft + statusRef.current.offsetWidth / 2
71
    };
72
    onboardingComponent = getOnboardingComponentFor(
×
73
      onboardingSteps.DEVICES_ACCEPTED_ONBOARDING,
74
      onboardingState,
75
      { anchor, place: 'top' },
76
      onboardingComponent
77
    );
78
  }
79
  return (
2✔
80
    <DeviceDataCollapse
81
      title={
82
        <div className="flexbox center-aligned">
83
          <h4>Authentication status</h4>
84
          <div className="flexbox center-aligned margin-left margin-right" ref={statusRef}>
85
            <div className="capitalized">{status}</div>
86
            {statusIcon}
87
          </div>
88
          {requestNotification}
89
          {status === DEVICE_STATES.pending && <MenderHelpTooltip id={HELPTOOLTIPS.authButton.id} style={{ marginTop: 5 }} />}
2!
90
        </div>
91
      }
92
    >
93
      <Authsets decommission={decommission} device={device} listRef={listRef} />
94
      {onboardingComponent}
95
    </DeviceDataCollapse>
96
  );
97
};
98

99
export default AuthStatus;
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