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

mendersoftware / gui / 963002358

pending completion
963002358

Pull #3870

gitlab-ci

mzedel
chore: cleaned up left over onboarding tooltips & aligned with updated design

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3870: MEN-5413

4348 of 6319 branches covered (68.81%)

95 of 122 new or added lines in 24 files covered. (77.87%)

1734 existing lines in 160 files now uncovered.

8174 of 9951 relevant lines covered (82.14%)

178.12 hits per line

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

71.01
/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 { getOfflineThresholdSettings } from '../../../selectors';
22
import DocsLink from '../../common/docslink';
23
import Pagination from '../../common/pagination';
24
import Time from '../../common/time';
25
import MonitorDetailsDialog from '../dialogs/monitordetailsdialog';
26
import { DeviceConnectionNote } from './connection';
27
import DeviceDataCollapse from './devicedatacollapse';
28
import { DeviceOfflineHeaderNotification, NoAlertsHeaderNotification, monitoringSeverities, severityMap } from './notifications';
29

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

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

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

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

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

70
  const onChangePage = page => dispatch(setAlertListState({ page }));
1✔
71

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

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

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

132
export const MonitoringTab = ({ device }) => {
10✔
133
  const [monitorDetails, setMonitorDetails] = useState();
1✔
134

135
  return (
1✔
136
    <>
137
      <DeviceMonitoring device={device} onDetailsClick={setMonitorDetails} />
UNCOV
138
      <MonitorDetailsDialog alert={monitorDetails} onClose={() => setMonitorDetails()} />
×
139
    </>
140
  );
141
};
142

143
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