-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
292 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
webpack/ForemanWebhooks/Routes/Webhooks/WebhooksIndexPage/Components/WebhookTestModal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import React from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { sprintf, translate as __ } from 'foremanReact/common/I18n'; | ||
import ForemanModal from 'foremanReact/components/ForemanModal'; | ||
import ForemanForm from 'foremanReact/components/common/forms/ForemanForm'; | ||
import { foremanUrl } from 'foremanReact/common/helpers'; | ||
import { submitForm } from 'foremanReact/redux/actions/common/forms'; | ||
import { useForemanModal } from 'foremanReact/components/ForemanModal/ForemanModalHooks'; | ||
|
||
import ForemanFormikField from '../../../Webhooks/Components/WebhookForm/Components/ForemanFormikField'; | ||
|
||
import { | ||
WEBHOOK_TEST_MODAL_ID, | ||
WEBHOOKS_API_PLAIN_PATH, | ||
} from '../../constants'; | ||
|
||
import './WebhookModal.scss'; | ||
|
||
const WebhookTestModal = ({ toTest }) => { | ||
const dispatch = useDispatch(); | ||
|
||
const { id, name } = toTest; | ||
const { setModalClosed: setTestModalClosed } = useForemanModal({ | ||
id: WEBHOOK_TEST_MODAL_ID, | ||
}); | ||
const initialTestValues = { | ||
payload: '', | ||
}; | ||
const errorToast = error => | ||
sprintf( | ||
__('Webhook test failed: %s'), | ||
error?.response?.data?.error?.message | ||
); | ||
|
||
const handleSubmit = (values, actions) => { | ||
dispatch( | ||
submitForm({ | ||
url: foremanUrl(`${WEBHOOKS_API_PLAIN_PATH}/${id}/test`), | ||
values: { ...values, controller: 'webhooks' }, | ||
item: 'WebhookTest', | ||
message: sprintf(__('Webhook %s test was successful'), name), | ||
method: 'post', | ||
successCallback: () => setTestModalClosed(), | ||
actions, | ||
errorToast, | ||
handleError: () => actions.setSubmitting(false), | ||
}) | ||
); | ||
}; | ||
|
||
return ( | ||
<ForemanModal | ||
id={WEBHOOK_TEST_MODAL_ID} | ||
title={`${__('Test')} ${name}`} | ||
backdrop="static" | ||
enforceFocus | ||
className="webhooks-modal" | ||
> | ||
<p> | ||
{sprintf( | ||
__( | ||
'You are about to test %s webhook.' + | ||
'\n' + | ||
'Please, note that this will not contain actual information or render the attached template.' + | ||
'\n' + | ||
'You can specify below a custom payload to test the webhook with.' | ||
), | ||
name | ||
)} | ||
</p> | ||
<ForemanForm | ||
onSubmit={handleSubmit} | ||
initialValues={initialTestValues} | ||
onCancel={setTestModalClosed} | ||
> | ||
<ForemanFormikField | ||
name="payload" | ||
type="textarea" | ||
label={__('Payload')} | ||
labelHelp={__('Will be sent as is')} | ||
placeholder="{ id: 1, name: test }" | ||
inputSizeClass="col-md-8" | ||
rows={8} | ||
/> | ||
</ForemanForm> | ||
</ForemanModal> | ||
); | ||
}; | ||
|
||
WebhookTestModal.propTypes = { | ||
toTest: PropTypes.object, | ||
}; | ||
|
||
WebhookTestModal.defaultProps = { | ||
toTest: {}, | ||
}; | ||
|
||
export default WebhookTestModal; |
52 changes: 52 additions & 0 deletions
52
...hooks/WebhooksIndexPage/Components/WebhooksTable/Components/ActionButtons/ActionButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { translate as __ } from 'foremanReact/common/I18n'; | ||
import { ActionButtons } from 'foremanReact/components/common/ActionButtons/ActionButtons'; | ||
import { noop } from 'foremanReact/common/helpers'; | ||
|
||
export const ActionButton = ({ | ||
id, | ||
name, | ||
enabled, | ||
canDelete, | ||
webhookActions, | ||
}) => { | ||
const buttons = []; | ||
if (canDelete) { | ||
buttons.push({ | ||
title: __('Delete'), | ||
action: { | ||
onClick: () => webhookActions.deleteWebhook(id, name), | ||
id: `webhook-delete-button-${id}`, | ||
}, | ||
}); | ||
} | ||
buttons.push({ | ||
title: __('Test webhook'), | ||
action: { | ||
disabled: !enabled, | ||
onClick: () => { | ||
enabled ? webhookActions.testWebhook(id, name) : noop(); | ||
}, | ||
id: `webhook-test-button-${id}`, | ||
}, | ||
}); | ||
|
||
return <ActionButtons buttons={buttons} />; | ||
}; | ||
|
||
ActionButton.propTypes = { | ||
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired, | ||
name: PropTypes.string.isRequired, | ||
canDelete: PropTypes.bool, | ||
webhookActions: PropTypes.shape({ | ||
deleteWebhook: PropTypes.func, | ||
testWebhook: PropTypes.func, | ||
}).isRequired, | ||
enabled: PropTypes.bool, | ||
}; | ||
|
||
ActionButton.defaultProps = { | ||
canDelete: false, | ||
enabled: false, | ||
}; |
21 changes: 21 additions & 0 deletions
21
...s/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/actionCellFormatter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react'; | ||
import { cellFormatter } from 'foremanReact/components/common/table'; | ||
import { ActionButton } from '../ActionButtons/ActionButton'; | ||
|
||
const actionCellFormatter = webhookActions => ( | ||
_, | ||
{ rowData: { id, name, enabled, canEdit, canDelete } } | ||
) => | ||
cellFormatter( | ||
canEdit && ( | ||
<ActionButton | ||
canDelete={canDelete} | ||
id={id} | ||
name={name} | ||
enabled={enabled} | ||
webhookActions={webhookActions} | ||
/> | ||
) | ||
); | ||
|
||
export default actionCellFormatter; |
1 change: 1 addition & 0 deletions
1
...Routes/Webhooks/WebhooksIndexPage/Components/WebhooksTable/Components/Formatters/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export { default as enabledCellFormatter } from './enabledCellFormatter'; | ||
export { default as nameToEditFormatter } from './nameToEditFormatter'; | ||
export { default as actionCellFormatter } from './actionCellFormatter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.