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

mendersoftware / gui / 944676341

pending completion
944676341

Pull #3875

gitlab-ci

mzedel
chore: aligned snapshots with updated design

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

4469 of 6446 branches covered (69.33%)

230 of 266 new or added lines in 43 files covered. (86.47%)

1712 existing lines in 161 files now uncovered.

8406 of 10170 relevant lines covered (82.65%)

196.7 hits per line

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

71.64
/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, severityMap } from './notifications';
31

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

34
export const DeviceMonitorsMissingNote = () => (
10✔
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 }) => {
10✔
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].icon}
48
      <div className="key muted">
49
        <b>{alert.name}</b>
50
      </div>
51
      <div>{alert.level}</div>
52
      <Time value={alert.timestamp} />
UNCOV
53
      {(lines.length || description) && <a onClick={() => onDetailsClick(alert)}>view {lines.length ? 'log' : 'details'}</a>}
×
54
    </div>
55
  );
56
};
57

58
const paginationCutoff = defaultPerPage;
10✔
59
export const DeviceMonitoring = ({ device, onDetailsClick }) => {
10✔
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
  }, [device.id, pageNo, pageLength]);
70

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

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

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

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

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

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

145
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