• 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

80.82
/src/js/actions/monitorActions.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 Api, { apiUrl, headerNames } from '../api/general-api';
15
import * as DeviceConstants from '../constants/deviceConstants';
16
import * as MonitorConstants from '../constants/monitorConstants';
17
import { getDeviceFilters } from '../selectors';
18
import { commonErrorFallback, commonErrorHandler, setSnackbar } from './appActions';
19
import { convertDeviceListStateToFilters, getSearchEndpoint } from './deviceActions';
20

21
export const monitorApiUrlv1 = `${apiUrl.v1}/devicemonitor`;
190✔
22

23
const { page: defaultPage, perPage: defaultPerPage } = DeviceConstants.DEVICE_LIST_DEFAULTS;
190✔
24

25
const cutoffLength = 75;
190✔
26
const ellipsis = '...';
190✔
27

28
const longTextTrimmer = text => (text.length >= cutoffLength + ellipsis.length ? `${text.substring(0, cutoffLength + ellipsis.length)}${ellipsis}` : text);
190!
29

30
const sanitizeDeviceAlerts = alerts => alerts.map(alert => ({ ...alert, fullName: alert.name, name: longTextTrimmer(alert.name) }));
190✔
31

32
export const setAlertListState = selectionState => (dispatch, getState) =>
190✔
33
  Promise.resolve(
1✔
34
    dispatch({
35
      type: MonitorConstants.SET_ALERT_LIST_STATE,
36
      value: { ...getState().monitor.alerts.alertList, ...selectionState }
37
    })
38
  );
39

40
export const getDeviceAlerts =
41
  (id, config = {}) =>
190✔
42
  dispatch => {
2✔
43
    const { page = defaultPage, perPage = defaultPerPage, issuedBefore, issuedAfter, sortAscending = false } = config;
2✔
44
    const issued_after = issuedAfter ? `&issued_after=${issuedAfter}` : '';
2!
45
    const issued_before = issuedBefore ? `&issued_before=${issuedBefore}` : '';
2!
46
    return Api.get(`${monitorApiUrlv1}/devices/${id}/alerts?page=${page}&per_page=${perPage}${issued_after}${issued_before}&sort_ascending=${sortAscending}`)
2✔
UNCOV
47
      .catch(err => commonErrorHandler(err, `Retrieving device alerts for device ${id} failed:`, dispatch))
×
48
      .then(res =>
49
        Promise.all([
1✔
50
          dispatch({
51
            type: MonitorConstants.RECEIVE_DEVICE_ALERTS,
52
            deviceId: id,
53
            alerts: sanitizeDeviceAlerts(res.data)
54
          }),
55
          dispatch(setAlertListState({ total: Number(res.headers[headerNames.total]) }))
56
        ])
57
      );
58
  };
59

60
export const getLatestDeviceAlerts =
61
  (id, config = {}) =>
190✔
62
  dispatch => {
2✔
63
    const { page = defaultPage, perPage = 10 } = config;
2✔
64
    return Api.get(`${monitorApiUrlv1}/devices/${id}/alerts/latest?page=${page}&per_page=${perPage}`)
2✔
UNCOV
65
      .catch(err => commonErrorHandler(err, `Retrieving device alerts for device ${id} failed:`, dispatch))
×
66
      .then(res =>
67
        Promise.resolve(
1✔
68
          dispatch({
69
            type: MonitorConstants.RECEIVE_LATEST_DEVICE_ALERTS,
70
            deviceId: id,
71
            alerts: sanitizeDeviceAlerts(res.data)
72
          })
73
        )
74
      );
75
  };
76

77
export const getIssueCountsByType =
78
  (type, options = {}) =>
190✔
79
  (dispatch, getState) => {
3✔
80
    const state = getState();
3✔
81
    const { filters = getDeviceFilters(state), group, status, ...remainder } = options;
3✔
82
    const { applicableFilters: nonMonitorFilters, filterTerms } = convertDeviceListStateToFilters({
3✔
83
      ...remainder,
84
      filters,
85
      group,
86
      offlineThreshold: getState().app.offlineThreshold,
87
      selectedIssues: [type],
88
      status
89
    });
90
    return Api.post(getSearchEndpoint(state.app.features.hasReporting), {
3✔
91
      page: 1,
92
      per_page: 1,
93
      filters: filterTerms,
94
      attributes: [{ scope: 'identity', attribute: 'status' }]
95
    })
UNCOV
96
      .catch(err => commonErrorHandler(err, `Retrieving issue counts failed:`, dispatch, commonErrorFallback))
×
97
      .then(res => {
98
        const total = nonMonitorFilters.length ? state.monitor.issueCounts.byType[type].total : Number(res.headers[headerNames.total]);
3!
99
        const filtered = nonMonitorFilters.length ? Number(res.headers[headerNames.total]) : total;
3!
100
        if (total === state.monitor.issueCounts.byType[type].total && filtered === state.monitor.issueCounts.byType[type].filtered) {
3✔
101
          return Promise.resolve();
1✔
102
        }
103
        return Promise.resolve(
2✔
104
          dispatch({
105
            counts: { filtered, total },
106
            issueType: type,
107
            type: MonitorConstants.RECEIVE_DEVICE_ISSUE_COUNTS
108
          })
109
        );
110
      });
111
  };
112

113
export const getDeviceMonitorConfig = id => dispatch =>
190✔
114
  Api.get(`${monitorApiUrlv1}/devices/${id}/config`)
2✔
UNCOV
115
    .catch(err => commonErrorHandler(err, `Retrieving device monitor config for device ${id} failed:`, dispatch))
×
116
    .then(({ data }) => {
117
      let tasks = [
1✔
118
        dispatch({
119
          type: MonitorConstants.RECEIVE_DEVICE_MONITOR_CONFIG,
120
          device: { id, monitors: data }
121
        })
122
      ];
123
      tasks.push(Promise.resolve(data));
1✔
124
      return Promise.all(tasks);
1✔
125
    });
126

127
export const changeNotificationSetting =
128
  (enabled, channel = MonitorConstants.alertChannels.email) =>
190✔
129
  dispatch => {
1✔
130
    return Api.put(`${monitorApiUrlv1}/settings/global/channel/alerts/${channel}/status`, { enabled })
1✔
UNCOV
131
      .catch(err => commonErrorHandler(err, `${enabled ? 'En' : 'Dis'}abling  ${channel} alerts failed:`, dispatch))
×
132
      .then(() =>
133
        Promise.all([
1✔
134
          dispatch({
135
            type: MonitorConstants.CHANGE_ALERT_CHANNEL,
136
            channel,
137
            enabled
138
          }),
139
          dispatch(setSnackbar(`Successfully ${enabled ? 'en' : 'dis'}abled ${channel} alerts`, 5000))
1!
140
        ])
141
      );
142
  };
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