Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Apr 1, 2020
1 parent c3e723c commit 0d4390f
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@
*/

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

export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) => {
const editorProperties = getEditorProperties({ isIndexingTriggered, ...props });
const layerWizard = getLayerWizard(GEOJSON_FILE);
return (
<Fragment>
{isIndexingTriggered ? null : (
Expand All @@ -27,7 +25,7 @@ export const ImportEditor = ({ clearSource, isIndexingTriggered, ...props }) =>
</Fragment>
)}
<EuiPanel style={{ position: 'relative' }}>
{layerWizard.renderWizard(editorProperties)}
{uploadLayerWizardConfig.renderWizard(editorProperties)}
</EuiPanel>
</Fragment>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@
*/

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

export const SourceEditor = ({
clearSource,
layerWizardId,
layerWizard,
isIndexingTriggered,
inspectorAdapters,
previewLayer,
}) => {
const layerWizard = getLayerWizard(layerWizardId);
if (!layerWizard) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export function SourceSelect({ updateSourceSelection }) {

const onClick = () => {
updateSourceSelection({
layerWizardId: layerWizard.id,
layerWizard: layerWizard,
isIndexingSource: !!layerWizard.isIndexingSource,
});
};

return (
<Fragment key={layerWizard.id}>
<Fragment key={layerWizard.title}>
<EuiSpacer size="s" />
<EuiCard
className="mapLayerAddpanel__card"
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 = {
layerWizardId: null,
layerWizard: null,
layer: null,
importView: false,
layerImportAddReady: false,
Expand All @@ -35,9 +35,9 @@ export class AddLayerPanel extends Component {
}

_getPanelDescription() {
const { layerWizardId, importView, layerImportAddReady } = this.state;
const { layerWizard, importView, layerImportAddReady } = this.state;
let panelDescription;
if (!layerWizardId) {
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 ? { layerWizardId: null, importView: false } : {}),
...(!keepSourceType ? { layerWizard: null, importView: false } : {}),
});
this.props.removeTransientLayer();
};

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

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

_renderAddLayerPanel() {
const { layerWizardId, importView } = this.state;
if (!layerWizardId) {
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}
layerWizardId={layerWizardId}
layerWizard={layerWizard}
previewLayer={this._viewLayer}
/>
);
Expand All @@ -148,7 +148,7 @@ export class AddLayerPanel extends Component {

return (
<FlyoutFooter
showNextButton={!!this.state.layerWizardId}
showNextButton={!!this.state.layerWizard}
disableNextButton={!buttonEnabled}
onClick={this._layerAddHandler}
nextButtonText={buttonDescription}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
type LayerWizard = {
description: string;
icon: string;
id: string;
isIndexingSource?: boolean;
renderWizard({
onPreviewSource,
Expand All @@ -18,7 +17,6 @@ type LayerWizard = {
inspectorAdapters: unknown;
}): unknown;
title: string;
sourceType: string;
};

const registry: LayerWizard[] = [];
Expand All @@ -30,7 +28,3 @@ export function registerLayerWizard(layerWizard: LayerWizard) {
export function getLayerWizards(): LayerWizard[] {
return [...registry];
}

export function getLayerWizard(id: string): LayerWizard | undefined {
return registry.find((layerWizard: LayerWizard) => layerWizard.id === id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ registerSource({
});

export const uploadLayerWizardConfig = {
id: GEOJSON_FILE,
description: i18n.translate('xpack.maps.source.geojsonFileDescription', {
defaultMessage: 'Index GeoJSON data in Elasticsearch',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ registerSource({
});

export const emsBoundariesLayerWizardConfig = {
id: EMS_FILE,
description: i18n.translate('xpack.maps.source.emsFileDescription', {
defaultMessage: 'Administrative boundaries from Elastic Maps Service',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ registerSource({
});

export const emsBaseMapLayerWizardConfig = {
id: EMS_TMS,
description: i18n.translate('xpack.maps.source.emsTileDescription', {
defaultMessage: 'Tile map service from Elastic Maps Service',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ registerSource({
});

export const clustersLayerWizardConfig = {
id: `${ES_GEO_GRID}_clusters`,
description: i18n.translate('xpack.maps.source.esGridClustersDescription', {
defaultMessage: 'Geospatial data grouped in grids with metrics for each gridded cell',
}),
Expand Down Expand Up @@ -446,7 +445,6 @@ export const clustersLayerWizardConfig = {
};

export const heatmapLayerWizardConfig = {
id: `${ES_GEO_GRID}_heatmap`,
description: i18n.translate('xpack.maps.source.esGridHeatmapDescription', {
defaultMessage: 'Geospatial data grouped in grids to show density',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ registerSource({
});

export const point2PointLayerWizardConfig = {
id: ES_PEW_PEW,
description: i18n.translate('xpack.maps.source.pewPewDescription', {
defaultMessage: 'Aggregated data paths between the source and destination',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ registerSource({
});

export const esDocumentsLayerWizardConfig = {
id: ES_SEARCH,
description: i18n.translate('xpack.maps.source.esSearchDescription', {
defaultMessage: 'Vector data from a Kibana index pattern',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ registerSource({
});

export const kibanaRegionMapLayerWizardConfig = {
id: REGIONMAP_FILE,
description: i18n.translate('xpack.maps.source.kbnRegionMapDescription', {
defaultMessage: 'Vector data from hosted GeoJSON configured in kibana.yml',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ registerSource({
});

export const kibanaBasemapLayerWizardConfig = {
id: KIBANA_TILEMAP,
description: i18n.translate('xpack.maps.source.kbnTMSDescription', {
defaultMessage: 'Tile map service configured in kibana.yml',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,17 @@ type SourceRegistryEntry = {
const registry: SourceRegistryEntry[] = [];

export function registerSource(entry: SourceRegistryEntry) {
const sourceTypeExists = registry.some(({ type }: SourceRegistryEntry) => {
return entry.type === type;
});
if (sourceTypeExists) {
throw new Error(
`Unable to register source type ${entry.type}. ${entry.type} has already been registered`
);
}
registry.push(entry);
}

function getSourceByType(sourceType: string): SourceRegistryEntry | undefined {
export function getSourceByType(sourceType: string): SourceRegistryEntry | undefined {
return registry.find((source: SourceRegistryEntry) => source.type === sourceType);
}

export function createSourceInstance(
sourceDescriptor: AbstractSourceDescriptor,
inspectorAdapters: object
): ISource {
const source = getSourceByType(sourceDescriptor.type);
if (!source) {
throw new Error(`Unrecognized sourceType ${sourceDescriptor.type}`);
}
return new source.ConstructorFunction(sourceDescriptor, inspectorAdapters);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ registerSource({
});

export const wmsLayerWizardConfig = {
id: WMS,
description: i18n.translate('xpack.maps.source.wmsDescription', {
defaultMessage: 'Maps from OGC Standard WMS',
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ registerSource({
});

export const tmsLayerWizardConfig = {
id: EMS_XYZ,
description: i18n.translate('xpack.maps.source.ems_xyzDescription', {
defaultMessage: 'Tile map service configured in interface',
}),
Expand Down
10 changes: 9 additions & 1 deletion x-pack/legacy/plugins/maps/public/selectors/map_selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../../plugins/maps/public/reducers/util';
import { InnerJoin } from '../layers/joins/inner_join';
import { createSourceInstance } from '../layers/sources/source_registry';
import { getSourceByType } from '../layers/sources/source_registry';

function createLayerInstance(layerDescriptor, inspectorAdapters) {
const source = createSourceInstance(layerDescriptor.sourceDescriptor, inspectorAdapters);
Expand Down Expand Up @@ -48,6 +48,14 @@ function createLayerInstance(layerDescriptor, inspectorAdapters) {
}
}

function createSourceInstance(sourceDescriptor, inspectorAdapters) {
const source = getSourceByType(sourceDescriptor.type);
if (!source) {
throw new Error(`Unrecognized sourceType ${sourceDescriptor.type}`);
}
return new source.ConstructorFunction(sourceDescriptor, inspectorAdapters);
}

export const getOpenTooltips = ({ map }) => {
return map && map.openTooltips ? map.openTooltips : [];
};
Expand Down

0 comments on commit 0d4390f

Please sign in to comment.