Skip to content

Commit 27c90ef

Browse files
committed
load VisEditor lazily
1 parent aafbb8a commit 27c90ef

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

src/plugins/vis_type_timeseries/public/application/components/vis_editor.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,3 +240,7 @@ VisEditor.propTypes = {
240240
timeRange: PropTypes.object,
241241
appState: PropTypes.object,
242242
};
243+
244+
// default export required for React.Lazy
245+
// eslint-disable-next-line import/no-default-export
246+
export { VisEditor as default };
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import React, { lazy, Suspense } from 'react';
21+
import { EuiLoadingSpinner } from '@elastic/eui';
22+
23+
// @ts-ignore
24+
const VisEditorComponent = lazy(() => import('./vis_editor'));
25+
26+
export const VisEditor = (props: any) => (
27+
<Suspense fallback={<EuiLoadingSpinner />}>
28+
<VisEditorComponent {...props} />
29+
</Suspense>
30+
);

src/plugins/vis_type_timeseries/public/application/editor_controller.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import React from 'react';
2121
import { render, unmountComponentAtNode } from 'react-dom';
2222
import { fetchIndexPatternFields } from './lib/fetch_fields';
2323
import { getSavedObjectsClient, getUISettings, getI18n } from '../services';
24-
import { VisEditor } from './components/vis_editor';
24+
import { VisEditor } from './components/vis_editor_lazy';
2525

2626
export class EditorController {
2727
constructor(el, vis, eventEmitter, embeddableHandler) {

src/plugins/vis_type_timeseries/public/metrics_type.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { EditorController } from './application';
2525
// @ts-ignore
2626
import { PANEL_TYPES } from '../common/panel_types';
2727
import { defaultFeedbackMessage } from '../../kibana_utils/public';
28+
import { VisEditor } from './application/components/vis_editor_lazy';
2829

2930
export const metricsVisDefinition = {
3031
name: 'metrics',
@@ -69,7 +70,7 @@ export const metricsVisDefinition = {
6970
show_legend: 1,
7071
show_grid: 1,
7172
},
72-
component: require('./application/components/vis_editor').VisEditor,
73+
component: VisEditor,
7374
},
7475
editor: EditorController,
7576
options: {

0 commit comments

Comments
 (0)