mirror of
https://github.com/ansible/awx.git
synced 2026-04-06 18:49:21 -02:30
Merge pull request #8150 from keithjgrant/7878-notification-websockets
Update status after sending test notification Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -17,6 +17,7 @@ import Jobs from './models/Jobs';
|
|||||||
import Labels from './models/Labels';
|
import Labels from './models/Labels';
|
||||||
import Me from './models/Me';
|
import Me from './models/Me';
|
||||||
import NotificationTemplates from './models/NotificationTemplates';
|
import NotificationTemplates from './models/NotificationTemplates';
|
||||||
|
import Notifications from './models/Notifications';
|
||||||
import Organizations from './models/Organizations';
|
import Organizations from './models/Organizations';
|
||||||
import ProjectUpdates from './models/ProjectUpdates';
|
import ProjectUpdates from './models/ProjectUpdates';
|
||||||
import Projects from './models/Projects';
|
import Projects from './models/Projects';
|
||||||
@@ -53,6 +54,7 @@ const JobsAPI = new Jobs();
|
|||||||
const LabelsAPI = new Labels();
|
const LabelsAPI = new Labels();
|
||||||
const MeAPI = new Me();
|
const MeAPI = new Me();
|
||||||
const NotificationTemplatesAPI = new NotificationTemplates();
|
const NotificationTemplatesAPI = new NotificationTemplates();
|
||||||
|
const NotificationsAPI = new Notifications();
|
||||||
const OrganizationsAPI = new Organizations();
|
const OrganizationsAPI = new Organizations();
|
||||||
const ProjectUpdatesAPI = new ProjectUpdates();
|
const ProjectUpdatesAPI = new ProjectUpdates();
|
||||||
const ProjectsAPI = new Projects();
|
const ProjectsAPI = new Projects();
|
||||||
@@ -90,6 +92,7 @@ export {
|
|||||||
LabelsAPI,
|
LabelsAPI,
|
||||||
MeAPI,
|
MeAPI,
|
||||||
NotificationTemplatesAPI,
|
NotificationTemplatesAPI,
|
||||||
|
NotificationsAPI,
|
||||||
OrganizationsAPI,
|
OrganizationsAPI,
|
||||||
ProjectUpdatesAPI,
|
ProjectUpdatesAPI,
|
||||||
ProjectsAPI,
|
ProjectsAPI,
|
||||||
|
|||||||
10
awx/ui_next/src/api/models/Notifications.js
Normal file
10
awx/ui_next/src/api/models/Notifications.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import Base from '../Base';
|
||||||
|
|
||||||
|
class Notifications extends Base {
|
||||||
|
constructor(http) {
|
||||||
|
super(http);
|
||||||
|
this.baseUrl = '/api/v2/notifications/';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Notifications;
|
||||||
@@ -26,6 +26,7 @@ const RunningIcon = styled(SyncAltIcon)`
|
|||||||
|
|
||||||
const colors = {
|
const colors = {
|
||||||
success: 'green',
|
success: 'green',
|
||||||
|
successful: 'green',
|
||||||
failed: 'red',
|
failed: 'red',
|
||||||
error: 'red',
|
error: 'red',
|
||||||
running: 'blue',
|
running: 'blue',
|
||||||
@@ -35,6 +36,7 @@ const colors = {
|
|||||||
};
|
};
|
||||||
const icons = {
|
const icons = {
|
||||||
success: CheckCircleIcon,
|
success: CheckCircleIcon,
|
||||||
|
successful: CheckCircleIcon,
|
||||||
failed: ExclamationCircleIcon,
|
failed: ExclamationCircleIcon,
|
||||||
error: ExclamationCircleIcon,
|
error: ExclamationCircleIcon,
|
||||||
running: RunningIcon,
|
running: RunningIcon,
|
||||||
@@ -58,6 +60,7 @@ export default function StatusLabel({ status }) {
|
|||||||
StatusLabel.propTypes = {
|
StatusLabel.propTypes = {
|
||||||
status: oneOf([
|
status: oneOf([
|
||||||
'success',
|
'success',
|
||||||
|
'successful',
|
||||||
'failed',
|
'failed',
|
||||||
'error',
|
'error',
|
||||||
'running',
|
'running',
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ 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 { NotificationTemplatesAPI, NotificationsAPI } 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 useRequest from '../../../util/useRequest';
|
||||||
@@ -27,6 +27,9 @@ const DataListAction = styled(_DataListAction)`
|
|||||||
grid-template-columns: 40px 40px;
|
grid-template-columns: 40px 40px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const NUM_RETRIES = 25;
|
||||||
|
const RETRY_TIMEOUT = 5000;
|
||||||
|
|
||||||
function NotificationTemplateListItem({
|
function NotificationTemplateListItem({
|
||||||
template,
|
template,
|
||||||
detailUrl,
|
detailUrl,
|
||||||
@@ -45,9 +48,29 @@ function NotificationTemplateListItem({
|
|||||||
}, [latestStatus]);
|
}, [latestStatus]);
|
||||||
|
|
||||||
const { request: sendTestNotification, isLoading, error } = useRequest(
|
const { request: sendTestNotification, isLoading, error } = useRequest(
|
||||||
useCallback(() => {
|
useCallback(async () => {
|
||||||
NotificationTemplatesAPI.test(template.id);
|
const request = NotificationTemplatesAPI.test(template.id);
|
||||||
setStatus('running');
|
setStatus('running');
|
||||||
|
let retries = NUM_RETRIES;
|
||||||
|
const {
|
||||||
|
data: { notification: notificationId },
|
||||||
|
} = await request;
|
||||||
|
|
||||||
|
async function pollForStatusChange() {
|
||||||
|
const { data: notification } = await NotificationsAPI.readDetail(
|
||||||
|
notificationId
|
||||||
|
);
|
||||||
|
if (notification.status !== 'pending') {
|
||||||
|
setStatus(notification.status);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
retries--;
|
||||||
|
if (retries > 0) {
|
||||||
|
setTimeout(pollForStatusChange, RETRY_TIMEOUT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(pollForStatusChange, RETRY_TIMEOUT);
|
||||||
}, [template.id])
|
}, [template.id])
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,9 @@ describe('<NotificationTemplateListItem />', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('should send test notification', async () => {
|
test('should send test notification', async () => {
|
||||||
NotificationTemplatesAPI.test.mockResolvedValue({});
|
NotificationTemplatesAPI.test.mockResolvedValue({
|
||||||
|
data: { notification: 1 },
|
||||||
|
});
|
||||||
|
|
||||||
const wrapper = mountWithContexts(
|
const wrapper = mountWithContexts(
|
||||||
<NotificationTemplateListItem
|
<NotificationTemplateListItem
|
||||||
|
|||||||
Reference in New Issue
Block a user