-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Monitoring] Enable out of the box alerts modal (#101565)
* Remove api call to create alerts * Add enable alerts modal * Update modal title * Add simple alerts dropdown * change alerts modal design * refactor alerts modal provider * Add alerts dropdown * Show toast after alert creation and add error handling * Do not show alerts modal if alerts already exist * Fix stack monitoring test * Fix more stack monitoring tests and types * Fix tests after merge * Attempt to fix stack monitoring tests * remove console.log * Change text * Remove commented comment * Update docs for stack monitoring alerts * Fix docs Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
e387d3d
commit 4640253
Showing
39 changed files
with
389 additions
and
18 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
77 changes: 77 additions & 0 deletions
77
x-pack/plugins/monitoring/public/alerts/alerts_dropdown.tsx
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,77 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { | ||
EuiButtonEmpty, | ||
EuiContextMenu, | ||
EuiContextMenuPanelDescriptor, | ||
EuiPopover, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import React, { useState } from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { Legacy } from '../legacy_shims'; | ||
|
||
export const AlertsDropdown: React.FC<{}> = () => { | ||
const $injector = Legacy.shims.getAngularInjector(); | ||
const alertsEnableModalProvider: any = $injector.get('enableAlertsModal'); | ||
|
||
const [isPopoverOpen, setIsPopoverOpen] = useState(false); | ||
|
||
const closePopover = () => { | ||
alertsEnableModalProvider.enableAlerts(); | ||
setIsPopoverOpen(false); | ||
}; | ||
|
||
const togglePopoverVisibility = () => { | ||
setIsPopoverOpen(!isPopoverOpen); | ||
}; | ||
|
||
const createDefaultRules = () => { | ||
closePopover(); | ||
}; | ||
|
||
const button = ( | ||
<EuiButtonEmpty iconSide={'right'} iconType={'arrowDown'} onClick={togglePopoverVisibility}> | ||
<FormattedMessage | ||
id="xpack.monitoring.alerts.dropdown.button" | ||
defaultMessage="Alerts and rules" | ||
/> | ||
</EuiButtonEmpty> | ||
); | ||
|
||
const items = [ | ||
{ | ||
name: i18n.translate('xpack.monitoring.alerts.dropdown.createAlerts', { | ||
defaultMessage: 'Create default rules', | ||
}), | ||
onClick: createDefaultRules, | ||
}, | ||
]; | ||
|
||
const panels: EuiContextMenuPanelDescriptor[] = [ | ||
{ | ||
id: 0, | ||
title: i18n.translate('xpack.monitoring.alerts.dropdown.title', { | ||
defaultMessage: 'Alerts and rules', | ||
}), | ||
items, | ||
}, | ||
]; | ||
|
||
return ( | ||
<EuiPopover | ||
panelPaddingSize="none" | ||
anchorPosition="downLeft" | ||
button={button} | ||
isOpen={isPopoverOpen} | ||
closePopover={closePopover} | ||
> | ||
<EuiContextMenu initialPanelId={0} panels={panels} /> | ||
</EuiPopover> | ||
); | ||
}; |
148 changes: 148 additions & 0 deletions
148
x-pack/plugins/monitoring/public/alerts/enable_alerts_modal.tsx
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,148 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useEffect, useState, useContext } from 'react'; | ||
|
||
import { | ||
EuiButton, | ||
EuiModal, | ||
EuiModalBody, | ||
EuiModalFooter, | ||
EuiModalHeader, | ||
EuiModalHeaderTitle, | ||
EuiButtonEmpty, | ||
EuiText, | ||
EuiLink, | ||
EuiRadioGroup, | ||
EuiSpacer, | ||
} from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { AlertsContext } from './context'; | ||
import { Legacy } from '../legacy_shims'; | ||
|
||
export const EnableAlertsModal: React.FC<{}> = () => { | ||
const [isModalVisible, setIsModalVisible] = useState(false); | ||
const $injector = Legacy.shims.getAngularInjector(); | ||
const alertsEnableModalProvider: any = $injector.get('enableAlertsModal'); | ||
const alertsContext = useContext(AlertsContext); | ||
|
||
const closeModal = () => { | ||
setIsModalVisible(false); | ||
alertsEnableModalProvider.hideModalForSession(); | ||
}; | ||
|
||
const radios = [ | ||
{ | ||
id: 'create-alerts', | ||
label: i18n.translate('xpack.monitoring.alerts.modal.yesOption', { | ||
defaultMessage: 'Yes (Recommended - create default rules in this kibana spaces)', | ||
}), | ||
}, | ||
{ | ||
id: 'not-create-alerts', | ||
label: i18n.translate('xpack.monitoring.alerts.modal.noOption', { | ||
defaultMessage: 'No', | ||
}), | ||
}, | ||
]; | ||
|
||
const [radioIdSelected, setRadioIdSelected] = useState('create-alerts'); | ||
|
||
const onChange = (optionId: string) => { | ||
setRadioIdSelected(optionId); | ||
}; | ||
|
||
useEffect(() => { | ||
if (alertsEnableModalProvider.shouldShowAlertsModal(alertsContext)) { | ||
setIsModalVisible(true); | ||
} | ||
}, [alertsEnableModalProvider, alertsContext]); | ||
|
||
const confirmButtonClick = () => { | ||
if (radioIdSelected === 'create-alerts') { | ||
alertsEnableModalProvider.enableAlerts(); | ||
} else { | ||
alertsEnableModalProvider.notAskAgain(); | ||
} | ||
|
||
closeModal(); | ||
}; | ||
|
||
const remindLaterClick = () => { | ||
alertsEnableModalProvider.hideModalForSession(); | ||
closeModal(); | ||
}; | ||
|
||
return isModalVisible ? ( | ||
<EuiModal onClose={closeModal}> | ||
<EuiModalHeader> | ||
<EuiModalHeaderTitle> | ||
<h1> | ||
<FormattedMessage | ||
id="xpack.monitoring.alerts.modal.title" | ||
defaultMessage="Create rules" | ||
/> | ||
</h1> | ||
</EuiModalHeaderTitle> | ||
</EuiModalHeader> | ||
|
||
<EuiModalBody> | ||
<EuiText> | ||
<p> | ||
<FormattedMessage | ||
id="xpack.monitoring.alerts.modal.description" | ||
defaultMessage="Stack monitoring comes with many out-of-the box rules to notify you of common issues | ||
around cluster health, resource utilization and errors or exceptions. {learnMoreLink}" | ||
values={{ | ||
learnMoreLink: ( | ||
<EuiLink | ||
href={Legacy.shims.docLinks.links.monitoring.alertsKibana} | ||
target="_blank" | ||
> | ||
<FormattedMessage | ||
id="xpack.monitoring.alerts.modal.description.link" | ||
defaultMessage="Learn more..." | ||
/> | ||
</EuiLink> | ||
), | ||
}} | ||
/> | ||
</p> | ||
<div> | ||
<FormattedMessage | ||
id="xpack.monitoring.alerts.modal.createDescription" | ||
defaultMessage="Create these out-of-the box rules?" | ||
/> | ||
|
||
<EuiSpacer size="xs" /> | ||
|
||
<EuiRadioGroup | ||
options={radios} | ||
idSelected={radioIdSelected} | ||
onChange={(id) => onChange(id)} | ||
name="radio group" | ||
/> | ||
</div> | ||
</EuiText> | ||
</EuiModalBody> | ||
|
||
<EuiModalFooter> | ||
<EuiButtonEmpty onClick={remindLaterClick}> | ||
<FormattedMessage | ||
id="xpack.monitoring.alerts.modal.remindLater" | ||
defaultMessage="Remind me later" | ||
/> | ||
</EuiButtonEmpty> | ||
|
||
<EuiButton onClick={confirmButtonClick} fill data-test-subj="alerts-modal-button"> | ||
<FormattedMessage id="xpack.monitoring.alerts.modal.confirm" defaultMessage="Ok" /> | ||
</EuiButton> | ||
</EuiModalFooter> | ||
</EuiModal> | ||
) : null; | ||
}; |
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
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.