diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/expression.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/expression.tsx index 873d711e26576..74c8d4fe60d9c 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/expression.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/expression.tsx @@ -20,7 +20,7 @@ import { EuiFormRow, EuiCallOut, } from '@elastic/eui'; -import { HttpSetup } from 'kibana/public'; +import { HttpSetup, IUiSettingsClient, ToastsApi } from 'kibana/public'; import { COMPARATORS, builtInComparators } from '../../../../common/constants'; import { getMatchingIndicesForThresholdAlertType, @@ -68,6 +68,11 @@ interface IndexThresholdProps { setAlertProperty: (key: string, value: any) => void; errors: { [key: string]: string[] }; http: HttpSetup; + uiSettings?: IUiSettingsClient; + toastNotifications?: Pick< + ToastsApi, + 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError' + >; } export const IndexThresholdAlertTypeExpression: React.FunctionComponent = ({ @@ -76,6 +81,8 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent { const { index, @@ -433,12 +440,15 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent - {canShowVizualization ? null : ( + {canShowVizualization || !uiSettings ? null : ( )} diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/visualization.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/visualization.tsx index 30217f43af3c5..87355f96d7a46 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/visualization.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/components/builtin_alert_types/threshold/visualization.tsx @@ -5,7 +5,7 @@ */ import React, { Fragment, useEffect, useState } from 'react'; -import { IUiSettingsClient } from 'kibana/public'; +import { IUiSettingsClient, HttpSetup, ToastsApi } from 'kibana/public'; import { i18n } from '@kbn/i18n'; import { AnnotationDomainTypes, @@ -26,7 +26,6 @@ import { EuiCallOut, EuiLoadingChart, EuiSpacer, EuiEmptyPrompt, EuiText } from import { FormattedMessage } from '@kbn/i18n/react'; import { npStart } from 'ui/new_platform'; import { getThresholdAlertVisualizationData } from './lib/api'; -import { useAppDependencies } from '../../../app_context'; import { AggregationType, Comparator } from '../../../../common/types'; import { IndexThresholdAlertParams } from '../types'; @@ -89,14 +88,22 @@ interface Props { comparators: { [key: string]: Comparator; }; + http: HttpSetup; + uiSettings: IUiSettingsClient; + toastNotifications?: Pick< + ToastsApi, + 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError' + >; } export const ThresholdVisualization: React.FunctionComponent = ({ alertParams, aggregationTypes, comparators, + http, + uiSettings, + toastNotifications, }) => { - const { http, uiSettings, toastNotifications } = useAppDependencies(); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(undefined); const [visualizationData, setVisualizationData] = useState>([]); @@ -142,12 +149,14 @@ export const ThresholdVisualization: React.FunctionComponent = ({ }) ); } catch (e) { - toastNotifications.addDanger({ - title: i18n.translate( - 'xpack.triggersActionsUI.sections.alertAdd.unableToLoadVisualizationMessage', - { defaultMessage: 'Unable to load visualization' } - ), - }); + if (toastNotifications) { + toastNotifications.addDanger({ + title: i18n.translate( + 'xpack.triggersActionsUI.sections.alertAdd.unableToLoadVisualizationMessage', + { defaultMessage: 'Unable to load visualization' } + ), + }); + } setError(e); } finally { setIsLoading(false); diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_modal.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_modal.tsx index c81393ccc8c2e..55386ec6d61f9 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_modal.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/action_connector_form/connector_add_modal.tsx @@ -36,12 +36,12 @@ interface ConnectorAddModalProps { setAddModalVisibility: React.Dispatch>; postSaveEventHandler?: (savedAction: ActionConnector) => void; http: HttpSetup; - toastNotifications: Pick< + alertTypeRegistry: TypeRegistry; + actionTypeRegistry: TypeRegistry; + toastNotifications?: Pick< ToastsApi, 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError' >; - alertTypeRegistry: TypeRegistry; - actionTypeRegistry: TypeRegistry; } export const ConnectorAddModal = ({ @@ -88,17 +88,19 @@ export const ConnectorAddModal = ({ const onActionConnectorSave = async (): Promise => await createActionConnector({ http, connector }) .then(savedConnector => { - toastNotifications.addSuccess( - i18n.translate( - 'xpack.triggersActionsUI.sections.addModalConnectorForm.updateSuccessNotificationText', - { - defaultMessage: "Created '{connectorName}'", - values: { - connectorName: savedConnector.name, - }, - } - ) - ); + if (toastNotifications) { + toastNotifications.addSuccess( + i18n.translate( + 'xpack.triggersActionsUI.sections.addModalConnectorForm.updateSuccessNotificationText', + { + defaultMessage: "Created '{connectorName}'", + values: { + connectorName: savedConnector.name, + }, + } + ) + ); + } return savedConnector; }) .catch(errorRes => { diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.test.tsx index 19ab187f9c136..032330b6f79b6 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.test.tsx @@ -96,10 +96,12 @@ describe('alert_add', () => { }} > ); diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.tsx index c1bca14d040a6..e3ca8a4962197 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_add.tsx @@ -18,7 +18,7 @@ import { EuiPortal, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { HttpSetup, ToastsApi } from 'kibana/public'; +import { HttpSetup, ToastsApi, IUiSettingsClient } from 'kibana/public'; import { useAlertsContext } from '../../context/alerts_context'; import { Alert, AlertAction, IErrorObject, AlertTypeModel, ActionTypeModel } from '../../../types'; import { AlertForm, validateBaseProperties } from './alert_form'; @@ -27,25 +27,33 @@ import { createAlert } from '../../lib/alert_api'; import { TypeRegistry } from '../../type_registry'; interface AlertAddProps { + consumer: string; http: HttpSetup; - toastNotifications: Pick< + alertTypeRegistry: TypeRegistry; + actionTypeRegistry: TypeRegistry; + uiSettings?: IUiSettingsClient; + toastNotifications?: Pick< ToastsApi, 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError' >; - alertTypeRegistry: TypeRegistry; - actionTypeRegistry: TypeRegistry; + alertTypeId?: string; + canChangeTrigger?: boolean; } export const AlertAdd = ({ + consumer, http, toastNotifications, alertTypeRegistry, actionTypeRegistry, + uiSettings, + canChangeTrigger, + alertTypeId, }: AlertAddProps) => { const initialAlert = ({ params: {}, - consumer: 'alerting', - alertTypeId: null, + consumer, + alertTypeId, schedule: { interval: '1m', }, @@ -106,14 +114,16 @@ export const AlertAdd = ({ async function onSaveAlert(): Promise { try { const newAlert = await createAlert({ http, alert }); - toastNotifications.addSuccess( - i18n.translate('xpack.triggersActionsUI.sections.alertForm.saveSuccessNotificationText', { - defaultMessage: "Saved '{alertName}'", - values: { - alertName: newAlert.name, - }, - }) - ); + if (toastNotifications) { + toastNotifications.addSuccess( + i18n.translate('xpack.triggersActionsUI.sections.alertForm.saveSuccessNotificationText', { + defaultMessage: "Saved '{alertName}'", + values: { + alertName: newAlert.name, + }, + }) + ); + } return newAlert; } catch (errorRes) { setServerError(errorRes); @@ -146,10 +156,12 @@ export const AlertAdd = ({ actionTypeRegistry={actionTypeRegistry} alertTypeRegistry={alertTypeRegistry} toastNotifications={toastNotifications} + uiSettings={uiSettings} alert={alert} dispatch={dispatch} errors={errors} serverError={serverError} + canChangeTrigger={canChangeTrigger} /> diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.test.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.test.tsx index 6bafe82cf8cf5..6af1d8334cf57 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.test.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.test.tsx @@ -108,6 +108,7 @@ describe('alert_form', () => { actionTypeRegistry={deps.actionTypeRegistry} alertTypeRegistry={deps.alertTypeRegistry} toastNotifications={deps.toastNotifications} + uiSettings={deps.uiSettings} /> ); } @@ -172,6 +173,7 @@ describe('alert_form', () => { actionTypeRegistry={deps.actionTypeRegistry} alertTypeRegistry={deps.alertTypeRegistry} toastNotifications={deps.toastNotifications} + uiSettings={deps.uiSettings} /> ); } diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.tsx index 4fa06def066a0..49fe4d9101631 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alert_add/alert_form.tsx @@ -28,7 +28,7 @@ import { EuiEmptyPrompt, EuiButtonEmpty, } from '@elastic/eui'; -import { HttpSetup, ToastsApi } from 'kibana/public'; +import { HttpSetup, ToastsApi, IUiSettingsClient } from 'kibana/public'; import { loadAlertTypes } from '../../lib/alert_api'; import { loadActionTypes, loadAllActions } from '../../lib/action_connector_api'; import { AlertReducerAction } from './alert_reducer'; @@ -82,19 +82,20 @@ export function validateBaseProperties(alertObject: Alert) { interface AlertFormProps { alert: Alert; - canChangeTrigger?: boolean; // to hide Change trigger button dispatch: React.Dispatch; errors: IErrorObject; serverError: { body: { message: string; error: string }; } | null; http: HttpSetup; - toastNotifications: Pick< + alertTypeRegistry: TypeRegistry; + actionTypeRegistry: TypeRegistry; + uiSettings?: IUiSettingsClient; + toastNotifications?: Pick< ToastsApi, 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError' >; - alertTypeRegistry: TypeRegistry; - actionTypeRegistry: TypeRegistry; + canChangeTrigger?: boolean; // to hide Change trigger button } interface ActiveActionConnectorState { @@ -112,6 +113,7 @@ export const AlertForm = ({ toastNotifications, alertTypeRegistry, actionTypeRegistry, + uiSettings, }: AlertFormProps) => { const [alertTypeModel, setAlertTypeModel] = useState( alertTypeRegistry.get(alert.alertTypeId) @@ -144,12 +146,14 @@ export const AlertForm = ({ } setActionTypesIndex(index); } catch (e) { - toastNotifications.addDanger({ - title: i18n.translate( - 'xpack.triggersActionsUI.sections.alertForm.unableToLoadActionTypesMessage', - { defaultMessage: 'Unable to load action types' } - ), - }); + if (toastNotifications) { + toastNotifications.addDanger({ + title: i18n.translate( + 'xpack.triggersActionsUI.sections.alertForm.unableToLoadActionTypesMessage', + { defaultMessage: 'Unable to load action types' } + ), + }); + } } finally { setIsLoadingActionTypes(false); } @@ -175,12 +179,14 @@ export const AlertForm = ({ } setAlertTypesIndex(index); } catch (e) { - toastNotifications.addDanger({ - title: i18n.translate( - 'xpack.triggersActionsUI.sections.alertForm.unableToLoadAlertTypesMessage', - { defaultMessage: 'Unable to load alert types' } - ), - }); + if (toastNotifications) { + toastNotifications.addDanger({ + title: i18n.translate( + 'xpack.triggersActionsUI.sections.alertForm.unableToLoadAlertTypesMessage', + { defaultMessage: 'Unable to load alert types' } + ), + }); + } } })(); // eslint-disable-next-line react-hooks/exhaustive-deps @@ -218,14 +224,16 @@ export const AlertForm = ({ const actionsResponse = await loadAllActions({ http }); setConnectors(actionsResponse.data); } catch (e) { - toastNotifications.addDanger({ - title: i18n.translate( - 'xpack.triggersActionsUI.sections.alertForm.unableToLoadActionsMessage', - { - defaultMessage: 'Unable to load connectors', - } - ), - }); + if (toastNotifications) { + toastNotifications.addDanger({ + title: i18n.translate( + 'xpack.triggersActionsUI.sections.alertForm.unableToLoadActionsMessage', + { + defaultMessage: 'Unable to load connectors', + } + ), + }); + } } } @@ -624,6 +632,9 @@ export const AlertForm = ({ errors={errors} setAlertParams={setAlertParams} setAlertProperty={setAlertProperty} + http={http} + toastNotifications={toastNotifications} + uiSettings={uiSettings} /> ) : null} diff --git a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx index 0bf4de876e5a9..0a2d7328267d4 100644 --- a/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx +++ b/x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/sections/alerts_list/components/alerts_list.tsx @@ -56,6 +56,7 @@ export const AlertsList: React.FunctionComponent = () => { capabilities, alertTypeRegistry, actionTypeRegistry, + uiSettings, } = useAppDependencies(); const canDelete = hasDeleteAlertsCapability(capabilities); const canSave = hasSaveAlertsCapability(capabilities); @@ -395,10 +396,12 @@ export const AlertsList: React.FunctionComponent = () => { }} >