• 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

74.42
/src/js/components/settings/webhooks/webhooks.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, { useCallback, useEffect, useMemo, useState } from 'react';
15
import { useDispatch, useSelector } from 'react-redux';
16

17
// material ui
18
import { ArrowRightAlt as ArrowRightAltIcon } from '@mui/icons-material';
19

20
import { changeIntegration, createIntegration, deleteIntegration, getIntegrations, getWebhookEvents } from '../../../actions/organizationActions';
21
import { EXTERNAL_PROVIDER } from '../../../constants/deviceConstants';
22
import { emptyWebhook } from '../../../constants/organizationConstants';
23
import DetailsTable from '../../common/detailstable';
24
import DocsLink from '../../common/docslink';
25
import Time from '../../common/time';
26
import WebhookManagement from './management';
27

28
const columns = [
5✔
29
  { key: 'url', title: 'URL', render: ({ url }) => url },
1✔
30
  { key: 'status', title: 'Status', render: ({ status }) => status },
1✔
31
  {
32
    key: 'updated_ts',
33
    title: 'Last activity',
34
    render: ({ updated_ts }) => <Time value={updated_ts} />
×
35
  },
36
  {
37
    key: 'manage',
38
    title: 'Manage',
39
    render: () => (
40
      <div className="bold flexbox center-aligned link-color margin-right-small uppercased" style={{ whiteSpace: 'nowrap' }}>
1✔
41
        view details <ArrowRightAltIcon />
42
      </div>
43
    )
44
  }
45
];
46

47
export const Webhooks = ({ webhook = { ...emptyWebhook } }) => {
5✔
48
  const [adding, setAdding] = useState(false);
2✔
49
  const [editing, setEditing] = useState(false);
2✔
50
  const [selectedWebhook, setSelectedWebhook] = useState(webhook);
2✔
51
  const dispatch = useDispatch();
2✔
52
  const { events, webhooks } = useSelector(state => {
2✔
53
    const webhooks = state.organization.externalDeviceIntegrations.filter(
4✔
54
      integration => integration.id && integration.provider === EXTERNAL_PROVIDER.webhook.provider
2✔
55
    );
56
    const events = webhooks.length ? state.organization.webhooks.events : [];
4✔
57
    return { events, webhooks };
4✔
58
  });
59
  const eventTotal = useSelector(state => state.organization.webhooks.eventTotal);
4✔
60

61
  useEffect(() => {
2✔
62
    dispatch(getIntegrations());
2✔
63
  }, [dispatch]);
64

65
  useEffect(() => {
2✔
66
    setSelectedWebhook(webhook);
2✔
67
    // eslint-disable-next-line react-hooks/exhaustive-deps
68
  }, [JSON.stringify(webhook)]);
69

70
  const onEdit = item => {
2✔
71
    setAdding(false);
×
72
    setEditing(true);
×
73
    setSelectedWebhook(item);
×
74
  };
75

76
  const onCancel = () => {
2✔
77
    setAdding(false);
×
78
    setEditing(false);
×
79
  };
80

81
  const onSubmit = item => {
2✔
82
    if (adding) {
×
83
      dispatch(createIntegration(item));
×
84
    } else {
85
      dispatch(changeIntegration(item));
×
86
    }
87
    setAdding(false);
×
88
    setEditing(false);
×
89
  };
90

91
  const onRemoveClick = () => dispatch(deleteIntegration(selectedWebhook));
2✔
92

93
  const { mappedWebhooks, relevantColumns } = useMemo(() => {
2✔
94
    const mappedWebhooks = webhooks.map(item => ({ ...item, url: item.credentials[EXTERNAL_PROVIDER.webhook.credentialsType].url, status: 'enabled' }));
2✔
95
    const relevantColumns = columns.reduce((accu, item) => {
2✔
96
      if (mappedWebhooks.some(hook => hook[item.key]) || item === columns[columns.length - 1]) {
8✔
97
        accu.push(item);
4✔
98
      }
99
      return accu;
8✔
100
    }, []);
101
    return { mappedWebhooks, relevantColumns };
2✔
102
    // eslint-disable-next-line react-hooks/exhaustive-deps
103
  }, [JSON.stringify(webhooks)]);
104

105
  const dispatchedGetWebhookEvents = useCallback(options => dispatch(getWebhookEvents(options)), [dispatch]);
2✔
106

107
  return (
2✔
108
    <div>
109
      <h2>Webhooks</h2>
110
      {webhooks.length ? (
2✔
111
        <DetailsTable columns={relevantColumns} items={mappedWebhooks} onItemClick={onEdit} />
112
      ) : (
113
        <div className="flexbox centered">
114
          No webhooks are configured yet. Learn more about webhooks in our <DocsLink path="server-integration" title="documentation" />
115
        </div>
116
      )}
117
      <WebhookManagement
118
        adding={adding}
119
        editing={editing}
120
        events={events}
121
        eventTotal={eventTotal}
122
        getWebhookEvents={dispatchedGetWebhookEvents}
123
        onCancel={onCancel}
124
        onSubmit={onSubmit}
125
        onRemove={onRemoveClick}
126
        webhook={selectedWebhook}
127
      />
128
    </div>
129
  );
130
};
131

132
export default Webhooks;
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