• 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.55
/src/js/components/settings/webhooks/activity.js
1
// Copyright 2022 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, useMemo, useState } from 'react';
15

16
// material ui
17
import { ArrowDropDown as ArrowDropDownIcon, ArrowDropUp as ArrowDropUpIcon, Circle as CircleIcon } from '@mui/icons-material';
18
import { Accordion, AccordionDetails, AccordionSummary, accordionClasses } from '@mui/material';
19
import { accordionSummaryClasses } from '@mui/material/AccordionSummary';
20
import { makeStyles } from 'tss-react/mui';
21

22
import { DEVICE_LIST_DEFAULTS } from '../../../constants/deviceConstants';
23
import { toggle } from '../../../helpers';
24
import Pagination from '../../common/pagination';
25
import Time from '../../common/time';
26

27
const useStyles = makeStyles()(theme => ({
5✔
28
  activityList: {
29
    display: 'flexbox',
30
    flexDirection: 'column',
31
    ['.header']: {
32
      padding: `0px ${theme.spacing(2)}`,
33
      marginBottom: theme.spacing()
34
    },
35
    [`.header, .${accordionSummaryClasses.content}`]: {
36
      display: 'grid',
37
      gridTemplateColumns: '1fr 2fr 1fr 50px'
38
    },
39
    [`.${accordionSummaryClasses.content}`]: {
40
      cursor: 'pointer',
41
      [`&>time, &>.trigger-type`]: {
42
        color: theme.palette.secondary.main
43
      },
44
      [`&>:last-child`]: {
45
        paddingRight: 'initial'
46
      }
47
    },
48
    [`.${accordionClasses.root}`]: {
49
      backgroundColor: theme.palette.background.default
50
    }
51
  },
52
  divider: { marginTop: theme.spacing(), marginBottom: theme.spacing() }
53
}));
54

55
const triggerMap = {
5✔
56
  'device-decommissioned': 'Device decommissioned',
57
  'device-provisioned': 'Device provisioned',
58
  'device-status-changed': 'Device status updated'
59
};
60

61
const iconStyles = {
5✔
62
  status: { fontSize: 12, marginRight: 8 },
63
  dropDown: { justifySelf: 'right', marginRight: 8 }
64
};
65

66
const DeliveryStatus = ({ entry, webhook = {} }) => {
5✔
67
  const { delivery_statuses = [] } = entry;
2!
68

69
  const status = useMemo(() => {
2✔
70
    const status = delivery_statuses.find(status => status.integration_id === webhook.id) ?? delivery_statuses[0];
2✔
71
    if (status) {
2!
72
      return { code: status.status_code, signal: status.success ? 'green' : 'red' };
2!
73
    }
74
    return { code: 418, signal: 'disabled' };
×
75
    // eslint-disable-next-line react-hooks/exhaustive-deps
76
  }, [JSON.stringify(delivery_statuses), webhook.id]);
77

78
  return (
2✔
79
    <div className="flexbox center-aligned">
80
      <CircleIcon className={status.signal} style={iconStyles.status} />
81
      <div className={status.code >= 400 ? 'muted' : ''}>{status.code}</div>
2!
82
    </div>
83
  );
84
};
85

86
const columns = [
5✔
87
  { key: 'created_ts', title: 'Time', render: ({ entry }) => <Time value={entry.time} /> },
2✔
88
  { key: 'trigger', title: 'Event trigger', render: ({ entry }) => <div className="trigger-type">{triggerMap[entry.type] ?? entry.type}</div> },
2!
89
  { key: 'status', title: 'Status', render: ({ entry, webhook }) => <DeliveryStatus entry={entry} webhook={webhook} /> },
2✔
90
  {
91
    key: 'details',
92
    title: 'Details',
93
    render: ({ isExpanded }) => (isExpanded ? <ArrowDropUpIcon style={iconStyles.dropDown} /> : <ArrowDropDownIcon style={iconStyles.dropDown} />)
2!
94
  }
95
];
96

97
const ListItem = ({ entry = {}, webhook }) => {
5!
98
  const [isExpanded, setIsExpanded] = useState(false);
2✔
99
  const { data = {} } = entry;
2!
100

101
  return (
2✔
102
    <Accordion square expanded={isExpanded}>
103
      <AccordionSummary onClick={() => setIsExpanded(toggle)}>
×
104
        {columns.map(({ key, render: Column }) => (
105
          <Column key={key} entry={entry} isExpanded={isExpanded} webhook={webhook} />
8✔
106
        ))}
107
      </AccordionSummary>
108
      <AccordionDetails>
109
        <code>{JSON.stringify(data)}</code>
110
      </AccordionDetails>
111
    </Accordion>
112
  );
113
};
114

115
const { page: defaultPage, perPage: defaultPerPage } = DEVICE_LIST_DEFAULTS;
5✔
116
const WebhookActivity = ({ events = [], getWebhookEvents, eventTotal, webhook }) => {
5!
117
  const { classes } = useStyles();
1✔
118
  const [page, setPage] = useState(defaultPage);
1✔
119

120
  useEffect(() => {
1✔
121
    getWebhookEvents({ page, perPage: defaultPerPage });
1✔
122
  }, [getWebhookEvents, page]);
123

124
  return (
1✔
125
    <div className={classes.activityList}>
126
      {events.length ? (
1!
127
        <>
128
          <div className="header">
129
            {columns.map(({ key, title }) => (
130
              <div key={key}>{title}</div>
4✔
131
            ))}
132
          </div>
133
          <div className="body">
134
            {events.map(entry => (
135
              <ListItem key={entry.id} entry={entry} webhook={webhook} />
2✔
136
            ))}
137
            {eventTotal > defaultPerPage && (
1!
138
              <Pagination
139
                className="margin-top-none"
140
                count={eventTotal ? eventTotal : defaultPerPage}
×
141
                showCountInfo={false}
142
                rowsPerPageOptions={[defaultPerPage]}
143
                page={page}
144
                rowsPerPage={defaultPerPage}
145
                onChangePage={setPage}
146
              />
147
            )}
148
          </div>
149
        </>
150
      ) : (
151
        <div className="margin-top-large flexbox centered disabled">No webhook activity yet.</div>
152
      )}
153
    </div>
154
  );
155
};
156

157
export default WebhookActivity;
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