Skip to content

Commit

Permalink
Fix toasts
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Oct 9, 2019
1 parent 7dec317 commit 26402e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,6 +20,9 @@ interface Props {

export function DeleteButton({ onDeleted, selectedConfig }: Props) {
const [isDeleting, setIsDeleting] = useState(false);
const {
notifications: { toasts }
} = useKibanaCore();

return (
<EuiButtonEmpty
Expand All @@ -27,7 +31,7 @@ export function DeleteButton({ onDeleted, selectedConfig }: Props) {
iconSide="right"
onClick={async () => {
setIsDeleting(true);
await deleteConfig(selectedConfig);
await deleteConfig(selectedConfig, toasts);
setIsDeleting(false);
onDeleted();
}}
Expand All @@ -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}',
Expand All @@ -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' }
Expand All @@ -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' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -54,6 +55,9 @@ export function AddEditFlyout({
onDeleted,
selectedConfig
}: Props) {
const {
notifications: { toasts }
} = useKibanaCore();
const [isSaving, setIsSaving] = useState(false);

// config conditions (service)
Expand Down Expand Up @@ -129,7 +133,8 @@ export function AddEditFlyout({
captureBody,
transactionMaxSpans,
configurationId: selectedConfig ? selectedConfig.id : undefined,
agentName
agentName,
toasts
});
setIsSaving(false);
onSaved();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -24,7 +24,8 @@ export async function saveConfig({
captureBody,
transactionMaxSpans,
configurationId,
agentName
agentName,
toasts
}: {
serviceName: string;
environment: string;
Expand All @@ -33,6 +34,7 @@ export async function saveConfig({
transactionMaxSpans: string;
configurationId?: string;
agentName?: string;
toasts: NotificationsStart['toasts'];
}) {
trackEvent({ app: 'apm', name: 'save_agent_configuration' });

Expand Down Expand Up @@ -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' }
Expand All @@ -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' }
Expand Down

0 comments on commit 26402e5

Please sign in to comment.