-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [Maps] remove indexing state from redux * add indexing step * tslint * tslint fixes * tslint item * clear preview when file changes * review feedback * use prevState instead of this.state in setState Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
a6de9a7
commit 69bc772
Showing
15 changed files
with
356 additions
and
368 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
29 changes: 0 additions & 29 deletions
29
...lugins/maps/public/classes/sources/client_file_source/create_client_file_source_editor.js
This file was deleted.
Oops, something went wrong.
160 changes: 160 additions & 0 deletions
160
...ugins/maps/public/classes/sources/client_file_source/create_client_file_source_editor.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,160 @@ | ||
/* | ||
* 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, { Component } from 'react'; | ||
import { IFieldType } from 'src/plugins/data/public'; | ||
import { | ||
ES_GEO_FIELD_TYPE, | ||
DEFAULT_MAX_RESULT_WINDOW, | ||
SCALING_TYPES, | ||
} from '../../../../common/constants'; | ||
import { getFileUploadComponent } from '../../../kibana_services'; | ||
// @ts-ignore | ||
import { GeojsonFileSource } from './geojson_file_source'; | ||
import { VectorLayer } from '../../layers/vector_layer/vector_layer'; | ||
// @ts-ignore | ||
import { createDefaultLayerDescriptor } from '../es_search_source'; | ||
import { RenderWizardArguments } from '../../layers/layer_wizard_registry'; | ||
|
||
export const INDEX_SETUP_STEP_ID = 'INDEX_SETUP_STEP_ID'; | ||
export const INDEXING_STEP_ID = 'INDEXING_STEP_ID'; | ||
|
||
enum INDEXING_STAGE { | ||
READY = 'READY', | ||
TRIGGERED = 'TRIGGERED', | ||
SUCCESS = 'SUCCESS', | ||
ERROR = 'ERROR', | ||
} | ||
|
||
interface State { | ||
indexingStage: INDEXING_STAGE | null; | ||
} | ||
|
||
export class ClientFileCreateSourceEditor extends Component<RenderWizardArguments, State> { | ||
private _isMounted: boolean = false; | ||
|
||
state = { | ||
indexingStage: null, | ||
}; | ||
|
||
componentDidMount() { | ||
this._isMounted = true; | ||
} | ||
|
||
componentWillUnmount() { | ||
this._isMounted = false; | ||
} | ||
|
||
componentDidUpdate() { | ||
if ( | ||
this.props.currentStepId === INDEXING_STEP_ID && | ||
this.state.indexingStage === INDEXING_STAGE.READY | ||
) { | ||
this.setState({ indexingStage: INDEXING_STAGE.TRIGGERED }); | ||
this.props.startStepLoading(); | ||
} | ||
} | ||
|
||
_onFileUpload = (geojsonFile: unknown, name: string) => { | ||
if (!this._isMounted) { | ||
return; | ||
} | ||
|
||
if (!geojsonFile) { | ||
this.props.previewLayers([]); | ||
return; | ||
} | ||
|
||
const sourceDescriptor = GeojsonFileSource.createDescriptor(geojsonFile, name); | ||
const layerDescriptor = VectorLayer.createDescriptor( | ||
{ sourceDescriptor }, | ||
this.props.mapColors | ||
); | ||
this.props.previewLayers([layerDescriptor]); | ||
}; | ||
|
||
_onIndexingComplete = (indexResponses: { indexDataResp: unknown; indexPatternResp: unknown }) => { | ||
if (!this._isMounted) { | ||
return; | ||
} | ||
|
||
this.props.advanceToNextStep(); | ||
|
||
const { indexDataResp, indexPatternResp } = indexResponses; | ||
|
||
// @ts-ignore | ||
const indexCreationFailed = !(indexDataResp && indexDataResp.success); | ||
// @ts-ignore | ||
const allDocsFailed = indexDataResp.failures.length === indexDataResp.docCount; | ||
// @ts-ignore | ||
const indexPatternCreationFailed = !(indexPatternResp && indexPatternResp.success); | ||
if (indexCreationFailed || allDocsFailed || indexPatternCreationFailed) { | ||
this.setState({ indexingStage: INDEXING_STAGE.ERROR }); | ||
return; | ||
} | ||
|
||
// @ts-ignore | ||
const { fields, id: indexPatternId } = indexPatternResp; | ||
const geoField = fields.find((field: IFieldType) => | ||
[ES_GEO_FIELD_TYPE.GEO_POINT as string, ES_GEO_FIELD_TYPE.GEO_SHAPE as string].includes( | ||
field.type | ||
) | ||
); | ||
if (!indexPatternId || !geoField) { | ||
this.setState({ indexingStage: INDEXING_STAGE.ERROR }); | ||
this.props.previewLayers([]); | ||
} else { | ||
const esSearchSourceConfig = { | ||
indexPatternId, | ||
geoField: geoField.name, | ||
// Only turn on bounds filter for large doc counts | ||
// @ts-ignore | ||
filterByMapBounds: indexDataResp.docCount > DEFAULT_MAX_RESULT_WINDOW, | ||
scalingType: | ||
geoField.type === ES_GEO_FIELD_TYPE.GEO_POINT | ||
? SCALING_TYPES.CLUSTERS | ||
: SCALING_TYPES.LIMIT, | ||
}; | ||
this.setState({ indexingStage: INDEXING_STAGE.SUCCESS }); | ||
this.props.previewLayers([ | ||
createDefaultLayerDescriptor(esSearchSourceConfig, this.props.mapColors), | ||
]); | ||
} | ||
}; | ||
|
||
// Called on file upload screen when UI state changes | ||
_onIndexReady = (indexReady: boolean) => { | ||
if (!this._isMounted) { | ||
return; | ||
} | ||
this.setState({ indexingStage: indexReady ? INDEXING_STAGE.READY : null }); | ||
if (indexReady) { | ||
this.props.enableNextBtn(); | ||
} else { | ||
this.props.disableNextBtn(); | ||
} | ||
}; | ||
|
||
// Called on file upload screen when upload file is changed or removed | ||
_onFileRemove = () => { | ||
this.props.previewLayers([]); | ||
}; | ||
|
||
render() { | ||
const FileUpload = getFileUploadComponent(); | ||
return ( | ||
<FileUpload | ||
appName={'Maps'} | ||
isIndexingTriggered={this.state.indexingStage === INDEXING_STAGE.TRIGGERED} | ||
onFileUpload={this._onFileUpload} | ||
onFileRemove={this._onFileRemove} | ||
onIndexReady={this._onIndexReady} | ||
transformDetails={'geo'} | ||
onIndexingComplete={this._onIndexingComplete} | ||
/> | ||
); | ||
} | ||
} |
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
Oops, something went wrong.