mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
send test notifications
This commit is contained in:
@@ -5,6 +5,10 @@ class NotificationTemplates extends Base {
|
|||||||
super(http);
|
super(http);
|
||||||
this.baseUrl = '/api/v2/notification_templates/';
|
this.baseUrl = '/api/v2/notification_templates/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test(id) {
|
||||||
|
return this.http.post(`${this.baseUrl}${id}/test/`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NotificationTemplates;
|
export default NotificationTemplates;
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ StatusLabel.propTypes = {
|
|||||||
'error',
|
'error',
|
||||||
'running',
|
'running',
|
||||||
'pending',
|
'pending',
|
||||||
|
'waiting',
|
||||||
'canceled',
|
'canceled',
|
||||||
]).isRequired,
|
]).isRequired,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import 'styled-components/macro';
|
import 'styled-components/macro';
|
||||||
import React from 'react';
|
import React, { useState, useEffect, useCallback } from 'react';
|
||||||
import { withI18n } from '@lingui/react';
|
import { withI18n } from '@lingui/react';
|
||||||
import { t } from '@lingui/macro';
|
import { t } from '@lingui/macro';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom';
|
||||||
@@ -14,8 +14,10 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
} from '@patternfly/react-core';
|
} from '@patternfly/react-core';
|
||||||
import { PencilAltIcon, BellIcon } from '@patternfly/react-icons';
|
import { PencilAltIcon, BellIcon } from '@patternfly/react-icons';
|
||||||
|
import { NotificationTemplatesAPI } from '../../../api';
|
||||||
import DataListCell from '../../../components/DataListCell';
|
import DataListCell from '../../../components/DataListCell';
|
||||||
import StatusLabel from '../../../components/StatusLabel';
|
import StatusLabel from '../../../components/StatusLabel';
|
||||||
|
import useRequest from '../../../util/useRequest';
|
||||||
import { NOTIFICATION_TYPES } from '../constants';
|
import { NOTIFICATION_TYPES } from '../constants';
|
||||||
|
|
||||||
const DataListAction = styled(_DataListAction)`
|
const DataListAction = styled(_DataListAction)`
|
||||||
@@ -32,10 +34,27 @@ function NotificationTemplateListItem({
|
|||||||
onSelect,
|
onSelect,
|
||||||
i18n,
|
i18n,
|
||||||
}) {
|
}) {
|
||||||
const sendTestNotification = () => {};
|
const latestStatus = template.summary_fields?.recent_notifications[0]?.status;
|
||||||
const labelId = `template-name-${template.id}`;
|
const [status, setStatus] = useState(latestStatus);
|
||||||
|
|
||||||
const lastNotification = template.summary_fields?.recent_notifications[0];
|
useEffect(() => {
|
||||||
|
setStatus(latestStatus);
|
||||||
|
}, [latestStatus]);
|
||||||
|
|
||||||
|
const { request: sendTestNotification, isLoading, error } = useRequest(
|
||||||
|
useCallback(() => {
|
||||||
|
NotificationTemplatesAPI.test(template.id);
|
||||||
|
setStatus('pending');
|
||||||
|
}, [template.id])
|
||||||
|
);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (error) {
|
||||||
|
setStatus('error');
|
||||||
|
}
|
||||||
|
}, [error]);
|
||||||
|
|
||||||
|
const labelId = `template-name-${template.id}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataListItem key={template.id} aria-labelledby={labelId} id={template.id}>
|
<DataListItem key={template.id} aria-labelledby={labelId} id={template.id}>
|
||||||
@@ -54,9 +73,7 @@ function NotificationTemplateListItem({
|
|||||||
</Link>
|
</Link>
|
||||||
</DataListCell>,
|
</DataListCell>,
|
||||||
<DataListCell>
|
<DataListCell>
|
||||||
{lastNotification && (
|
{status && <StatusLabel status={status} />}
|
||||||
<StatusLabel status={lastNotification.status} />
|
|
||||||
)}
|
|
||||||
</DataListCell>,
|
</DataListCell>,
|
||||||
<DataListCell key="type">
|
<DataListCell key="type">
|
||||||
<strong css="margin-right: 24px">{i18n._(t`Type`)}</strong>
|
<strong css="margin-right: 24px">{i18n._(t`Type`)}</strong>
|
||||||
@@ -71,6 +88,7 @@ function NotificationTemplateListItem({
|
|||||||
aria-label={i18n._(t`Test Notification`)}
|
aria-label={i18n._(t`Test Notification`)}
|
||||||
variant="plain"
|
variant="plain"
|
||||||
onClick={sendTestNotification}
|
onClick={sendTestNotification}
|
||||||
|
disabled={isLoading}
|
||||||
>
|
>
|
||||||
<BellIcon />
|
<BellIcon />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user