From 26402e539868a23b2e2c9a7583e63553095c2e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Louv-Jansen?= Date: Wed, 9 Oct 2019 09:14:41 +0200 Subject: [PATCH] Fix toasts --- .../AddEditFlyout/DeleteButton.tsx | 17 ++++++++++++----- .../AgentConfigurations/AddEditFlyout/index.tsx | 7 ++++++- .../AddEditFlyout/saveConfig.ts | 10 ++++++---- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/DeleteButton.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/DeleteButton.tsx index 0b7134fbf1932..7c0557991fa26 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/DeleteButton.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/DeleteButton.tsx @@ -6,11 +6,12 @@ import React, { useState } from 'react'; import { EuiButtonEmpty } from '@elastic/eui'; -import { toastNotifications } from 'ui/notify'; +import { NotificationsStart } from 'kibana/public'; import { i18n } from '@kbn/i18n'; import { Config } from '../index'; import { callApmApi } from '../../../../../services/rest/callApmApi'; import { getOptionLabel } from '../constants'; +import { useKibanaCore } from '../../../../../../../observability/public'; interface Props { onDeleted: () => void; @@ -19,6 +20,9 @@ interface Props { export function DeleteButton({ onDeleted, selectedConfig }: Props) { const [isDeleting, setIsDeleting] = useState(false); + const { + notifications: { toasts } + } = useKibanaCore(); return ( { setIsDeleting(true); - await deleteConfig(selectedConfig); + await deleteConfig(selectedConfig, toasts); setIsDeleting(false); onDeleted(); }} @@ -40,7 +44,10 @@ export function DeleteButton({ onDeleted, selectedConfig }: Props) { ); } -async function deleteConfig(selectedConfig: Config) { +async function deleteConfig( + selectedConfig: Config, + toasts: NotificationsStart['toasts'] +) { try { await callApmApi({ pathname: '/api/apm/settings/agent-configuration/{configurationId}', @@ -49,7 +56,7 @@ async function deleteConfig(selectedConfig: Config) { path: { configurationId: selectedConfig.id } } }); - toastNotifications.addSuccess({ + toasts.addSuccess({ title: i18n.translate( 'xpack.apm.settings.agentConf.flyout.deleteSection.deleteConfigSucceededTitle', { defaultMessage: 'Configuration was deleted' } @@ -64,7 +71,7 @@ async function deleteConfig(selectedConfig: Config) { ) }); } catch (error) { - toastNotifications.addDanger({ + toasts.addDanger({ title: i18n.translate( 'xpack.apm.settings.agentConf.flyout.deleteSection.deleteConfigFailedTitle', { defaultMessage: 'Configuration could not be deleted' } diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx index 40e50ddbc16c6..551351e75107f 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx @@ -34,6 +34,7 @@ import { useFetcher } from '../../../../../hooks/useFetcher'; import { isRumAgentName } from '../../../../../../common/agent_name'; import { ALL_OPTION_VALUE } from '../constants'; import { saveConfig } from './saveConfig'; +import { useKibanaCore } from '../../../../../../../observability/public'; const defaultSettings = { TRANSACTION_SAMPLE_RATE: '1.0', @@ -54,6 +55,9 @@ export function AddEditFlyout({ onDeleted, selectedConfig }: Props) { + const { + notifications: { toasts } + } = useKibanaCore(); const [isSaving, setIsSaving] = useState(false); // config conditions (service) @@ -129,7 +133,8 @@ export function AddEditFlyout({ captureBody, transactionMaxSpans, configurationId: selectedConfig ? selectedConfig.id : undefined, - agentName + agentName, + toasts }); setIsSaving(false); onSaved(); diff --git a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts index 7ad8d0a09e69f..3e0e6a8849fad 100644 --- a/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts +++ b/x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/saveConfig.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { toastNotifications } from 'ui/notify'; import { i18n } from '@kbn/i18n'; +import { NotificationsStart } from 'kibana/public'; import { trackEvent } from '../../../../../../../infra/public/hooks/use_track_metric'; import { isRumAgentName } from '../../../../../../common/agent_name'; import { getOptionValue, getOptionLabel } from '../constants'; @@ -24,7 +24,8 @@ export async function saveConfig({ captureBody, transactionMaxSpans, configurationId, - agentName + agentName, + toasts }: { serviceName: string; environment: string; @@ -33,6 +34,7 @@ export async function saveConfig({ transactionMaxSpans: string; configurationId?: string; agentName?: string; + toasts: NotificationsStart['toasts']; }) { trackEvent({ app: 'apm', name: 'save_agent_configuration' }); @@ -74,7 +76,7 @@ export async function saveConfig({ }); } - toastNotifications.addSuccess({ + toasts.addSuccess({ title: i18n.translate( 'xpack.apm.settings.agentConf.saveConfig.succeeded.title', { defaultMessage: 'Configuration saved' } @@ -89,7 +91,7 @@ export async function saveConfig({ ) }); } catch (error) { - toastNotifications.addDanger({ + toasts.addDanger({ title: i18n.translate( 'xpack.apm.settings.agentConf.saveConfig.failed.title', { defaultMessage: 'Configuration could not be saved' }