Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] Separate layer wizards for Clusters and heatmap #60870

Merged
merged 21 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
*/

import React, { Fragment } from 'react';
import { GeojsonFileSource } from '../../../layers/sources/client_file_source';
import { EuiSpacer, EuiPanel, EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { uploadLayerWizardConfig } from '../../../layers/sources/client_file_source';

export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) => {
const editorProperties = getEditorProperties({ isIndexingTriggered, ...props });
const editor = GeojsonFileSource.renderEditor(editorProperties);
return (
<Fragment>
{isIndexingTriggered ? null : (
Expand All @@ -25,7 +24,9 @@ export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) =>
<EuiSpacer size="s" />
</Fragment>
)}
<EuiPanel style={{ position: 'relative' }}>{editor}</EuiPanel>
<EuiPanel style={{ position: 'relative' }}>
{uploadLayerWizardConfig.renderWizard(editorProperties)}
</EuiPanel>
</Fragment>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,20 @@
*/

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

export const SourceEditor = ({
clearSource,
sourceType,
layerWizard,
isIndexingTriggered,
inspectorAdapters,
previewLayer,
}) => {
const editorProperties = {
onPreviewSource: previewLayer,
inspectorAdapters,
};
const Source = ALL_SOURCES.find(Source => {
return Source.type === sourceType;
});
if (!Source) {
throw new Error(`Unexpected source type: ${sourceType}`);
if (!layerWizard) {
return null;
}
const editor = Source.renderEditor(editorProperties);

return (
<Fragment>
{isIndexingTriggered ? null : (
Expand All @@ -40,7 +32,9 @@ export const SourceEditor = ({
<EuiSpacer size="s" />
</Fragment>
)}
<EuiPanel>{editor}</EuiPanel>
<EuiPanel>
{layerWizard.renderWizard({ onPreviewSource: previewLayer, inspectorAdapters })}
</EuiPanel>
</Fragment>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,33 @@
*/

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

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

const sourceTitle = Source.title;
const onClick = () => {
updateSourceSelection({
layerWizard: layerWizard,
isIndexingSource: !!layerWizard.isIndexingSource,
});
};

return (
<Fragment key={Source.type}>
<Fragment key={layerWizard.title}>
<EuiSpacer size="s" />
<EuiCard
className="mapLayerAddpanel__card"
title={sourceTitle}
title={layerWizard.title}
icon={icon}
onClick={() =>
updateSourceSelection({ type: Source.type, isIndexingSource: Source.isIndexingSource })
}
description={Source.description}
onClick={onClick}
description={layerWizard.description}
layout="horizontal"
data-test-subj={_.camelCase(Source.title)}
data-test-subj={_.camelCase(layerWizard.title)}
/>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n';

export class AddLayerPanel extends Component {
state = {
sourceType: null,
layerWizard: null,
layer: null,
importView: false,
layerImportAddReady: false,
Expand All @@ -35,9 +35,9 @@ export class AddLayerPanel extends Component {
}

_getPanelDescription() {
const { sourceType, importView, layerImportAddReady } = this.state;
const { layerWizard, importView, layerImportAddReady } = this.state;
let panelDescription;
if (!sourceType) {
if (!layerWizard) {
panelDescription = i18n.translate('xpack.maps.addLayerPanel.selectSource', {
defaultMessage: 'Select source',
});
Expand Down Expand Up @@ -85,13 +85,13 @@ export class AddLayerPanel extends Component {

this.setState({
layer: null,
...(!keepSourceType ? { sourceType: null, importView: false } : {}),
...(!keepSourceType ? { layerWizard: null, importView: false } : {}),
});
this.props.removeTransientLayer();
};

_onSourceSelectionChange = ({ type, isIndexingSource }) => {
this.setState({ sourceType: type, importView: isIndexingSource });
_onSourceSelectionChange = ({ layerWizard, isIndexingSource }) => {
this.setState({ layerWizard, importView: isIndexingSource });
};

_layerAddHandler = () => {
Expand All @@ -118,8 +118,8 @@ export class AddLayerPanel extends Component {
};

_renderAddLayerPanel() {
const { sourceType, importView } = this.state;
if (!sourceType) {
const { layerWizard, importView } = this.state;
if (!layerWizard) {
return <SourceSelect updateSourceSelection={this._onSourceSelectionChange} />;
}
if (importView) {
Expand All @@ -134,7 +134,7 @@ export class AddLayerPanel extends Component {
return (
<SourceEditor
clearSource={this._clearLayerData}
sourceType={sourceType}
layerWizard={layerWizard}
previewLayer={this._viewLayer}
/>
);
Expand All @@ -148,7 +148,7 @@ export class AddLayerPanel extends Component {

return (
<FlyoutFooter
showNextButton={!!this.state.sourceType}
showNextButton={!!this.state.layerWizard}
disableNextButton={!buttonEnabled}
onClick={this._layerAddHandler}
nextButtonText={buttonDescription}
Expand Down
30 changes: 30 additions & 0 deletions x-pack/legacy/plugins/maps/public/layers/layer_wizard_registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

type LayerWizard = {
description: string;
icon: string;
isIndexingSource?: boolean;
renderWizard({
onPreviewSource,
inspectorAdapters,
}: {
onPreviewSource: () => void;
inspectorAdapters: unknown;
}): unknown;
title: string;
};

const registry: LayerWizard[] = [];

export function registerLayerWizard(layerWizard: LayerWizard) {
registry.push(layerWizard);
nreese marked this conversation as resolved.
Show resolved Hide resolved
}

export function getLayerWizards(): LayerWizard[] {
return [...registry];
}
30 changes: 30 additions & 0 deletions x-pack/legacy/plugins/maps/public/layers/load_layer_wizards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { registerLayerWizard } from './layer_wizard_registry';
import { uploadLayerWizardConfig } from './sources/client_file_source';
import { esDocumentsLayerWizardConfig } from './sources/es_search_source';
import { clustersLayerWizardConfig, heatmapLayerWizardConfig } from './sources/es_geo_grid_source';
import { point2PointLayerWizardConfig } from './sources/es_pew_pew_source/es_pew_pew_source';
import { emsBoundariesLayerWizardConfig } from './sources/ems_file_source';
import { emsBaseMapLayerWizardConfig } from './sources/ems_tms_source';
import { kibanaRegionMapLayerWizardConfig } from './sources/kibana_regionmap_source';
import { kibanaBasemapLayerWizardConfig } from './sources/kibana_tilemap_source';
import { tmsLayerWizardConfig } from './sources/xyz_tms_source';
import { wmsLayerWizardConfig } from './sources/wms_source';

// Registration order determines display order
registerLayerWizard(uploadLayerWizardConfig);
registerLayerWizard(esDocumentsLayerWizardConfig);
registerLayerWizard(clustersLayerWizardConfig);
registerLayerWizard(heatmapLayerWizardConfig);
registerLayerWizard(point2PointLayerWizardConfig);
registerLayerWizard(emsBoundariesLayerWizardConfig);
registerLayerWizard(emsBaseMapLayerWizardConfig);
registerLayerWizard(kibanaRegionMapLayerWizardConfig);
registerLayerWizard(kibanaBasemapLayerWizardConfig);
registerLayerWizard(tmsLayerWizardConfig);
registerLayerWizard(wmsLayerWizardConfig);
29 changes: 0 additions & 29 deletions x-pack/legacy/plugins/maps/public/layers/sources/all_sources.js

This file was deleted.

Loading