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

mendersoftware / gui / 901187442

pending completion
901187442

Pull #3795

gitlab-ci

mzedel
feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

Ticket: None
Changelog: None
Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3795: feat: increased chances of adopting our intended navigation patterns instead of unsupported browser navigation

4389 of 6365 branches covered (68.96%)

5 of 5 new or added lines in 1 file covered. (100.0%)

1729 existing lines in 165 files now uncovered.

8274 of 10019 relevant lines covered (82.58%)

144.86 hits per line

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

72.06
/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 { DEVICE_LIST_DEFAULTS } from '../../../constants/deviceConstants';
21
import { getDocsVersion, getOfflineThresholdSettings } from '../../../selectors';
22
import Pagination from '../../common/pagination';
23
import Time from '../../common/time';
24
import MonitorDetailsDialog from '../dialogs/monitordetailsdialog';
25
import { DeviceConnectionNote } from './connection';
26
import DeviceDataCollapse from './devicedatacollapse';
27
import { DeviceOfflineHeaderNotification, NoAlertsHeaderNotification, severityMap } from './notifications';
28

29
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
10✔
30

31
export const DeviceMonitorsMissingNote = ({ docsVersion }) => (
10✔
32
  <DeviceConnectionNote>
1✔
33
    No alert monitor is currently configured for this device.
34
    <br />
35
    Please{' '}
36
    <a target="_blank" rel="noopener noreferrer" href={`https://docs.mender.io/${docsVersion}add-ons/monitor`}>
37
      see the documentation
38
    </a>{' '}
39
    for a description on how to configure different kinds of monitors.
40
  </DeviceConnectionNote>
41
);
42

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

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

69
  useEffect(() => {
1✔
70
    dispatch(getDeviceAlerts(device.id, alertListState));
1✔
71
  }, [device.id, pageNo, pageLength]);
72

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

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

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

80
  return (
1✔
81
    <DeviceDataCollapse
82
      header={
83
        hasMonitorsDefined || isOffline ? (
2!
84
          <>
85
            {hasMonitorsDefined && !latestAlerts.length && <NoAlertsHeaderNotification />}
2!
86
            {latestAlerts.map(alert => (
87
              <MonitoringAlert alert={alert} key={alert.id} onDetailsClick={onDetailsClick} style={{ marginBottom: theme.spacing() }} />
1✔
88
            ))}
89
            {isOffline && <DeviceOfflineHeaderNotification offlineThresholdSettings={offlineThresholdSettings} />}
1!
90
          </>
91
        ) : (
92
          <DeviceMonitorsMissingNote docsVersion={docsVersion} />
93
        )
94
      }
95
      isAddOn
96
      title={
97
        <div className="flexbox center-aligned">
98
          <h4 className="margin-bottom-small margin-right">Monitoring</h4>
99
          {!!monitors.length && <Time className="muted" value={updated_ts} />}
1!
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 }) => {
10✔
136
  const [monitorDetails, setMonitorDetails] = useState();
1✔
137

138
  return (
1✔
139
    <>
140
      <DeviceMonitoring device={device} onDetailsClick={setMonitorDetails} />
UNCOV
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