Skip to content

Commit

Permalink
[Maps] update LayerWizard previewLayer to take layerDescriptor instea…
Browse files Browse the repository at this point in the history
…d of ISource (elastic#64461)

* more changes

* remove unused state argument

* revert change to make diff easier to follow

* migrate pew pew source to new previewLayer

* remove createDefaultLayer from ISource

* migrate EMS boundaries layer wizard

* convert ems tms layer wizard to previewLayer

* convert kibana base map to preview layer

* convert all other sources to previewLayer

* tslint clean-up

* remaining ts lint errors

* i18n clean up

* review feedback

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
nreese and elasticmachine committed Apr 27, 2020
1 parent 0e99bd6 commit ab2bed3
Show file tree
Hide file tree
Showing 51 changed files with 727 additions and 910 deletions.
31 changes: 11 additions & 20 deletions x-pack/plugins/maps/public/angular/get_initial_layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,18 @@
*/
import _ from 'lodash';
// Import each layer type, even those not used, to init in registry

import '../layers/sources/wms_source';

import '../layers/sources/ems_file_source';

import '../layers/sources/es_search_source';

import '../layers/sources/es_pew_pew_source/es_pew_pew_source';

import '../layers/sources/es_pew_pew_source';
import '../layers/sources/kibana_regionmap_source';

import '../layers/sources/es_geo_grid_source';

import '../layers/sources/xyz_tms_source';

import { KibanaTilemapSource } from '../layers/sources/kibana_tilemap_source';

import { TileLayer } from '../layers/tile_layer';
import { EMSTMSSource } from '../layers/sources/ems_tms_source';

import { VectorTileLayer } from '../layers/vector_tile_layer';
import { getInjectedVarFunc } from '../kibana_services';

import { getKibanaTileMap } from '../meta';

export function getInitialLayers(layerListJSON, initialLayers = []) {
Expand All @@ -35,18 +26,18 @@ export function getInitialLayers(layerListJSON, initialLayers = []) {

const tilemapSourceFromKibana = getKibanaTileMap();
if (_.get(tilemapSourceFromKibana, 'url')) {
const sourceDescriptor = KibanaTilemapSource.createDescriptor();
const source = new KibanaTilemapSource(sourceDescriptor);
const layer = source.createDefaultLayer();
return [layer.toLayerDescriptor(), ...initialLayers];
const layerDescriptor = TileLayer.createDescriptor({
sourceDescriptor: KibanaTilemapSource.createDescriptor(),
});
return [layerDescriptor, ...initialLayers];
}

const isEmsEnabled = getInjectedVarFunc()('isEmsEnabled', true);
if (isEmsEnabled) {
const descriptor = EMSTMSSource.createDescriptor({ isAutoSelect: true });
const source = new EMSTMSSource(descriptor);
const layer = source.createDefaultLayer();
return [layer.toLayerDescriptor(), ...initialLayers];
const layerDescriptor = VectorTileLayer.createDescriptor({
sourceDescriptor: EMSTMSSource.createDescriptor({ isAutoSelect: true }),
});
return [layerDescriptor, ...initialLayers];
}

return initialLayers;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,36 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment } from 'react';
import { EuiSpacer, EuiPanel, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import React from 'react';
import { EuiPanel } from '@elastic/eui';

import { uploadLayerWizardConfig } from '../../../layers/sources/client_file_source';

export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) => {
const editorProperties = getEditorProperties({ isIndexingTriggered, ...props });
export const ImportEditor = props => {
const editorProperties = getEditorProperties(props);
return (
<Fragment>
{isIndexingTriggered ? null : (
<Fragment>
<EuiButtonEmpty size="xs" flush="left" onClick={clearSource} iconType="arrowLeft">
<FormattedMessage
id="xpack.maps.addLayerPanel.changeDataSourceButtonLabel"
defaultMessage="Change data source"
/>
</EuiButtonEmpty>
<EuiSpacer size="s" />
</Fragment>
)}
<EuiPanel style={{ position: 'relative' }}>
{uploadLayerWizardConfig.renderWizard(editorProperties)}
</EuiPanel>
</Fragment>
<EuiPanel style={{ position: 'relative' }}>
{uploadLayerWizardConfig.renderWizard(editorProperties)}
</EuiPanel>
);
};

function getEditorProperties({
inspectorAdapters,
previewLayer,
mapColors,
onRemove,
viewLayer,
isIndexingTriggered,
onIndexReady,
importSuccessHandler,
importErrorHandler,
}) {
return {
onPreviewSource: viewLayer,
inspectorAdapters,
previewLayer,
mapColors,
onRemove,
importSuccessHandler,
importErrorHandler,
isIndexingTriggered,
addAndViewSource: viewLayer,
onIndexReady,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ function mapStateToProps(state = {}) {

function mapDispatchToProps(dispatch) {
return {
viewLayer: async layer => {
previewLayer: async layerDescriptor => {
await dispatch(setSelectedLayer(null));
await dispatch(removeTransientLayer());
dispatch(addLayer(layer.toLayerDescriptor()));
dispatch(setSelectedLayer(layer.getId()));
dispatch(setTransientLayer(layer.getId()));
dispatch(addLayer(layerDescriptor));
dispatch(setSelectedLayer(layerDescriptor.id));
dispatch(setTransientLayer(layerDescriptor.id));
},
removeTransientLayer: () => {
dispatch(setSelectedLayer(null));
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import React, { Fragment } from 'react';

import { getLayerWizards } from '../../../layers/layer_wizard_registry';
import { EuiTitle, EuiSpacer, EuiCard, EuiIcon } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSpacer, EuiCard, EuiIcon } from '@elastic/eui';
import _ from 'lodash';

export function SourceSelect({ updateSourceSelection }) {
Expand Down Expand Up @@ -38,17 +37,5 @@ export function SourceSelect({ updateSourceSelection }) {
);
});

return (
<Fragment>
<EuiTitle size="xs">
<h2>
<FormattedMessage
id="xpack.maps.addLayerPanel.chooseDataSourceTitle"
defaultMessage="Choose data source"
/>
</h2>
</EuiTitle>
{sourceCards}
</Fragment>
);
return <Fragment>{sourceCards}</Fragment>;
}
Loading

0 comments on commit ab2bed3

Please sign in to comment.