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

mendersoftware / gui / 1350829378

27 Jun 2024 01:46PM UTC coverage: 83.494% (-16.5%) from 99.965%
1350829378

Pull #4465

gitlab-ci

mzedel
chore: test fixes

Signed-off-by: Manuel Zedel <manuel.zedel@northern.tech>
Pull Request #4465: MEN-7169 - feat: added multi sorting capabilities to devices view

4506 of 6430 branches covered (70.08%)

81 of 100 new or added lines in 14 files covered. (81.0%)

1661 existing lines in 163 files now uncovered.

8574 of 10269 relevant lines covered (83.49%)

160.6 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',
UNCOV
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✔
UNCOV
71
    setAdding(false);
×
UNCOV
72
    setEditing(true);
×
UNCOV
73
    setSelectedWebhook(item);
×
74
  };
75

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

81
  const onSubmit = item => {
2✔
UNCOV
82
    if (adding) {
×
UNCOV
83
      dispatch(createIntegration(item));
×
84
    } else {
UNCOV
85
      dispatch(changeIntegration(item));
×
86
    }
UNCOV
87
    setAdding(false);
×
UNCOV
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