-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rename advanced setting ml:fileDataVisualizerMaxFileSize to fileUploa…
…d:maxFileSize and increase max geojson upload size to 1GB (#92620) * rename ml:fileDataVisualizerMaxFileSize to fileUppload:maxFileSize * add saved object migration * file preview * importing status * remove console statement * import complete view * fix geojson_importer test * tslint * i18n fixes * cleanup * update documenation for advanced setting rename * advanced settings usage_collection * remove ml:fileDataVisualizerMaxFileSize from schemas and types * add copy buttons for import response and fix geojson upload functional tests * tslint * remove clipboard-read check * return early if env does not support reading from clipboard * fix reporting tests * review feedback * update GeoJsonFileSource to support showing results trimmed icon and tooltip * add fileUpload to useMlKibana context and replace dependencyCache with useMlKibana * tslint * review feedback * lower case file name * default to selecting geo_shape when file contains both points and shapes * fix wizard onError callback to not advance to next step Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
- Loading branch information
1 parent
57a860d
commit bd9b349
Showing
47 changed files
with
1,428 additions
and
940 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
x-pack/plugins/file_upload/public/components/geojson_file_picker.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { Component } from 'react'; | ||
import { EuiFilePicker, EuiFormRow } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { MB } from '../../common'; | ||
import { getMaxBytesFormatted } from '../get_max_bytes'; | ||
import { validateFile } from '../importer'; | ||
import { GeoJsonImporter, GeoJsonPreview, GEOJSON_FILE_TYPES } from '../importer/geojson_importer'; | ||
|
||
interface Props { | ||
onSelect: ({ | ||
features, | ||
hasPoints, | ||
hasShapes, | ||
importer, | ||
indexName, | ||
previewCoverage, | ||
}: GeoJsonPreview & { | ||
indexName: string; | ||
importer: GeoJsonImporter; | ||
}) => void; | ||
onClear: () => void; | ||
} | ||
|
||
interface State { | ||
error: string | null; | ||
isLoadingPreview: boolean; | ||
previewSummary: string | null; | ||
} | ||
|
||
export class GeoJsonFilePicker extends Component<Props, State> { | ||
private _isMounted = false; | ||
|
||
state: State = { | ||
error: null, | ||
isLoadingPreview: false, | ||
previewSummary: null, | ||
}; | ||
|
||
async componentDidMount() { | ||
this._isMounted = true; | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
_onFileSelect = (files: FileList | null) => { | ||
this.props.onClear(); | ||
|
||
this.setState({ | ||
error: null, | ||
isLoadingPreview: false, | ||
previewSummary: null, | ||
}); | ||
|
||
if (files && files.length) { | ||
this._loadFilePreview(files[0]); | ||
} | ||
}; | ||
|
||
async _loadFilePreview(file: File) { | ||
this.setState({ isLoadingPreview: true }); | ||
|
||
let importer: GeoJsonImporter | null = null; | ||
let previewError: string | null = null; | ||
let preview: GeoJsonPreview | null = null; | ||
try { | ||
validateFile(file, GEOJSON_FILE_TYPES); | ||
importer = new GeoJsonImporter(file); | ||
preview = await importer.previewFile(10000, MB * 3); | ||
if (preview.features.length === 0) { | ||
previewError = i18n.translate('xpack.fileUpload.geojsonFilePicker.noFeaturesDetected', { | ||
defaultMessage: 'No GeoJson features found in selected file.', | ||
}); | ||
} | ||
} catch (error) { | ||
previewError = error.message; | ||
} | ||
|
||
if (!this._isMounted) { | ||
return; | ||
} | ||
|
||
this.setState({ | ||
error: previewError, | ||
isLoadingPreview: false, | ||
previewSummary: | ||
!previewError && preview | ||
? i18n.translate('xpack.fileUpload.geojsonFilePicker.previewSummary', { | ||
defaultMessage: 'Previewing {numFeatures} features, {previewCoverage}% of file.', | ||
values: { | ||
numFeatures: preview.features.length, | ||
previewCoverage: preview.previewCoverage, | ||
}, | ||
}) | ||
: null, | ||
}); | ||
|
||
if (importer && preview) { | ||
this.props.onSelect({ | ||
...preview, | ||
importer, | ||
indexName: file.name.split('.')[0].toLowerCase(), | ||
}); | ||
} | ||
} | ||
|
||
_renderHelpText() { | ||
return this.state.previewSummary !== null ? ( | ||
this.state.previewSummary | ||
) : ( | ||
<span> | ||
{i18n.translate('xpack.fileUpload.geojsonFilePicker.acceptedFormats', { | ||
defaultMessage: 'Formats accepted: {fileTypes}', | ||
values: { fileTypes: GEOJSON_FILE_TYPES.join(', ') }, | ||
})} | ||
<br /> | ||
{i18n.translate('xpack.fileUpload.geojsonFilePicker.maxSize', { | ||
defaultMessage: 'Max size: {maxFileSize}', | ||
values: { maxFileSize: getMaxBytesFormatted() }, | ||
})} | ||
<br /> | ||
{i18n.translate('xpack.fileUpload.geojsonFilePicker.acceptedCoordinateSystem', { | ||
defaultMessage: 'Coordinates must be in EPSG:4326 coordinate reference system.', | ||
})} | ||
</span> | ||
); | ||
} | ||
|
||
render() { | ||
return ( | ||
<EuiFormRow | ||
isInvalid={!!this.state.error} | ||
error={!!this.state.error ? [this.state.error] : []} | ||
helpText={this._renderHelpText()} | ||
> | ||
<EuiFilePicker | ||
initialPromptText={i18n.translate('xpack.fileUpload.geojsonFilePicker.filePicker', { | ||
defaultMessage: 'Select or drag and drop a file', | ||
})} | ||
onChange={this._onFileSelect} | ||
accept={GEOJSON_FILE_TYPES.join(',')} | ||
isLoading={this.state.isLoadingPreview} | ||
/> | ||
</EuiFormRow> | ||
); | ||
} | ||
} |
Oops, something went wrong.