foreman_webhooks 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v2/webhooks_controller.rb +7 -1
  3. data/app/controllers/concerns/foreman_webhooks/controller/parameters/webhook.rb +1 -0
  4. data/app/controllers/webhooks_controller.rb +1 -24
  5. data/app/services/foreman_webhooks/webhook_service.rb +1 -1
  6. data/app/views/foreman_webhooks/webhook_templates/remote_execution_-_host_job.erb +0 -1
  7. data/config/routes.rb +6 -2
  8. data/lib/foreman_webhooks/engine.rb +2 -2
  9. data/lib/foreman_webhooks/version.rb +1 -1
  10. data/package.json +6 -6
  11. data/webpack/ForemanWebhooks/Routes/ForemanWebhooksRoutes.js +2 -2
  12. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/ForemanFormikField.js +117 -0
  13. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/WebhookFormTabs.css +7 -0
  14. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/Components/WebhookFormTabs.js +163 -0
  15. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookForm.js +69 -0
  16. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/WebhookFormSelectors.js +58 -0
  17. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/__tests__/WebhookForm.test.js +51 -0
  18. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/__tests__/__snapshots__/WebhookForm.test.js.snap +510 -0
  19. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/constants.js +9 -0
  20. data/webpack/ForemanWebhooks/Routes/Webhooks/Components/WebhookForm/index.js +73 -0
  21. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/EmptyWebhooksIndexPage/index.js +63 -0
  22. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookCreateModal.js +69 -0
  23. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookDeleteModal.js +1 -0
  24. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookEditModal.js +107 -0
  25. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookEditModalSelectors.js +22 -0
  26. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookModal.scss +6 -0
  27. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/index.js +1 -0
  28. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/nameToEditFormatter.js +19 -0
  29. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/NameToEditCell.js +35 -0
  30. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/WebhooksTable.js +31 -14
  31. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/WebhooksTableSchema.js +12 -4
  32. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/__tests__/WebhooksTable.test.js +13 -4
  33. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/__tests__/__snapshots__/WebhooksTable.test.js.snap +62 -19
  34. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/index.js +27 -5
  35. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/WebhooksIndexPage.js +61 -32
  36. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/WebhooksIndexPage.fixtures.js +36 -0
  37. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/WebhooksIndexPage.test.js +3 -1
  38. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/__snapshots__/WebhooksIndexPage.test.js.snap +18 -60
  39. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/__snapshots__/integration.test.js.snap +43 -0
  40. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/__tests__/integration.test.js +34 -0
  41. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksPageActions.js +3 -0
  42. data/webpack/ForemanWebhooks/Routes/Webhooks/constants.js +11 -1
  43. data/webpack/__mocks__/foremanReact/Root/Context/ForemanContext.js +1 -0
  44. data/webpack/__mocks__/foremanReact/common/HOC.js +26 -1
  45. data/webpack/__mocks__/foremanReact/common/urlHelpers.js +7 -0
  46. data/webpack/__mocks__/foremanReact/components/ForemanModal/index.js +6 -1
  47. data/webpack/__mocks__/foremanReact/components/Loading/Loading.js +2 -0
  48. data/webpack/__mocks__/foremanReact/components/Loading/index.js +3 -0
  49. data/webpack/__mocks__/foremanReact/components/Pagination/PaginationWrapper.js +3 -1
  50. data/webpack/__mocks__/foremanReact/components/common/forms/ForemanForm.js +9 -0
  51. data/webpack/__mocks__/foremanReact/components/common/forms/FormField.js +3 -0
  52. data/webpack/__mocks__/foremanReact/components/common/table.js +21 -0
  53. data/webpack/__mocks__/foremanReact/history.js +3 -0
  54. data/webpack/__mocks__/foremanReact/redux/actions/common/forms.js +1 -0
  55. data/webpack/test_setup.js +15 -0
  56. metadata +30 -7
  57. data/app/views/webhooks/_form.html.erb +0 -38
  58. data/app/views/webhooks/_templates.html.erb +0 -5
  59. data/app/views/webhooks/edit.html.erb +0 -3
  60. data/app/views/webhooks/new.html.erb +0 -3
  61. data/webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/EmptyWebhooksTable/index.js +0 -29
@@ -0,0 +1,9 @@
1
+ export const HTTP_METHODS = [
2
+ { value: 'POST', label: 'POST' },
3
+ { value: 'GET', label: 'GET' },
4
+ { value: 'PUT', label: 'PUT' },
5
+ { value: 'DELETE', label: 'DELETE' },
6
+ { value: 'PATCH', label: 'PATCH' },
7
+ ];
8
+
9
+ export const WEBHOOK_ITEM = 'Webhook';
@@ -0,0 +1,73 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useSelector, useDispatch } from 'react-redux';
3
+ import PropTypes from 'prop-types';
4
+ import { startCase, camelCase } from 'lodash';
5
+
6
+ import { foremanUrl } from 'foremanReact/common/helpers';
7
+ import { get } from 'foremanReact/redux/API';
8
+
9
+ import WebhookForm from './WebhookForm';
10
+
11
+ import {
12
+ selectWebhookTemplates,
13
+ selectWebhookEvents,
14
+ selectTemplatesIsLoading,
15
+ selectEventsIsLoading,
16
+ } from './WebhookFormSelectors';
17
+
18
+ import {
19
+ WEBHOOK_TEMPLATES_API_REQUEST_KEY,
20
+ WEBHOOK_TEMPLATES_API_PATH,
21
+ WEBHOOK_EVENTS_API_REQUEST_KEY,
22
+ WEBHOOKS_API_PLAIN_PATH,
23
+ } from '../../constants';
24
+
25
+ const params = { page: 1, search: 'snippet = false', per_page: 'all' };
26
+
27
+ const ConnectedWebhookForm = ({ onCancel, handleSubmit, initialValues }) => {
28
+ const dispatch = useDispatch();
29
+
30
+ const templates = useSelector(selectWebhookTemplates);
31
+ const availableEvents = useSelector(selectWebhookEvents).map(e => ({
32
+ value: `${e}.event.foreman`,
33
+ label: startCase(camelCase(e)),
34
+ }));
35
+ const isTemplatesLoading = useSelector(selectTemplatesIsLoading);
36
+ const isEventsLoading = useSelector(selectEventsIsLoading);
37
+
38
+ useEffect(() => {
39
+ dispatch(
40
+ get({
41
+ key: WEBHOOK_TEMPLATES_API_REQUEST_KEY,
42
+ url: foremanUrl(WEBHOOK_TEMPLATES_API_PATH),
43
+ params,
44
+ })
45
+ );
46
+ dispatch(
47
+ get({
48
+ key: WEBHOOK_EVENTS_API_REQUEST_KEY,
49
+ url: foremanUrl(`${WEBHOOKS_API_PLAIN_PATH}/events`),
50
+ })
51
+ );
52
+ }, [dispatch]);
53
+
54
+ return (
55
+ <WebhookForm
56
+ templates={templates}
57
+ availableEvents={availableEvents}
58
+ onCancel={onCancel}
59
+ handleSubmit={handleSubmit}
60
+ initialValues={initialValues}
61
+ isTemplatesLoading={isTemplatesLoading}
62
+ isEventsLoading={isEventsLoading}
63
+ />
64
+ );
65
+ };
66
+
67
+ ConnectedWebhookForm.propTypes = {
68
+ onCancel: PropTypes.func.isRequired,
69
+ handleSubmit: PropTypes.func.isRequired,
70
+ initialValues: PropTypes.object.isRequired,
71
+ };
72
+
73
+ export default ConnectedWebhookForm;
@@ -0,0 +1,63 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { translate as __ } from 'foremanReact/common/I18n';
4
+ import DefaultEmptyState from 'foremanReact/components/common/EmptyState';
5
+
6
+ import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
7
+
8
+ import WebhookCreateModal from '../WebhookCreateModal';
9
+ import { WEBHOOK_CREATE_MODAL_ID } from '../../../constants';
10
+
11
+ const EmptyWebhooksIndexPage = ({
12
+ search,
13
+ reloadWithSearch,
14
+ message: { type, text },
15
+ }) => {
16
+ const {
17
+ setModalOpen: setCreateModalOpen,
18
+ setModalClosed: setCreateModalClosed,
19
+ } = useForemanModal({
20
+ id: WEBHOOK_CREATE_MODAL_ID,
21
+ });
22
+
23
+ return (
24
+ <>
25
+ <WebhookCreateModal
26
+ onSuccess={() => {
27
+ setCreateModalClosed();
28
+ reloadWithSearch(search);
29
+ }}
30
+ onCancel={setCreateModalClosed}
31
+ />
32
+ <DefaultEmptyState
33
+ icon={type === 'error' ? 'error-circle-o' : 'add-circle-o'}
34
+ header={type === 'error' ? __('Error') : __('No Results')}
35
+ description={text}
36
+ documentation={null}
37
+ action={{
38
+ title: __('Create Webhook'),
39
+ onClick: () => setCreateModalOpen(),
40
+ }}
41
+ />
42
+ </>
43
+ );
44
+ };
45
+
46
+ EmptyWebhooksIndexPage.propTypes = {
47
+ message: PropTypes.shape({
48
+ type: PropTypes.oneOf(['empty', 'error']),
49
+ text: PropTypes.string,
50
+ }),
51
+ search: PropTypes.string,
52
+ reloadWithSearch: PropTypes.func.isRequired,
53
+ };
54
+
55
+ EmptyWebhooksIndexPage.defaultProps = {
56
+ message: {
57
+ type: 'empty',
58
+ text: __('Try to create a new Webhook'),
59
+ },
60
+ search: '',
61
+ };
62
+
63
+ export default EmptyWebhooksIndexPage;
@@ -0,0 +1,69 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { useDispatch } from 'react-redux';
4
+
5
+ import { translate as __ } from 'foremanReact/common/I18n';
6
+ import { submitForm } from 'foremanReact/redux/actions/common/forms';
7
+ import { foremanUrl } from 'foremanReact/common/helpers';
8
+ import ForemanModal from 'foremanReact/components/ForemanModal';
9
+
10
+ import ConnectedWebhookForm from '../../Components/WebhookForm';
11
+
12
+ import { WEBHOOK_CREATE_MODAL_ID, WEBHOOKS_PATH } from '../../constants';
13
+
14
+ import './WebhookModal.scss';
15
+
16
+ const WebhookCreateModal = ({ onSuccess, onCancel }) => {
17
+ const dispatch = useDispatch();
18
+
19
+ const initialWebhookValues = {
20
+ name: '',
21
+ target_url: '',
22
+ user: '',
23
+ password: '',
24
+ webhook_template_id: undefined,
25
+ event: '',
26
+ http_method: 'POST',
27
+ http_content_type: 'application/json',
28
+ enabled: true,
29
+ verify_ssl: true,
30
+ ssl_ca_certs: '',
31
+ http_headers: '',
32
+ proxy_authorization: false,
33
+ };
34
+
35
+ const handleSubmit = (values, actions) =>
36
+ dispatch(
37
+ submitForm({
38
+ url: foremanUrl(`/api${WEBHOOKS_PATH}`),
39
+ values: { ...values, controller: 'webhooks' },
40
+ item: 'Webhook',
41
+ message: __('Webhook was successfully created.'),
42
+ successCallback: onSuccess,
43
+ actions,
44
+ })
45
+ );
46
+
47
+ return (
48
+ <ForemanModal
49
+ id={WEBHOOK_CREATE_MODAL_ID}
50
+ title={__('Create Webhook')}
51
+ backdrop="static"
52
+ className="webhooks-modal"
53
+ >
54
+ <ForemanModal.Header />
55
+ <ConnectedWebhookForm
56
+ handleSubmit={handleSubmit}
57
+ initialValues={initialWebhookValues}
58
+ onCancel={onCancel}
59
+ />
60
+ </ForemanModal>
61
+ );
62
+ };
63
+
64
+ WebhookCreateModal.propTypes = {
65
+ onSuccess: PropTypes.func.isRequired,
66
+ onCancel: PropTypes.func.isRequired,
67
+ };
68
+
69
+ export default WebhookCreateModal;
@@ -14,6 +14,7 @@ const WebhookDeleteModal = ({ toDelete, onSuccess }) => {
14
14
  <ForemanModal
15
15
  id={WEBHOOK_DELETE_MODAL_ID}
16
16
  title={__('Confirm Webhook Deletion')}
17
+ backdrop="static"
17
18
  enforceFocus
18
19
  submitProps={{
19
20
  url: foremanUrl(`/api/v2/webhooks/${id}`),
@@ -0,0 +1,107 @@
1
+ import React, { useEffect } from 'react';
2
+ import { useSelector, useDispatch } from 'react-redux';
3
+ import PropTypes from 'prop-types';
4
+
5
+ import { translate as __ } from 'foremanReact/common/I18n';
6
+ import ForemanModal from 'foremanReact/components/ForemanModal';
7
+ import Loading from 'foremanReact/components/Loading';
8
+ import { foremanUrl } from 'foremanReact/common/helpers';
9
+ import { submitForm } from 'foremanReact/redux/actions/common/forms';
10
+ import { get } from 'foremanReact/redux/API';
11
+
12
+ import ConnectedWebhookForm from '../../Components/WebhookForm';
13
+
14
+ import {
15
+ WEBHOOKS_PATH,
16
+ WEBHOOK_API_REQUEST_KEY,
17
+ WEBHOOK_EDIT_MODAL_ID,
18
+ WEBHOOKS_API_PLAIN_PATH,
19
+ } from '../../constants';
20
+
21
+ import {
22
+ selectIsLoading,
23
+ selectWebhookValues,
24
+ selectWebhookTemplateId,
25
+ } from './WebhookEditModalSelectors';
26
+
27
+ import './WebhookModal.scss';
28
+
29
+ const WebhookEditModal = ({ toEdit, onSuccess, onCancel }) => {
30
+ const dispatch = useDispatch();
31
+
32
+ const id = toEdit;
33
+
34
+ const handleSubmit = (values, actions) =>
35
+ dispatch(
36
+ submitForm({
37
+ url: foremanUrl(`/api${WEBHOOKS_PATH}/${id}`),
38
+ values: { ...values, controller: 'webhooks' },
39
+ item: 'Webhook',
40
+ message: __('Webhook was successfully updated.'),
41
+ method: 'put',
42
+ successCallback: onSuccess,
43
+ actions,
44
+ })
45
+ );
46
+
47
+ const isLoading = useSelector(selectIsLoading);
48
+ const initialWebhookValues = {
49
+ id: useSelector(selectWebhookValues).id,
50
+ name: useSelector(selectWebhookValues).name,
51
+ target_url: useSelector(selectWebhookValues).targetUrl,
52
+ user: useSelector(selectWebhookValues).user || '',
53
+ password: '',
54
+ http_method: useSelector(selectWebhookValues).httpMethod,
55
+ http_content_type: useSelector(selectWebhookValues).httpContentType || '',
56
+ webhook_template_id: useSelector(selectWebhookTemplateId),
57
+ event: useSelector(selectWebhookValues).event,
58
+ enabled: useSelector(selectWebhookValues).enabled,
59
+ verify_ssl: useSelector(selectWebhookValues).verifySsl,
60
+ ssl_ca_certs: useSelector(selectWebhookValues).sslCaCerts || '',
61
+ http_headers: useSelector(selectWebhookValues).httpHeaders || '',
62
+ proxy_authorization: useSelector(selectWebhookValues).proxyAuthorization,
63
+ };
64
+
65
+ useEffect(() => {
66
+ if (id) {
67
+ dispatch(
68
+ get({
69
+ key: WEBHOOK_API_REQUEST_KEY,
70
+ url: foremanUrl(`${WEBHOOKS_API_PLAIN_PATH}/${id}`),
71
+ })
72
+ );
73
+ }
74
+ }, [id, dispatch]);
75
+
76
+ return (
77
+ <ForemanModal
78
+ id={WEBHOOK_EDIT_MODAL_ID}
79
+ title={`${__('Edit')} ${initialWebhookValues.name}`}
80
+ backdrop="static"
81
+ className="webhooks-modal"
82
+ >
83
+ <ForemanModal.Header />
84
+ {isLoading ? (
85
+ <Loading />
86
+ ) : (
87
+ <ConnectedWebhookForm
88
+ handleSubmit={handleSubmit}
89
+ initialValues={initialWebhookValues}
90
+ onCancel={onCancel}
91
+ />
92
+ )}
93
+ </ForemanModal>
94
+ );
95
+ };
96
+
97
+ WebhookEditModal.propTypes = {
98
+ onSuccess: PropTypes.func.isRequired,
99
+ onCancel: PropTypes.func.isRequired,
100
+ toEdit: PropTypes.number,
101
+ };
102
+
103
+ WebhookEditModal.defaultProps = {
104
+ toEdit: 0,
105
+ };
106
+
107
+ export default WebhookEditModal;
@@ -0,0 +1,22 @@
1
+ import { STATUS } from 'foremanReact/constants';
2
+ import { deepPropsToCamelCase } from 'foremanReact/common/helpers';
3
+ import {
4
+ selectAPIStatus,
5
+ selectAPIResponse,
6
+ } from 'foremanReact/redux/API/APISelectors';
7
+
8
+ import { WEBHOOK_API_REQUEST_KEY } from '../../constants';
9
+
10
+ export const selectWebhookValues = state =>
11
+ deepPropsToCamelCase(selectAPIResponse(state, WEBHOOK_API_REQUEST_KEY)) || {};
12
+
13
+ export const selectWebhookTemplateId = state =>
14
+ selectWebhookValues(state)?.webhookTemplate?.id || 0;
15
+
16
+ const selectWebhooksEditPageStatus = state =>
17
+ selectAPIStatus(state, WEBHOOK_API_REQUEST_KEY);
18
+
19
+ export const selectIsLoading = state => {
20
+ const status = selectWebhooksEditPageStatus(state);
21
+ return !status || status === STATUS.PENDING;
22
+ };
@@ -0,0 +1,6 @@
1
+ .webhooks-modal {
2
+ .modal-dialog {
3
+ width: 50vw;
4
+ min-width: 50vw;
5
+ }
6
+ }
@@ -1 +1,2 @@
1
1
  export { default as enabledCellFormatter } from './enabledCellFormatter';
2
+ export { default as nameToEditFormatter } from './nameToEditFormatter';
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import NameToEditCell from '../NameToEditCell';
3
+
4
+ const nameToEditFormatter = (controllerPluralize, onClick) => (
5
+ value,
6
+ { rowData: { canEdit, id, name } }
7
+ ) => (
8
+ <NameToEditCell
9
+ active={canEdit}
10
+ id={id}
11
+ name={encodeURI(name)}
12
+ controller={controllerPluralize}
13
+ onClick={onClick}
14
+ >
15
+ {value}
16
+ </NameToEditCell>
17
+ );
18
+
19
+ export default nameToEditFormatter;
@@ -0,0 +1,35 @@
1
+ import React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Button } from '@patternfly/react-core';
4
+
5
+ const NameToEditCell = ({ active, id, name, controller, onClick, children }) =>
6
+ active ? (
7
+ <Button
8
+ variant="link"
9
+ isInline
10
+ component="span"
11
+ onClick={() => onClick(id)}
12
+ >
13
+ {children}
14
+ </Button>
15
+ ) : (
16
+ <Button variant="link" isInline isDisabled component="span">
17
+ {children}
18
+ </Button>
19
+ );
20
+
21
+ NameToEditCell.propTypes = {
22
+ active: PropTypes.bool,
23
+ id: PropTypes.number.isRequired,
24
+ name: PropTypes.string.isRequired,
25
+ controller: PropTypes.string.isRequired,
26
+ onClick: PropTypes.func.isRequired,
27
+ children: PropTypes.node,
28
+ };
29
+
30
+ NameToEditCell.defaultProps = {
31
+ active: false,
32
+ children: null,
33
+ };
34
+
35
+ export default NameToEditCell;
@@ -1,16 +1,17 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
 
4
- import { translate as __ } from 'foremanReact/common/I18n';
5
4
  import { Table } from 'foremanReact/components/common/table';
6
5
  import Pagination from 'foremanReact/components/Pagination/PaginationWrapper';
7
- import { withRenderHandler } from 'foremanReact/common/HOC';
6
+ import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks';
8
7
 
9
8
  import WebhookDeleteModal from '../WebhookDeleteModal';
10
- import EmptyWebhooksTable from '../EmptyWebhooksTable';
9
+ import WebhookEditModal from '../WebhookEditModal';
11
10
 
12
11
  import createWebhooksTableSchema from './WebhooksTableSchema';
13
12
 
13
+ import { WEBHOOK_EDIT_MODAL_ID } from '../../../constants';
14
+
14
15
  const WebhooksTable = ({
15
16
  fetchAndPush,
16
17
  itemCount,
@@ -19,23 +20,40 @@ const WebhooksTable = ({
19
20
  pagination,
20
21
  toDelete,
21
22
  onDeleteClick,
22
- message,
23
+ toEdit,
24
+ onEditClick,
25
+ reloadWithSearch,
26
+ search,
23
27
  }) => {
24
- const onSuccess = () => {
28
+ const onDeleteSuccess = () => {
25
29
  const currentPage = pagination.page;
26
30
  const maxPage = Math.ceil((itemCount - 1) / pagination.perPage);
27
31
  fetchAndPush({ page: maxPage < currentPage ? maxPage : currentPage });
28
32
  };
33
+
34
+ const { setModalClosed: setEditModalClosed } = useForemanModal({
35
+ id: WEBHOOK_EDIT_MODAL_ID,
36
+ });
37
+
29
38
  return (
30
39
  <React.Fragment>
31
- <WebhookDeleteModal toDelete={toDelete} onSuccess={onSuccess} />
40
+ <WebhookDeleteModal toDelete={toDelete} onSuccess={onDeleteSuccess} />
41
+ <WebhookEditModal
42
+ toEdit={toEdit}
43
+ onSuccess={() => {
44
+ setEditModalClosed();
45
+ reloadWithSearch(search);
46
+ }}
47
+ onCancel={setEditModalClosed}
48
+ />
32
49
  <Table
33
50
  key="webhooks-table"
34
51
  columns={createWebhooksTableSchema(
35
52
  fetchAndPush,
36
53
  sort.by,
37
54
  sort.order,
38
- onDeleteClick
55
+ onDeleteClick,
56
+ onEditClick
39
57
  )}
40
58
  rows={results}
41
59
  id="webhooks-table"
@@ -56,20 +74,19 @@ WebhooksTable.propTypes = {
56
74
  results: PropTypes.array.isRequired,
57
75
  fetchAndPush: PropTypes.func.isRequired,
58
76
  onDeleteClick: PropTypes.func.isRequired,
77
+ onEditClick: PropTypes.func.isRequired,
59
78
  itemCount: PropTypes.number.isRequired,
60
79
  sort: PropTypes.object,
61
80
  pagination: PropTypes.object.isRequired,
62
81
  toDelete: PropTypes.object.isRequired,
63
- message: PropTypes.object,
82
+ toEdit: PropTypes.number.isRequired,
83
+ reloadWithSearch: PropTypes.func.isRequired,
84
+ search: PropTypes.string,
64
85
  };
65
86
 
66
87
  WebhooksTable.defaultProps = {
67
88
  sort: { by: '', order: '' },
68
- message: { type: 'empty', text: __('Try to create a new Webhook') },
89
+ search: '',
69
90
  };
70
91
 
71
- export default withRenderHandler({
72
- Component: WebhooksTable,
73
- EmptyComponent: EmptyWebhooksTable,
74
- ErrorComponent: EmptyWebhooksTable,
75
- });
92
+ export default WebhooksTable;