kibana/x-pack/plugins/file_upload/public/get_file_upload_component.ts
Nathan Reese 187a13075b
[file upload] lazy load to reduce page load size (#74967)
* [file upload] lazy load to reduce page load size

* tslint
2020-08-14 07:15:16 -06:00

39 lines
1.2 KiB
TypeScript

/*
* 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<React.ComponentType<FileUploadComponentProps>>;
export async function getFileUploadComponent(): Promise<
React.ComponentType<FileUploadComponentProps>
> {
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;
}