diff --git a/x-pack/plugins/file_upload/public/get_file_upload_component.ts b/x-pack/plugins/file_upload/public/get_file_upload_component.ts new file mode 100644 index 0000000000000..7232c4126e297 --- /dev/null +++ b/x-pack/plugins/file_upload/public/get_file_upload_component.ts @@ -0,0 +1,38 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { FeatureCollection } from 'geojson'; + +export interface FileUploadComponentProps { + appName: string; + isIndexingTriggered: boolean; + onFileUpload: (geojsonFile: FeatureCollection, name: string) => void; + onFileRemove: () => void; + onIndexReady: (indexReady: boolean) => void; + transformDetails: string; + onIndexingComplete: (indexResponses: { + indexDataResp: unknown; + indexPatternResp: unknown; + }) => void; +} + +let lazyLoadPromise: Promise>; + +export async function getFileUploadComponent(): Promise< + React.ComponentType +> { + if (typeof lazyLoadPromise !== 'undefined') { + return lazyLoadPromise; + } + + lazyLoadPromise = new Promise(async (resolve) => { + // @ts-expect-error + const { JsonUploadAndParse } = await import('./components/json_upload_and_parse'); + resolve(JsonUploadAndParse); + }); + return lazyLoadPromise; +} diff --git a/x-pack/plugins/file_upload/public/index.ts b/x-pack/plugins/file_upload/public/index.ts index 205ceae37d6a1..1e39fb4dc8596 100644 --- a/x-pack/plugins/file_upload/public/index.ts +++ b/x-pack/plugins/file_upload/public/index.ts @@ -9,3 +9,5 @@ import { FileUploadPlugin } from './plugin'; export function plugin() { return new FileUploadPlugin(); } + +export { FileUploadComponentProps } from './get_file_upload_component'; diff --git a/x-pack/plugins/file_upload/public/plugin.ts b/x-pack/plugins/file_upload/public/plugin.ts index 338c61ad141c6..ff74be659aeca 100644 --- a/x-pack/plugins/file_upload/public/plugin.ts +++ b/x-pack/plugins/file_upload/public/plugin.ts @@ -4,10 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -// @ts-ignore import { CoreSetup, CoreStart, Plugin } from 'kibana/server'; -// @ts-ignore -import { JsonUploadAndParse } from './components/json_upload_and_parse'; +import { getFileUploadComponent } from './get_file_upload_component'; // @ts-ignore import { setupInitServicesAndConstants, startInitServicesAndConstants } from './kibana_services'; import { IDataPluginServices } from '../../../../src/plugins/data/public'; @@ -35,7 +33,7 @@ export class FileUploadPlugin implements Plugin | null; } export class ClientFileCreateSourceEditor extends Component { private _isMounted: boolean = false; - state = { + state: State = { indexingStage: null, + fileUploadComponent: null, }; componentDidMount() { this._isMounted = true; + this._loadFileUploadComponent(); } componentWillUnmount() { @@ -59,6 +63,13 @@ export class ClientFileCreateSourceEditor extends Component { if (!this._isMounted) { return; @@ -145,7 +156,11 @@ export class ClientFileCreateSourceEditor extends Component >; export function getIndexPatternSelectComponent(): any; export function getHttp(): any; export function getTimeFilter(): any; diff --git a/x-pack/plugins/maps/public/kibana_services.js b/x-pack/plugins/maps/public/kibana_services.js index 9b035a87a3b37..64aa0e07ffafb 100644 --- a/x-pack/plugins/maps/public/kibana_services.js +++ b/x-pack/plugins/maps/public/kibana_services.js @@ -33,8 +33,8 @@ export const getInspector = () => { let fileUploadPlugin; export const setFileUpload = (fileUpload) => (fileUploadPlugin = fileUpload); -export const getFileUploadComponent = () => { - return fileUploadPlugin.JsonUploadAndParse; +export const getFileUploadComponent = async () => { + return await fileUploadPlugin.getFileUploadComponent(); }; let uiSettings;