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

mendersoftware / gui / 897326496

pending completion
897326496

Pull #3752

gitlab-ci

mzedel
chore(e2e): made use of shared timeout & login checking values to remove code duplication

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #3752: chore(e2e-tests): slightly simplified log in test + separated log out test

4395 of 6392 branches covered (68.76%)

8060 of 9780 relevant lines covered (82.41%)

126.17 hits per line

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

75.93
/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, { useEffect, useMemo, useState } from 'react';
15
import { connect } 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 { getDocsVersion } from '../../../selectors';
24
import DetailsTable from '../../common/detailstable';
25
import Time from '../../common/time';
26
import WebhookManagement from './management';
27

28
const columns = [
6✔
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 = ({
6✔
48
  changeIntegration,
49
  createIntegration,
50
  deleteIntegration,
51
  docsVersion,
52
  events,
53
  eventTotal,
54
  getIntegrations,
55
  getWebhookEvents,
56
  webhook = { ...emptyWebhook },
2✔
57
  webhooks
58
}) => {
59
  const [adding, setAdding] = useState(false);
2✔
60
  const [editing, setEditing] = useState(false);
2✔
61
  const [selectedWebhook, setSelectedWebhook] = useState(webhook);
2✔
62

63
  useEffect(() => {
2✔
64
    getIntegrations();
2✔
65
  }, []);
66

67
  useEffect(() => {
2✔
68
    setSelectedWebhook(webhook);
2✔
69
  }, [JSON.stringify(webhook)]);
70

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

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

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

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

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

105
  return (
2✔
106
    <div>
107
      <h2>Webhooks</h2>
108
      {webhooks.length ? (
2✔
109
        <DetailsTable columns={relevantColumns} items={mappedWebhooks} onItemClick={onEdit} />
110
      ) : (
111
        <div className="flexbox centered">
112
          No webhooks are configured yet. Learn more about webhooks in our{' '}
113
          <a href={`https://docs.mender.io/${docsVersion}server-integration`} target="_blank" rel="noopener noreferrer">
114
            documentation
115
          </a>
116
        </div>
117
      )}
118
      <WebhookManagement
119
        adding={adding}
120
        editing={editing}
121
        events={events}
122
        eventTotal={eventTotal}
123
        getWebhookEvents={getWebhookEvents}
124
        onCancel={onCancel}
125
        onSubmit={onSubmit}
126
        onRemove={onRemoveClick}
127
        webhook={selectedWebhook}
128
      />
129
    </div>
130
  );
131
};
132

133
const actionCreators = { changeIntegration, createIntegration, deleteIntegration, getIntegrations, getWebhookEvents };
6✔
134

135
const mapStateToProps = state => {
6✔
136
  const webhooks = state.organization.externalDeviceIntegrations.filter(
2✔
137
    integration => integration.id && integration.provider === EXTERNAL_PROVIDER.webhook.provider
1✔
138
  );
139
  const events = webhooks.length ? state.organization.webhooks.events : [];
2✔
140
  return {
2✔
141
    docsVersion: getDocsVersion(state),
142
    events,
143
    eventTotal: state.organization.webhooks.eventTotal,
144
    webhooks
145
  };
146
};
147

148
export default connect(mapStateToProps, actionCreators)(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