• 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

93.1
/src/js/components/devices/device-details/monitoring.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, { useEffect, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
import { useTheme } from '@mui/material/styles';
18

19
import { getDeviceAlerts, setAlertListState } from '../../../actions/monitorActions';
20
import { BENEFITS } from '../../../constants/appConstants';
21
import { DEVICE_LIST_DEFAULTS } from '../../../constants/deviceConstants';
22
import { getOfflineThresholdSettings } from '../../../selectors';
23
import DocsLink from '../../common/docslink';
24
import EnterpriseNotification from '../../common/enterpriseNotification';
25
import Pagination from '../../common/pagination';
26
import Time from '../../common/time';
27
import MonitorDetailsDialog from '../dialogs/monitordetailsdialog';
28
import { DeviceConnectionNote } from './connection';
29
import DeviceDataCollapse from './devicedatacollapse';
30
import { DeviceOfflineHeaderNotification, NoAlertsHeaderNotification, monitoringSeverities, severityMap } from './notifications';
31

32
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
9✔
33

34
export const DeviceMonitorsMissingNote = () => (
9✔
35
  <DeviceConnectionNote>
1✔
36
    No alert monitor is currently configured for this device.
37
    <br />
38
    Please <DocsLink path="add-ons/monitor" title="see the documentation" /> for a description on how to configure different kinds of monitors.
39
  </DeviceConnectionNote>
40
);
41

42
const MonitoringAlert = ({ alert, onDetailsClick, style }) => {
9✔
43
  const { description, lines_before = [], lines_after = [], line_matching = '' } = alert.subject.details;
2✔
44
  const lines = [...lines_before, line_matching, ...lines_after].filter(i => i);
2✔
45
  return (
2✔
46
    <div className="monitoring-alert column-data" style={style}>
47
      {(severityMap[alert.level] ?? severityMap[monitoringSeverities.UNKNOWN]).icon}
2!
48
      <div className="key muted">
49
        <b>{alert.name}</b>
50
      </div>
51
      <div>{alert.level}</div>
52
      <Time value={alert.timestamp} />
53
      {(lines.length || description) && <a onClick={() => onDetailsClick(alert)}>view {lines.length ? 'log' : 'details'}</a>}
×
54
    </div>
55
  );
56
};
57

58
const paginationCutoff = defaultPerPage;
9✔
59
export const DeviceMonitoring = ({ device, onDetailsClick }) => {
9✔
60
  const theme = useTheme();
1✔
61
  const { alerts = [], latest: latestAlerts = [] } = useSelector(state => state.monitor.alerts.byDeviceId[device.id]) ?? {};
2!
62
  const alertListState = useSelector(state => state.monitor.alerts.alertList) ?? {};
2!
63
  const offlineThresholdSettings = useSelector(getOfflineThresholdSettings);
1✔
64
  const dispatch = useDispatch();
1✔
65
  const { page: pageNo = defaultPage, perPage: pageLength = defaultPerPage, total: alertCount } = alertListState;
1!
66

67
  useEffect(() => {
1✔
68
    dispatch(getDeviceAlerts(device.id, alertListState));
1✔
69
    // eslint-disable-next-line react-hooks/exhaustive-deps
70
  }, [device.id, dispatch, pageNo, pageLength]);
71

72
  const onChangePage = page => dispatch(setAlertListState({ page }));
1✔
73

74
  const onChangeRowsPerPage = perPage => dispatch(setAlertListState({ page: 1, perPage }));
1✔
75

76
  const { monitors = [], isOffline, updated_ts = '' } = device;
1!
77
  const hasMonitorsDefined = !!(monitors.length || alerts.length || latestAlerts.length);
1!
78

79
  return (
1✔
80
    <DeviceDataCollapse
81
      header={
82
        hasMonitorsDefined || isOffline ? (
2!
83
          <>
84
            {hasMonitorsDefined && !latestAlerts.length && <NoAlertsHeaderNotification />}
2!
85
            {latestAlerts.map(alert => (
86
              <MonitoringAlert alert={alert} key={alert.id} onDetailsClick={onDetailsClick} style={{ marginBottom: theme.spacing() }} />
1✔
87
            ))}
88
            {isOffline && <DeviceOfflineHeaderNotification offlineThresholdSettings={offlineThresholdSettings} />}
1!
89
          </>
90
        ) : (
91
          <DeviceMonitorsMissingNote />
92
        )
93
      }
94
      isAddOn
95
      title={
96
        <div className="flexbox center-aligned">
97
          <h4 className="margin-bottom-small margin-right">Monitoring</h4>
98
          {!!monitors.length && <Time className="muted" value={updated_ts} />}
1!
99
          <EnterpriseNotification className="margin-left-small" id={BENEFITS.deviceMonitor.id} />
100
        </div>
101
      }
102
    >
103
      {alerts.length ? (
1!
104
        <>
105
          <div>
106
            <h4 className="muted">Alert history</h4>
107
            {alerts.map(alert => (
108
              <MonitoringAlert alert={alert} key={alert.id} onDetailsClick={onDetailsClick} />
1✔
109
            ))}
110
          </div>
111
          <div className="flexbox margin-top">
112
            {alertCount > paginationCutoff && (
2✔
113
              <Pagination
114
                className="margin-top-none"
115
                count={alertCount}
116
                rowsPerPage={pageLength}
117
                onChangeRowsPerPage={onChangeRowsPerPage}
118
                page={pageNo}
119
                onChangePage={onChangePage}
120
              />
121
            )}
122
          </div>
123
        </>
124
      ) : (
125
        hasMonitorsDefined && (
×
126
          <p className="muted margin-left-large" style={{ fontSize: 'larger' }}>
127
            There are currently no issues reported
128
          </p>
129
        )
130
      )}
131
    </DeviceDataCollapse>
132
  );
133
};
134

135
export const MonitoringTab = ({ device }) => {
9✔
136
  const [monitorDetails, setMonitorDetails] = useState();
1✔
137

138
  return (
1✔
139
    <>
140
      <DeviceMonitoring device={device} onDetailsClick={setMonitorDetails} />
141
      <MonitorDetailsDialog alert={monitorDetails} onClose={() => setMonitorDetails()} />
×
142
    </>
143
  );
144
};
145

146
export default MonitoringTab;
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