Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce visTypeTimeseries bundle size #64631

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,7 @@ VisEditor.propTypes = {
timeRange: PropTypes.object,
appState: PropTypes.object,
};

// default export required for React.Lazy
// eslint-disable-next-line import/no-default-export
export { VisEditor as default };
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import React, { lazy, Suspense } from 'react';
import { EuiLoadingSpinner } from '@elastic/eui';

// @ts-ignore
const VisEditorComponent = lazy(() => import('./vis_editor'));

export const VisEditor = (props: any) => (
<Suspense fallback={<EuiLoadingSpinner />}>
<VisEditorComponent {...props} />
</Suspense>
);
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { fetchIndexPatternFields } from './lib/fetch_fields';
import { getSavedObjectsClient, getUISettings, getI18n } from '../services';
import { VisEditor } from './components/vis_editor';
import { VisEditor } from './components/vis_editor_lazy';

export class EditorController {
constructor(el, vis, eventEmitter, embeddableHandler) {
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/vis_type_timeseries/public/metrics_fn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import { get } from 'lodash';
import { i18n } from '@kbn/i18n';
import { ExpressionFunctionDefinition, KibanaContext, Render } from '../../expressions/public';
import { PersistedState } from '../../visualizations/public';

// @ts-ignore
import { metricsRequestHandler } from './request_handler';
Expand Down Expand Up @@ -76,6 +75,7 @@ export const createMetricsFn = (): ExpressionFunctionDefinition<
const params = JSON.parse(args.params);
const uiStateParams = JSON.parse(args.uiState);
const savedObjectId = args.savedObjectId;
const { PersistedState } = await import('../../visualizations/public');
const uiState = new PersistedState(uiStateParams);

const response = await metricsRequestHandler({
Expand Down
3 changes: 2 additions & 1 deletion src/plugins/vis_type_timeseries/public/metrics_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { EditorController } from './application';
// @ts-ignore
import { PANEL_TYPES } from '../common/panel_types';
import { defaultFeedbackMessage } from '../../kibana_utils/public';
import { VisEditor } from './application/components/vis_editor_lazy';

export const metricsVisDefinition = {
name: 'metrics',
Expand Down Expand Up @@ -69,7 +70,7 @@ export const metricsVisDefinition = {
show_legend: 1,
show_grid: 1,
},
component: require('./application/components/vis_editor').VisEditor,
component: VisEditor,
},
editor: EditorController,
options: {
Expand Down