Skip to content

Commit 3f408b6

Browse files
[Maps] Separate layer wizards for Clusters and heatmap (#60870)
* [Maps] source registry and register seperate clusters and heat map sources * split into to registries * add EMS file source * add geojson upload layer * register rest of sources * i18n changes * ts lint errors * fix jest test * fix pew-pew source * review feedback * import registires in plugin so they exist in embeddable * remove order parameter and move all layer registies into single file * fix functionalt est * pass constructor to sourceREgistry instead of factory * review feedback Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 47127b0 commit 3f408b6

36 files changed

Lines changed: 629 additions & 416 deletions

File tree

x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/import_editor/view.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@
55
*/
66

77
import React, { Fragment } from 'react';
8-
import { GeojsonFileSource } from '../../../layers/sources/client_file_source';
98
import { EuiSpacer, EuiPanel, EuiButtonEmpty } from '@elastic/eui';
109
import { FormattedMessage } from '@kbn/i18n/react';
10+
import { uploadLayerWizardConfig } from '../../../layers/sources/client_file_source';
1111

1212
export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) => {
1313
const editorProperties = getEditorProperties({ isIndexingTriggered, ...props });
14-
const editor = GeojsonFileSource.renderEditor(editorProperties);
1514
return (
1615
<Fragment>
1716
{isIndexingTriggered ? null : (
@@ -25,7 +24,9 @@ export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) =>
2524
<EuiSpacer size="s" />
2625
</Fragment>
2726
)}
28-
<EuiPanel style={{ position: 'relative' }}>{editor}</EuiPanel>
27+
<EuiPanel style={{ position: 'relative' }}>
28+
{uploadLayerWizardConfig.renderWizard(editorProperties)}
29+
</EuiPanel>
2930
</Fragment>
3031
);
3132
};

x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_editor/view.js

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,20 @@
55
*/
66

77
import React, { Fragment } from 'react';
8-
import { ALL_SOURCES } from '../../../layers/sources/all_sources';
98
import { EuiSpacer, EuiPanel, EuiButtonEmpty } from '@elastic/eui';
109
import { FormattedMessage } from '@kbn/i18n/react';
1110

1211
export const SourceEditor = ({
1312
clearSource,
14-
sourceType,
13+
layerWizard,
1514
isIndexingTriggered,
1615
inspectorAdapters,
1716
previewLayer,
1817
}) => {
19-
const editorProperties = {
20-
onPreviewSource: previewLayer,
21-
inspectorAdapters,
22-
};
23-
const Source = ALL_SOURCES.find(Source => {
24-
return Source.type === sourceType;
25-
});
26-
if (!Source) {
27-
throw new Error(`Unexpected source type: ${sourceType}`);
18+
if (!layerWizard) {
19+
return null;
2820
}
29-
const editor = Source.renderEditor(editorProperties);
21+
3022
return (
3123
<Fragment>
3224
{isIndexingTriggered ? null : (
@@ -40,7 +32,9 @@ export const SourceEditor = ({
4032
<EuiSpacer size="s" />
4133
</Fragment>
4234
)}
43-
<EuiPanel>{editor}</EuiPanel>
35+
<EuiPanel>
36+
{layerWizard.renderWizard({ onPreviewSource: previewLayer, inspectorAdapters })}
37+
</EuiPanel>
4438
</Fragment>
4539
);
4640
};

x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/source_select/source_select.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,33 @@
55
*/
66

77
import React, { Fragment } from 'react';
8-
import { ALL_SOURCES } from '../../../layers/sources/all_sources';
8+
import { getLayerWizards } from '../../../layers/layer_wizard_registry';
99
import { EuiTitle, EuiSpacer, EuiCard, EuiIcon } from '@elastic/eui';
1010
import { FormattedMessage } from '@kbn/i18n/react';
1111
import _ from 'lodash';
1212

1313
export function SourceSelect({ updateSourceSelection }) {
14-
const sourceCards = ALL_SOURCES.map(Source => {
15-
const icon = Source.icon ? <EuiIcon type={Source.icon} size="l" /> : null;
14+
const sourceCards = getLayerWizards().map(layerWizard => {
15+
const icon = layerWizard.icon ? <EuiIcon type={layerWizard.icon} size="l" /> : null;
1616

17-
const sourceTitle = Source.title;
17+
const onClick = () => {
18+
updateSourceSelection({
19+
layerWizard: layerWizard,
20+
isIndexingSource: !!layerWizard.isIndexingSource,
21+
});
22+
};
1823

1924
return (
20-
<Fragment key={Source.type}>
25+
<Fragment key={layerWizard.title}>
2126
<EuiSpacer size="s" />
2227
<EuiCard
2328
className="mapLayerAddpanel__card"
24-
title={sourceTitle}
29+
title={layerWizard.title}
2530
icon={icon}
26-
onClick={() =>
27-
updateSourceSelection({ type: Source.type, isIndexingSource: Source.isIndexingSource })
28-
}
29-
description={Source.description}
31+
onClick={onClick}
32+
description={layerWizard.description}
3033
layout="horizontal"
31-
data-test-subj={_.camelCase(Source.title)}
34+
data-test-subj={_.camelCase(layerWizard.title)}
3235
/>
3336
</Fragment>
3437
);

x-pack/legacy/plugins/maps/public/connected_components/layer_addpanel/view.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n';
1414

1515
export class AddLayerPanel extends Component {
1616
state = {
17-
sourceType: null,
17+
layerWizard: null,
1818
layer: null,
1919
importView: false,
2020
layerImportAddReady: false,
@@ -35,9 +35,9 @@ export class AddLayerPanel extends Component {
3535
}
3636

3737
_getPanelDescription() {
38-
const { sourceType, importView, layerImportAddReady } = this.state;
38+
const { layerWizard, importView, layerImportAddReady } = this.state;
3939
let panelDescription;
40-
if (!sourceType) {
40+
if (!layerWizard) {
4141
panelDescription = i18n.translate('xpack.maps.addLayerPanel.selectSource', {
4242
defaultMessage: 'Select source',
4343
});
@@ -85,13 +85,13 @@ export class AddLayerPanel extends Component {
8585

8686
this.setState({
8787
layer: null,
88-
...(!keepSourceType ? { sourceType: null, importView: false } : {}),
88+
...(!keepSourceType ? { layerWizard: null, importView: false } : {}),
8989
});
9090
this.props.removeTransientLayer();
9191
};
9292

93-
_onSourceSelectionChange = ({ type, isIndexingSource }) => {
94-
this.setState({ sourceType: type, importView: isIndexingSource });
93+
_onSourceSelectionChange = ({ layerWizard, isIndexingSource }) => {
94+
this.setState({ layerWizard, importView: isIndexingSource });
9595
};
9696

9797
_layerAddHandler = () => {
@@ -118,8 +118,8 @@ export class AddLayerPanel extends Component {
118118
};
119119

120120
_renderAddLayerPanel() {
121-
const { sourceType, importView } = this.state;
122-
if (!sourceType) {
121+
const { layerWizard, importView } = this.state;
122+
if (!layerWizard) {
123123
return <SourceSelect updateSourceSelection={this._onSourceSelectionChange} />;
124124
}
125125
if (importView) {
@@ -134,7 +134,7 @@ export class AddLayerPanel extends Component {
134134
return (
135135
<SourceEditor
136136
clearSource={this._clearLayerData}
137-
sourceType={sourceType}
137+
layerWizard={layerWizard}
138138
previewLayer={this._viewLayer}
139139
/>
140140
);
@@ -148,7 +148,7 @@ export class AddLayerPanel extends Component {
148148

149149
return (
150150
<FlyoutFooter
151-
showNextButton={!!this.state.sourceType}
151+
showNextButton={!!this.state.layerWizard}
152152
disableNextButton={!buttonEnabled}
153153
onClick={this._layerAddHandler}
154154
nextButtonText={buttonDescription}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
/* eslint-disable @typescript-eslint/consistent-type-definitions */
7+
8+
type LayerWizard = {
9+
description: string;
10+
icon: string;
11+
isIndexingSource?: boolean;
12+
renderWizard({
13+
onPreviewSource,
14+
inspectorAdapters,
15+
}: {
16+
onPreviewSource: () => void;
17+
inspectorAdapters: unknown;
18+
}): unknown;
19+
title: string;
20+
};
21+
22+
const registry: LayerWizard[] = [];
23+
24+
export function registerLayerWizard(layerWizard: LayerWizard) {
25+
registry.push(layerWizard);
26+
}
27+
28+
export function getLayerWizards(): LayerWizard[] {
29+
return [...registry];
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import { registerLayerWizard } from './layer_wizard_registry';
8+
import { uploadLayerWizardConfig } from './sources/client_file_source';
9+
import { esDocumentsLayerWizardConfig } from './sources/es_search_source';
10+
import { clustersLayerWizardConfig, heatmapLayerWizardConfig } from './sources/es_geo_grid_source';
11+
import { point2PointLayerWizardConfig } from './sources/es_pew_pew_source/es_pew_pew_source';
12+
import { emsBoundariesLayerWizardConfig } from './sources/ems_file_source';
13+
import { emsBaseMapLayerWizardConfig } from './sources/ems_tms_source';
14+
import { kibanaRegionMapLayerWizardConfig } from './sources/kibana_regionmap_source';
15+
import { kibanaBasemapLayerWizardConfig } from './sources/kibana_tilemap_source';
16+
import { tmsLayerWizardConfig } from './sources/xyz_tms_source';
17+
import { wmsLayerWizardConfig } from './sources/wms_source';
18+
19+
// Registration order determines display order
20+
registerLayerWizard(uploadLayerWizardConfig);
21+
registerLayerWizard(esDocumentsLayerWizardConfig);
22+
registerLayerWizard(clustersLayerWizardConfig);
23+
registerLayerWizard(heatmapLayerWizardConfig);
24+
registerLayerWizard(point2PointLayerWizardConfig);
25+
registerLayerWizard(emsBoundariesLayerWizardConfig);
26+
registerLayerWizard(emsBaseMapLayerWizardConfig);
27+
registerLayerWizard(kibanaRegionMapLayerWizardConfig);
28+
registerLayerWizard(kibanaBasemapLayerWizardConfig);
29+
registerLayerWizard(tmsLayerWizardConfig);
30+
registerLayerWizard(wmsLayerWizardConfig);

x-pack/legacy/plugins/maps/public/layers/sources/all_sources.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)