Skip to content

Commit

Permalink
adapt calls by using reactMount
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Oct 28, 2019
1 parent 772a304 commit d45da3e
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,10 @@
import { i18n } from '@kbn/i18n';
import React from 'react';

import { NotificationsStart } from 'src/core/public';
import { NotificationsStart, Toast } from 'src/core/public';
import { DashboardPanelState } from 'src/legacy/core_plugins/dashboard_embeddable_container/public/np_ready/public';

import {
EuiFlyout,
EuiFlyoutBody,
EuiFlyoutHeader,
EuiTitle,
EuiGlobalToastListToast as Toast,
} from '@elastic/eui';
import { EuiFlyout, EuiFlyoutBody, EuiFlyoutHeader, EuiTitle } from '@elastic/eui';

import { IContainer } from '../../../../../../embeddable_api/public/np_ready/public';
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { EuiSuperUpdateButton, OnRefreshProps } from '@elastic/eui';
import { FormattedMessage, InjectedIntl, injectI18n } from '@kbn/i18n/react';
import { Toast } from 'src/core/public';
import { TimeRange } from 'src/plugins/data/public';
import { useKibana } from '../../../../../../../plugins/kibana_react/public';
import { useKibana, reactMount } from '../../../../../../../plugins/kibana_react/public';

import { IndexPattern } from '../../../index_patterns';
import { QueryBarInput } from './query_bar_input';
Expand Down Expand Up @@ -301,7 +301,7 @@ function QueryBarTopRowUI(props: Props) {
id: 'data.query.queryBar.luceneSyntaxWarningTitle',
defaultMessage: 'Lucene syntax warning',
}),
text: (
text: reactMount(
<div>
<p>
<FormattedMessage
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/ui/public/legacy_compat/angular_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import { fatalError } from 'ui/notify';
import { capabilities } from 'ui/capabilities';
// @ts-ignore
import { modifyUrl } from 'ui/url';
import { reactMount } from '../../../../plugins/kibana_react/public';
// @ts-ignore
import { UrlOverflowService } from '../error_url_overflow';
import { npStart } from '../new_platform';
Expand Down Expand Up @@ -305,7 +306,7 @@ const $setupUrlOverflowHandling = (newPlatform: CoreStart) => (
title: i18n.translate('common.ui.chrome.bigUrlWarningNotificationTitle', {
defaultMessage: 'The URL is big and Kibana might stop working',
}),
text: (
text: reactMount(
<Fragment>
<FormattedMessage
id="common.ui.chrome.bigUrlWarningNotificationMessage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import * as React from 'react';
import { KibanaServices } from '../context/types';
import { KibanaReactNotifications } from './types';
import { reactMount } from '../util';

export const createNotifications = (services: KibanaServices): KibanaReactNotifications => {
const show: KibanaReactNotifications['toasts']['show'] = ({
Expand All @@ -34,8 +35,8 @@ export const createNotifications = (services: KibanaServices): KibanaReactNotifi
throw new TypeError('Could not show notification as notifications service is not available.');
}
services.notifications!.toasts.add({
title,
text: <>{body || null}</>,
title: reactMount(title),
text: reactMount(<>{body || null}</>),
color,
iconType,
toastLifeTimeMs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { i18n } from '@kbn/i18n';
import React, { Component } from 'react';
import { reactMount } from '../../../../../../../../../../src/plugins/kibana_react/public';
import { startMLJob } from '../../../../../services/rest/ml';
import { IUrlParams } from '../../../../../context/UrlParamsContext/types';
import { MLJobLink } from '../../../../shared/Links/MachineLearningLinks/MLJobLink';
Expand Down Expand Up @@ -71,7 +72,7 @@ export class MachineLearningFlyout extends Component<Props, State> {
defaultMessage: 'Job creation failed'
}
),
text: (
text: reactMount(
<p>
{i18n.translate(
'xpack.apm.serviceDetails.enableAnomalyDetectionPanel.jobCreationFailedNotificationText',
Expand Down Expand Up @@ -105,7 +106,7 @@ export class MachineLearningFlyout extends Component<Props, State> {
defaultMessage: 'Job successfully created'
}
),
text: (
text: reactMount(
<p>
{i18n.translate(
'xpack.apm.serviceDetails.enableAnomalyDetectionPanel.jobCreatedNotificationText',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { padLeft, range } from 'lodash';
import moment from 'moment-timezone';
import React, { Component } from 'react';
import styled from 'styled-components';
import { reactMount } from '../../../../../../../../../src/plugins/kibana_react/public';
import { KibanaCoreContext } from '../../../../../../observability/public';
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
import { KibanaLink } from '../../../shared/Links/KibanaLink';
Expand Down Expand Up @@ -219,7 +220,7 @@ export class WatcherFlyout extends Component<
defaultMessage: 'Watch creation failed'
}
),
text: (
text: reactMount(
<p>
{i18n.translate(
'xpack.apm.serviceDetails.enableErrorReportsPanel.watchCreationFailedNotificationText',
Expand All @@ -243,7 +244,7 @@ export class WatcherFlyout extends Component<
defaultMessage: 'New watch created!'
}
),
text: (
text: reactMount(
<p>
{i18n.translate(
'xpack.apm.serviceDetails.enableErrorReportsPanel.watchCreatedNotificationText',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useEffect, useMemo } from 'react';
import url from 'url';
import { reactMount } from '../../../../../../../../src/plugins/kibana_react/public';
import { useFetcher } from '../../../hooks/useFetcher';
import { NoServicesMessage } from './NoServicesMessage';
import { ServiceList } from './ServiceList';
Expand Down Expand Up @@ -55,7 +56,7 @@ export function ServiceOverview() {
defaultMessage:
'Legacy data was detected within the selected time range'
}),
text: (
text: reactMount(
<p>
{i18n.translate('xpack.apm.serviceOverview.toastText', {
defaultMessage:
Expand Down
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/apm/public/hooks/useFetcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { useContext, useEffect, useState, useMemo } from 'react';
import { idx } from '@kbn/elastic-idx';
import { i18n } from '@kbn/i18n';
import { IHttpFetchError } from 'src/core/public';
import { reactMount } from '../../../../../../src/plugins/kibana_react/public';
import { LoadingIndicatorContext } from '../context/LoadingIndicatorContext';
import { useComponentId } from './useComponentId';
import { useKibanaCore } from '../../../observability/public';
Expand Down Expand Up @@ -92,7 +93,7 @@ export function useFetcher<TReturn>(
title: i18n.translate('xpack.apm.fetcher.error.title', {
defaultMessage: `Error while fetching resource`
}),
text: (
text: reactMount(
<div>
<h5>
{i18n.translate('xpack.apm.fetcher.error.status', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { toastNotifications } from 'ui/notify';
import { i18n } from '@kbn/i18n';
import { idx } from '@kbn/elastic-idx/target';
import { KFetchError } from 'ui/kfetch/kfetch_error';
import { reactMount } from '../../../../../../src/plugins/kibana_react/public';
import { useTrackedPromise } from '../utils/use_tracked_promise';
export function useHTTPRequest<Response>(
pathname: string,
Expand All @@ -36,7 +37,7 @@ export function useHTTPRequest<Response>(
title: i18n.translate('xpack.infra.useHTTPRequest.error.title', {
defaultMessage: `Error while fetching resource`,
}),
text: (
text: reactMount(
<div>
<h5>
{i18n.translate('xpack.infra.useHTTPRequest.error.status', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React, { Component, ReactElement } from 'react';
import { KFetchError } from 'ui/kfetch/kfetch_error';
import { toastNotifications } from 'ui/notify';
import url from 'url';
import { reactMount } from '../../../../../../src/plugins/kibana_react/public';
import { reportingClient } from '../lib/reporting_client';

interface Props {
Expand Down Expand Up @@ -209,7 +210,7 @@ class ReportingPanelContentUi extends Component<Props, State> {
},
{ objectType: this.props.objectType }
),
text: (
text: reactMount(
<FormattedMessage
id="xpack.reporting.panelContent.successfullyQueuedReportNotificationDescription"
defaultMessage="Track its progress in Management"
Expand All @@ -229,7 +230,7 @@ class ReportingPanelContentUi extends Component<Props, State> {
},
{ objectType: this.props.objectType }
),
text: (
text: reactMount(
<FormattedMessage
id="xpack.reporting.panelContent.whatCanBeExportedWarningDescription"
defaultMessage="Please save your work first"
Expand All @@ -256,7 +257,7 @@ class ReportingPanelContentUi extends Component<Props, State> {
id: 'xpack.reporting.panelContent.notification.reportingErrorTitle',
defaultMessage: 'Reporting error',
}),
text: kfetchError.message || defaultMessage,
text: reactMount(kfetchError.message || defaultMessage),
'data-test-subj': 'queueReportError',
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React from 'react';

import { i18n } from '@kbn/i18n';
import { toastNotifications } from 'ui/notify';
import { reactMount } from '../../../../../../../src/plugins/kibana_react/public';

import { TransformListRow, refreshTransformList$, REFRESH_TRANSFORM_LIST_STATE } from '../common';
import { ToastNotificationText } from '../components';
Expand Down Expand Up @@ -53,7 +54,7 @@ export const useDeleteTransforms = () => {
title: i18n.translate('xpack.transform.transformList.deleteTransformGenericErrorMessage', {
defaultMessage: 'An error occurred calling the API endpoint to delete transforms.',
}),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
EuiText,
} from '@elastic/eui';

import { reactMount } from '../../../../../../../../../../src/plugins/kibana_react/public';
import { ToastNotificationText } from '../../../../components';
import { useApi } from '../../../../hooks/use_api';
import { isKibanaContextInitialized, KibanaContext } from '../../../../lib/kibana';
Expand Down Expand Up @@ -112,7 +113,7 @@ export const StepCreateForm: SFC<Props> = React.memo(
defaultMessage: 'An error occurred creating the transform {transformId}:',
values: { transformId },
}),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
return false;
}
Expand Down Expand Up @@ -142,7 +143,7 @@ export const StepCreateForm: SFC<Props> = React.memo(
defaultMessage: 'An error occurred starting the transform {transformId}:',
values: { transformId },
}),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
}
}
Expand Down Expand Up @@ -201,7 +202,7 @@ export const StepCreateForm: SFC<Props> = React.memo(
'An error occurred creating the Kibana index pattern {indexPatternName}:',
values: { indexPatternName },
}),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
return false;
}
Expand Down Expand Up @@ -232,7 +233,7 @@ export const StepCreateForm: SFC<Props> = React.memo(
title: i18n.translate('xpack.transform.stepCreateForm.progressErrorMessage', {
defaultMessage: 'An error occurred getting the progress percentage:',
}),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
clearInterval(interval);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { toastNotifications } from 'ui/notify';

import { EuiLink, EuiSwitch, EuiFieldText, EuiForm, EuiFormRow, EuiSelect } from '@elastic/eui';

import { reactMount } from '../../../../../../../../../../src/plugins/kibana_react/public';
import { isKibanaContextInitialized, KibanaContext } from '../../../../lib/kibana';
import { isValidIndexName } from '../../../../../../common/utils/es_utils';

Expand Down Expand Up @@ -91,7 +92,7 @@ export const StepDetailsForm: SFC<Props> = React.memo(({ overrides = {}, onChang
title: i18n.translate('xpack.transform.stepDetailsForm.errorGettingTransformList', {
defaultMessage: 'An error occurred getting the existing transform IDs:',
}),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
}

Expand All @@ -102,7 +103,7 @@ export const StepDetailsForm: SFC<Props> = React.memo(({ overrides = {}, onChang
title: i18n.translate('xpack.transform.stepDetailsForm.errorGettingIndexNames', {
defaultMessage: 'An error occurred getting the existing index names:',
}),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
}

Expand All @@ -116,7 +117,7 @@ export const StepDetailsForm: SFC<Props> = React.memo(({ overrides = {}, onChang
defaultMessage: 'An error occurred getting the existing index pattern titles:',
}
),
text: <ToastNotificationText text={e} />,
text: reactMount(<ToastNotificationText text={e} />),
});
}
}
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/reporting/public/components/general_error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import React, { Fragment } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import { ToastInput } from '../../../../../src/core/public';
import { reactMount } from '../../../../../src/plugins/kibana_react/public';

export const getGeneralErrorToast = (errorText: string, err: Error): ToastInput => ({
text: (
text: reactMount(
<Fragment>
<EuiCallOut title={errorText} color="danger" iconType="alert">
{err.toString()}
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/reporting/public/components/job_failure.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import { ToastInput } from '../../../../../src/core/public';
import { reactMount } from '../../../../../src/plugins/kibana_react/public';
import { JobSummary, ManagementLinkFn } from '../../index.d';

export const getFailureToast = (
Expand All @@ -17,14 +18,14 @@ export const getFailureToast = (
getManagmenetLink: ManagementLinkFn
): ToastInput => {
return {
title: (
title: reactMount(
<FormattedMessage
id="xpack.reporting.publicNotifier.error.couldNotCreateReportTitle"
defaultMessage="Could not create report for {reportObjectType} '{reportObjectTitle}'."
values={{ reportObjectType: job.type, reportObjectTitle: job.title }}
/>
),
text: (
text: reactMount(
<Fragment>
<EuiCallOut
size="m"
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/reporting/public/components/job_success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React, { Fragment } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { ToastInput } from '../../../../../src/core/public';
import { reactMount } from '../../../../../src/plugins/kibana_react/public';
import { JobId, JobSummary } from '../../index.d';
import { ReportLink } from './report_link';
import { DownloadButton } from './download_button';
Expand All @@ -16,15 +17,15 @@ export const getSuccessToast = (
getReportLink: () => string,
getDownloadLink: (jobId: JobId) => string
): ToastInput => ({
title: (
title: reactMount(
<FormattedMessage
id="xpack.reporting.publicNotifier.successfullyCreatedReportNotificationTitle"
defaultMessage="Created report for {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.type, reportObjectTitle: job.title }}
/>
),
color: 'success',
text: (
text: reactMount(
<Fragment>
<p>
<ReportLink getUrl={getReportLink} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import React, { Fragment } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { ToastInput } from '../../../../../src/core/public';
import { reactMount } from '../../../../../src/plugins/kibana_react/public';
import { JobId, JobSummary } from '../../index.d';
import { ReportLink } from './report_link';
import { DownloadButton } from './download_button';
Expand All @@ -16,14 +17,14 @@ export const getWarningFormulasToast = (
getReportLink: () => string,
getDownloadLink: (jobId: JobId) => string
): ToastInput => ({
title: (
title: reactMount(
<FormattedMessage
id="xpack.reporting.publicNotifier.csvContainsFormulas.formulaReportTitle"
defaultMessage="Report may contain formulas {reportObjectType} '{reportObjectTitle}'"
values={{ reportObjectType: job.type, reportObjectTitle: job.title }}
/>
),
text: (
text: reactMount(
<Fragment>
<p>
<FormattedMessage
Expand Down
Loading

0 comments on commit d45da3e

Please sign in to comment.