Skip to content

Commit c9d6835

Browse files
committed
add lazy loading
1 parent 7049cae commit c9d6835

8 files changed

Lines changed: 34 additions & 11 deletions

File tree

src/plugins/index_pattern_editor/public/components/empty_prompts/empty_index_pattern_prompt/empty_index_pattern_prompt.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ interface Props {
2121
indexPatternsIntroUrl: string;
2222
}
2323

24+
const Illustration = lazy(() => import('./assets/index_pattern_illustration'));
25+
2426
export const EmptyIndexPatternPrompt = ({
2527
goToCreate,
2628
canSaveIndexPattern,
2729
indexPatternsIntroUrl,
2830
}: Props) => {
29-
const Illustration = lazy(() => import('./assets/index_pattern_illustration'));
30-
3131
return (
3232
<EuiPageContent
3333
data-test-subj="emptyIndexPatternPrompt"

src/plugins/index_pattern_editor/public/components/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ export {
1111
Props as IndexPatternEditorFlyoutContentProps,
1212
} from './index_pattern_editor_flyout_content';
1313

14-
export { IndexPatternFlyoutContentContainer } from './index_pattern_flyout_content_container';
15-
1614
export { IndexPatternEditor } from './index_pattern_editor';
1715

1816
export { schema } from './form_schema';

src/plugins/index_pattern_editor/public/components/index_pattern_editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import React from 'react';
1010
import { EuiFlyout } from '@elastic/eui';
11-
import { IndexPatternFlyoutContentContainer } from './index_pattern_flyout_content_container';
11+
import { IndexPatternEditorLazy } from './index_pattern_editor_lazy';
1212
import { IndexPatternEditorContext, IndexPatternEditorProps } from '../types';
1313
import { createKibanaReactContext } from '../shared_imports';
1414
import './index_pattern_editor.scss';
@@ -31,7 +31,7 @@ export const IndexPatternEditor = ({
3131
return (
3232
<KibanaReactContextProvider>
3333
<EuiFlyout onClose={() => {}} hideCloseButton={true} size="l">
34-
<IndexPatternFlyoutContentContainer
34+
<IndexPatternEditorLazy
3535
onSave={onSave}
3636
onCancel={onCancel}
3737
defaultTypeIsRollup={defaultTypeIsRollup}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0 and the Server Side Public License, v 1; you may not use this file except
5+
* in compliance with, at your election, the Elastic License 2.0 or the Server
6+
* Side Public License, v 1.
7+
*/
8+
9+
import React, { lazy, Suspense } from 'react';
10+
import { EuiLoadingSpinner } from '@elastic/eui';
11+
12+
import { IndexPatternEditorProps } from '../types';
13+
14+
const IndexPatternFlyoutContentContainer = lazy(
15+
() => import('./index_pattern_flyout_content_container')
16+
);
17+
18+
export const IndexPatternEditorLazy = (props: IndexPatternEditorProps) => (
19+
<Suspense fallback={<EuiLoadingSpinner size="xl" />}>
20+
<IndexPatternFlyoutContentContainer {...props} />
21+
</Suspense>
22+
);

src/plugins/index_pattern_editor/public/components/index_pattern_flyout_content_container.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { IndexPatternSpec, useKibana } from '../shared_imports';
1313
import { IndexPatternEditorFlyoutContent } from './index_pattern_editor_flyout_content';
1414
import { IndexPatternEditorContext, IndexPatternEditorProps } from '../types';
1515

16-
export const IndexPatternFlyoutContentContainer = ({
16+
const IndexPatternFlyoutContentContainer = ({
1717
onSave,
1818
onCancel = () => {},
1919
defaultTypeIsRollup,
@@ -51,3 +51,6 @@ export const IndexPatternFlyoutContentContainer = ({
5151
/>
5252
);
5353
};
54+
55+
/* eslint-disable import/no-default-export */
56+
export default IndexPatternFlyoutContentContainer;

src/plugins/index_pattern_editor/public/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import { IndexPatternEditorPlugin } from './plugin';
2222

23-
export { PluginStart as IndexPatternEditorStart, IndexPatternEditorProps } from './types';
23+
export type { PluginStart as IndexPatternEditorStart, IndexPatternEditorProps } from './types';
2424

2525
export function plugin() {
2626
return new IndexPatternEditorPlugin();

src/plugins/index_pattern_editor/public/open_editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
} from './shared_imports';
1919

2020
import { CloseEditor, IndexPatternEditorContext, IndexPatternEditorProps } from './types';
21-
import { IndexPatternFlyoutContentContainer } from './components/index_pattern_flyout_content_container';
21+
import { IndexPatternEditorLazy } from './components/index_pattern_editor_lazy';
2222

2323
interface Dependencies {
2424
core: CoreStart;
@@ -67,7 +67,7 @@ export const getEditorOpener = ({ core, indexPatternService }: Dependencies) =>
6767
toMountPoint(
6868
<KibanaReactContextProvider>
6969
<I18nProvider>
70-
<IndexPatternFlyoutContentContainer
70+
<IndexPatternEditorLazy
7171
onSave={onSaveIndexPattern}
7272
onCancel={() => {
7373
closeEditor();

src/plugins/index_pattern_editor/public/plugin.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
IndexPatternEditorProps,
1818
} from './types';
1919
import { getEditorOpener } from './open_editor';
20-
import { IndexPatternEditor } from './components';
20+
import { IndexPatternEditor } from './components/index_pattern_editor';
2121

2222
export class IndexPatternEditorPlugin
2323
implements Plugin<PluginSetup, PluginStart, SetupPlugins, StartPlugins> {

0 commit comments

Comments
 (0)