Skip to content

Commit

Permalink
[APM] Lazy-load alert triggers (elastic#68806)
Browse files Browse the repository at this point in the history
Use `React.lazy` to load the alert triggers so the code doesn't load until the alert flyout is opened.

Fixes elastic#66189.
  • Loading branch information
smith committed Jun 10, 2020
1 parent 681ab59 commit e511a1f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,8 @@ export function ErrorRateAlertTrigger(props: Props) {
/>
);
}

// Default export is required for React.lazy loading
//
// eslint-disable-next-line import/no-default-export
export default ErrorRateAlertTrigger;
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,8 @@ export function TransactionDurationAlertTrigger(props: Props) {
/>
);
}

// Default export is required for React.lazy loading
//
// eslint-disable-next-line import/no-default-export
export default TransactionDurationAlertTrigger;
32 changes: 17 additions & 15 deletions x-pack/plugins/apm/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,38 @@
*/

import { i18n } from '@kbn/i18n';
import { lazy } from 'react';
import { ConfigSchema } from '.';
import {
AppMountParameters,
CoreSetup,
CoreStart,
DEFAULT_APP_CATEGORIES,
Plugin,
PluginInitializerContext,
} from '../../../../src/core/public';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/public';

import {
PluginSetupContract as AlertingPluginPublicSetup,
PluginStartContract as AlertingPluginPublicStart,
} from '../../alerts/public';
import { FeaturesPluginSetup } from '../../features/public';
import {
DataPublicPluginSetup,
DataPublicPluginStart,
} from '../../../../src/plugins/data/public';
import { HomePublicPluginSetup } from '../../../../src/plugins/home/public';
import {
PluginSetupContract as AlertingPluginPublicSetup,
PluginStartContract as AlertingPluginPublicStart,
} from '../../alerts/public';
import { FeaturesPluginSetup } from '../../features/public';
import { LicensingPluginSetup } from '../../licensing/public';
import {
TriggersAndActionsUIPublicPluginSetup,
TriggersAndActionsUIPublicPluginStart,
} from '../../triggers_actions_ui/public';
import { ConfigSchema } from '.';
import { createCallApmApi } from './services/rest/createCallApmApi';
import { featureCatalogueEntry } from './featureCatalogueEntry';
import { AlertType } from '../common/alert_types';
import { ErrorRateAlertTrigger } from './components/shared/ErrorRateAlertTrigger';
import { TransactionDurationAlertTrigger } from './components/shared/TransactionDurationAlertTrigger';
import { featureCatalogueEntry } from './featureCatalogueEntry';
import { createCallApmApi } from './services/rest/createCallApmApi';
import { createStaticIndexPattern } from './services/rest/index_pattern';
import { setHelpExtension } from './setHelpExtension';
import { toggleAppLinkInNav } from './toggleAppLinkInNav';
import { setReadonlyBadge } from './updateBadge';
import { createStaticIndexPattern } from './services/rest/index_pattern';

export type ApmPluginSetup = void;
export type ApmPluginStart = void;
Expand Down Expand Up @@ -112,7 +110,9 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
defaultMessage: 'Error rate',
}),
iconClass: 'bell',
alertParamsExpression: ErrorRateAlertTrigger,
alertParamsExpression: lazy(() =>
import('./components/shared/ErrorRateAlertTrigger')
),
validate: () => ({
errors: [],
}),
Expand All @@ -125,7 +125,9 @@ export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> {
defaultMessage: 'Transaction duration',
}),
iconClass: 'bell',
alertParamsExpression: TransactionDurationAlertTrigger,
alertParamsExpression: lazy(() =>
import('./components/shared/TransactionDurationAlertTrigger')
),
validate: () => ({
errors: [],
}),
Expand Down

0 comments on commit e511a1f

Please sign in to comment.