diff --git a/x-pack/plugins/triggers_actions_ui/public/application/home.tsx b/x-pack/plugins/triggers_actions_ui/public/application/home.tsx index 20aec6974d395..3da25cb4cf0d8 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/home.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/home.tsx @@ -90,7 +90,7 @@ export const TriggersActionsUIHome: React.FunctionComponent - + diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx index 1bbffc850ee18..cad4dabbe8275 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.test.tsx @@ -12,8 +12,14 @@ import { mountWithIntl, nextTick } from '@kbn/test/jest'; import { act } from '@testing-library/react'; import { AlertDetails } from './alert_details'; import { Alert, ActionType, AlertTypeModel, AlertType } from '../../../../types'; -import { EuiTitle, EuiBadge, EuiFlexItem, EuiSwitch, EuiButtonEmpty, EuiText } from '@elastic/eui'; -import { ViewInApp } from './view_in_app'; +import { + EuiBadge, + EuiFlexItem, + EuiSwitch, + EuiButtonEmpty, + EuiText, + EuiPageHeaderProps, +} from '@elastic/eui'; import { ActionGroup, AlertExecutionStatusErrorReasons, @@ -75,13 +81,7 @@ describe('alert_details', () => { expect( shallow( - ).containsMatchingElement( - -

- {alert.name} -

-
- ) + ).find('EuiPageHeader') ).toBeTruthy(); }); @@ -103,7 +103,7 @@ describe('alert_details', () => { expect( shallow( - ).containsMatchingElement({alertType.name}) + ).find({alertType.name}) ).toBeTruthy(); }); @@ -290,7 +290,7 @@ describe('alert_details', () => { expect( shallow( - ).containsMatchingElement() + ).find('ViewInApp') ).toBeTruthy(); }); @@ -309,16 +309,29 @@ describe('alert_details', () => { minimumLicenseRequired: 'basic', enabledInLicense: true, }; - - expect( - shallow( - - ) - .find(EuiButtonEmpty) - .find('[data-test-subj="openEditAlertFlyoutButton"]') - .first() - .exists() - ).toBeTruthy(); + const pageHeaderProps = shallow( + + ) + .find('EuiPageHeader') + .props() as EuiPageHeaderProps; + const rightSideItems = pageHeaderProps.rightSideItems; + expect(!!rightSideItems && rightSideItems[2]!).toMatchInlineSnapshot(` + + + + + + `); }); }); }); @@ -768,20 +781,34 @@ describe('edit button', () => { enabledInLicense: true, }; - expect( - shallow( - + ) + .find('EuiPageHeader') + .props() as EuiPageHeaderProps; + const rightSideItems = pageHeaderProps.rightSideItems; + expect(!!rightSideItems && rightSideItems[2]!).toMatchInlineSnapshot(` + + + - ) - .find(EuiButtonEmpty) - .find('[name="edit"]') - .first() - .exists() - ).toBeTruthy(); + + + `); }); it('should not render an edit button when alert editable but actions arent', () => { @@ -851,20 +878,34 @@ describe('edit button', () => { enabledInLicense: true, }; - expect( - shallow( - + ) + .find('EuiPageHeader') + .props() as EuiPageHeaderProps; + const rightSideItems = pageHeaderProps.rightSideItems; + expect(!!rightSideItems && rightSideItems[2]!).toMatchInlineSnapshot(` + + + - ) - .find(EuiButtonEmpty) - .find('[name="edit"]') - .first() - .exists() - ).toBeTruthy(); + + + `); }); }); @@ -885,7 +926,7 @@ describe('refresh button', () => { }; const requestRefresh = jest.fn(); - const refreshButton = shallow( + const wrapper = mountWithIntl( { {...mockAlertApis} requestRefresh={requestRefresh} /> - ) - .find('[data-test-subj="refreshAlertsButton"]') - .first(); + ); + const refreshButton = wrapper.find('[data-test-subj="refreshAlertsButton"]').first(); expect(refreshButton.exists()).toBeTruthy(); refreshButton.simulate('click'); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx index ba6c77a4403f1..3e411913520ad 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_details.tsx @@ -12,14 +12,11 @@ import { useHistory } from 'react-router-dom'; import { EuiPageBody, EuiPageContent, - EuiPageContentHeader, - EuiPageContentHeaderSection, - EuiTitle, + EuiPageHeader, EuiText, EuiFlexGroup, EuiFlexItem, EuiBadge, - EuiPage, EuiPageContentBody, EuiSwitch, EuiCallOut, @@ -45,7 +42,7 @@ import { alertsErrorReasonTranslationsMapping } from '../../alerts_list/translat import { useKibana } from '../../../../common/lib/kibana'; import { alertReducer } from '../../alert_form/alert_reducer'; -type AlertDetailsProps = { +export type AlertDetailsProps = { alert: Alert; alertType: AlertType; actionTypes: ActionType[]; @@ -120,249 +117,245 @@ export const AlertDetails: React.FunctionComponent = ({ } }; + const rightPageHeaderButtons = hasEditButton + ? [ + <> + setEditFlyoutVisibility(true)} + name="edit" + disabled={!alertType.enabledInLicense} + > + + + {editFlyoutVisible && ( + { + setInitialAlert(alert); + setEditFlyoutVisibility(false); + }} + actionTypeRegistry={actionTypeRegistry} + alertTypeRegistry={alertTypeRegistry} + onSave={setAlert} + /> + )} + , + ] + : []; + return ( - - - - - - -

- {alert.name} -

-
-
- - - {hasEditButton ? ( - - <> - {' '} - setEditFlyoutVisibility(true)} - name="edit" - disabled={!alertType.enabledInLicense} - > - - - {editFlyoutVisible && ( - { - setInitialAlert(alert); - setEditFlyoutVisibility(false); - }} - actionTypeRegistry={actionTypeRegistry} - alertTypeRegistry={alertTypeRegistry} - onSave={setAlert} - /> - )} - - - ) : null} + + + + } + rightSideItems={[ + , + + + , + ...rightPageHeaderButtons, + ]} + /> + + + + + +

+ +

+
+ + {alertType.name} +
+ + {uniqueActions && uniqueActions.length ? ( + <> + +

+ +

+
+ + + {uniqueActions.map((action, index) => ( + + + {actionTypesByTypeId[action].name ?? action} + + + ))} + + + ) : null} +
+ + + - - - + { + if (isEnabled) { + setIsEnabled(false); + await disableAlert(alert); + // Reset dismiss if previously clicked + setDissmissAlertErrors(false); + } else { + setIsEnabled(true); + await enableAlert(alert); + } + requestRefresh(); + }} + label={ + + } + /> - + { + if (isMuted) { + setIsMuted(false); + await unmuteAlert(alert); + } else { + setIsMuted(true); + await muteAlert(alert); + } + requestRefresh(); + }} + label={ + + } + /> -
-
- - - - -

- -

-
- - {alertType.name} -
- - {uniqueActions && uniqueActions.length ? ( - <> - -

- -

-
- - - {uniqueActions.map((action, index) => ( - - - {actionTypesByTypeId[action].name ?? action} - - - ))} - - - ) : null} -
- - - - - { - if (isEnabled) { - setIsEnabled(false); - await disableAlert(alert); - // Reset dismiss if previously clicked - setDissmissAlertErrors(false); - } else { - setIsEnabled(true); - await enableAlert(alert); - } - requestRefresh(); - }} - label={ - - } - /> - - - { - if (isMuted) { - setIsMuted(false); - await unmuteAlert(alert); - } else { - setIsMuted(true); - await muteAlert(alert); - } - requestRefresh(); - }} - label={ + + + {alert.enabled && !dissmissAlertErrors && alert.executionStatus.status === 'error' ? ( + + + + + {alert.executionStatus.error?.message} + + + + + setDissmissAlertErrors(true)} + > - } - /> - - - - - {alert.enabled && !dissmissAlertErrors && alert.executionStatus.status === 'error' ? ( - - - - - {alert.executionStatus.error?.message} - - - + + + {alert.executionStatus.error?.reason === + AlertExecutionStatusErrorReasons.License && ( - setDissmissAlertErrors(true)} + target="_blank" > - + - {alert.executionStatus.error?.reason === - AlertExecutionStatusErrorReasons.License && ( - - - - - - )} - - - -
- ) : null} - - - {alert.enabled ? ( - - ) : ( - <> - - -

- -

-
- - )} + )} +
+
- -
- - + ) : null} + + + {alert.enabled ? ( + + ) : ( + <> + + +

+ +

+
+ + )} +
+
+ +
+ ); }; diff --git a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts index 34e08ad257f84..8cf92f77d939c 100644 --- a/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts +++ b/x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/details.ts @@ -136,7 +136,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { it('renders the alert details', async () => { const headingText = await pageObjects.alertDetailsUI.getHeadingText(); - expect(headingText).to.be(`test-alert-${testRunUuid}`); + expect(headingText.includes(`test-alert-${testRunUuid}`)).to.be(true); const alertType = await pageObjects.alertDetailsUI.getAlertType(); expect(alertType).to.be(`Always Firing`); @@ -279,7 +279,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { expect(toastTitle).to.eql(`Updated '${updatedAlertName}'`); const headingText = await pageObjects.alertDetailsUI.getHeadingText(); - expect(headingText).to.be(updatedAlertName); + expect(headingText.includes(updatedAlertName)).to.be(true); }); it('should reset alert when canceling an edit', async () => {