Skip to content

Commit

Permalink
update RenderWizardArguments arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed May 27, 2020
1 parent 8cbac63 commit 16b08c3
Show file tree
Hide file tree
Showing 16 changed files with 47 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,12 @@ export class ObservabilityLayerTemplate extends Component<RenderWizardArguments,
};

_previewLayer() {
this.props.previewLayer(
createLayerDescriptor({
layer: this.state.layer,
metric: this.state.metric,
display: this.state.display,
})
);
const layerDescriptor = createLayerDescriptor({
layer: this.state.layer,
metric: this.state.metric,
display: this.state.display,
});
this.props.previewLayers([layerDescriptor]);
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const uploadLayerWizardConfig: LayerWizard = {
icon: 'importAction',
isIndexingSource: true,
renderWizard: ({
previewLayer,
previewLayers,
mapColors,
isIndexingTriggered,
onRemove,
Expand All @@ -38,13 +38,13 @@ export const uploadLayerWizardConfig: LayerWizard = {
}: RenderWizardArguments) => {
function previewGeojsonFile(geojsonFile: unknown, name: string) {
if (!geojsonFile) {
previewLayer(null);
previewLayers([]);
return;
}
const sourceDescriptor = GeojsonFileSource.createDescriptor(geojsonFile, name);
const layerDescriptor = VectorLayer.createDescriptor({ sourceDescriptor }, mapColors);
// TODO figure out a better way to handle passing this information back to layer_addpanel
previewLayer(layerDescriptor, true);
previewLayers([layerDescriptor], true);
}

function viewIndexedData(indexResponses: {
Expand Down Expand Up @@ -72,7 +72,7 @@ export const uploadLayerWizardConfig: LayerWizard = {
)
);
if (!indexPatternId || !geoField) {
previewLayer(null);
previewLayers([]);
} else {
const esSearchSourceConfig = {
indexPatternId,
Expand All @@ -85,7 +85,7 @@ export const uploadLayerWizardConfig: LayerWizard = {
? SCALING_TYPES.CLUSTERS
: SCALING_TYPES.LIMIT,
};
previewLayer(createDefaultLayerDescriptor(esSearchSourceConfig, mapColors));
previewLayers([createDefaultLayerDescriptor(esSearchSourceConfig, mapColors)]);
importSuccessHandler(indexResponses);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ export const emsBoundariesLayerWizardConfig: LayerWizard = {
defaultMessage: 'Administrative boundaries from Elastic Maps Service',
}),
icon: 'emsApp',
renderWizard: ({ previewLayer, mapColors }: RenderWizardArguments) => {
renderWizard: ({ previewLayers, mapColors }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: Partial<EMSFileSourceDescriptor>) => {
const sourceDescriptor = EMSFileSource.createDescriptor(sourceConfig);
const layerDescriptor = VectorLayer.createDescriptor({ sourceDescriptor }, mapColors);
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};
return <EMSFileCreateSourceEditor onSourceConfigChange={onSourceConfigChange} />;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export const emsBaseMapLayerWizardConfig: LayerWizard = {
defaultMessage: 'Tile map service from Elastic Maps Service',
}),
icon: 'emsApp',
renderWizard: ({ previewLayer }: RenderWizardArguments) => {
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: unknown) => {
const layerDescriptor = VectorTileLayer.createDescriptor({
sourceDescriptor: EMSTMSSource.createDescriptor(sourceConfig),
});
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};

return <TileServiceSelect onTileSelect={onSourceConfigChange} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ export const clustersLayerWizardConfig: LayerWizard = {
defaultMessage: 'Geospatial data grouped in grids with metrics for each gridded cell',
}),
icon: 'logoElasticsearch',
renderWizard: ({ previewLayer }: RenderWizardArguments) => {
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: Partial<ESGeoGridSourceDescriptor>) => {
if (!sourceConfig) {
previewLayer(null);
previewLayers([]);
return;
}

Expand Down Expand Up @@ -94,7 +94,7 @@ export const clustersLayerWizardConfig: LayerWizard = {
},
}),
});
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ export const heatmapLayerWizardConfig: LayerWizard = {
defaultMessage: 'Geospatial data grouped in grids to show density',
}),
icon: 'logoElasticsearch',
renderWizard: ({ previewLayer }: RenderWizardArguments) => {
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: Partial<ESGeoGridSourceDescriptor>) => {
if (!sourceConfig) {
previewLayer(null);
previewLayers([]);
return;
}

const layerDescriptor = HeatmapLayer.createDescriptor({
sourceDescriptor: ESGeoGridSource.createDescriptor(sourceConfig),
});
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export const point2PointLayerWizardConfig: LayerWizard = {
defaultMessage: 'Aggregated data paths between the source and destination',
}),
icon: 'logoElasticsearch',
renderWizard: ({ previewLayer }: RenderWizardArguments) => {
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: unknown) => {
if (!sourceConfig) {
previewLayer(null);
previewLayers([]);
return;
}

Expand Down Expand Up @@ -65,7 +65,7 @@ export const point2PointLayerWizardConfig: LayerWizard = {
},
}),
});
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};

return <CreateSourceEditor onSourceConfigChange={onSourceConfigChange} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ export const esDocumentsLayerWizardConfig: LayerWizard = {
defaultMessage: 'Vector data from a Kibana index pattern',
}),
icon: 'logoElasticsearch',
renderWizard: ({ previewLayer, mapColors }: RenderWizardArguments) => {
renderWizard: ({ previewLayers, mapColors }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: unknown) => {
if (!sourceConfig) {
previewLayer(null);
previewLayers([]);
return;
}

previewLayer(createDefaultLayerDescriptor(sourceConfig, mapColors));
previewLayers([createDefaultLayerDescriptor(sourceConfig, mapColors)]);
};
return <CreateSourceEditor onSourceConfigChange={onSourceConfigChange} />;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export const kibanaRegionMapLayerWizardConfig: LayerWizard = {
defaultMessage: 'Vector data from hosted GeoJSON configured in kibana.yml',
}),
icon: 'logoKibana',
renderWizard: ({ previewLayer, mapColors }: RenderWizardArguments) => {
renderWizard: ({ previewLayers, mapColors }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: unknown) => {
const sourceDescriptor = KibanaRegionmapSource.createDescriptor(sourceConfig);
const layerDescriptor = VectorLayer.createDescriptor({ sourceDescriptor }, mapColors);
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};

return <CreateSourceEditor onSourceConfigChange={onSourceConfigChange} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ export const kibanaBasemapLayerWizardConfig: LayerWizard = {
defaultMessage: 'Tile map service configured in kibana.yml',
}),
icon: 'logoKibana',
renderWizard: ({ previewLayer }: RenderWizardArguments) => {
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = () => {
const layerDescriptor = TileLayer.createDescriptor({
sourceDescriptor: KibanaTilemapSource.createDescriptor(),
});
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};
return <CreateSourceEditor onSourceConfigChange={onSourceConfigChange} />;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ export const mvtVectorSourceWizardConfig: LayerWizard = {
defaultMessage: 'Vector source wizard',
}),
icon: 'grid',
renderWizard: ({ previewLayer, mapColors }: RenderWizardArguments) => {
renderWizard: ({ previewLayers, mapColors }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: MVTSingleLayerVectorSourceConfig) => {
const sourceDescriptor = MVTSingleLayerVectorSource.createDescriptor(sourceConfig);
const layerDescriptor = TiledVectorLayer.createDescriptor({ sourceDescriptor }, mapColors);
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};

return <MVTSingleLayerVectorSourceEditor onSourceConfigChange={onSourceConfigChange} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ export const wmsLayerWizardConfig: LayerWizard = {
defaultMessage: 'Maps from OGC Standard WMS',
}),
icon: 'grid',
renderWizard: ({ previewLayer }: RenderWizardArguments) => {
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: unknown) => {
if (!sourceConfig) {
previewLayer(null);
previewLayers([]);
return;
}

const layerDescriptor = TileLayer.createDescriptor({
sourceDescriptor: WMSSource.createDescriptor(sourceConfig),
});
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};
return <WMSCreateSourceEditor onSourceConfigChange={onSourceConfigChange} />;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export const tmsLayerWizardConfig: LayerWizard = {
defaultMessage: 'Tile map service configured in interface',
}),
icon: 'grid',
renderWizard: ({ previewLayer }: RenderWizardArguments) => {
renderWizard: ({ previewLayers }: RenderWizardArguments) => {
const onSourceConfigChange = (sourceConfig: XYZTMSSourceConfig) => {
const layerDescriptor = TileLayer.createDescriptor({
sourceDescriptor: XYZTMSSource.createDescriptor(sourceConfig),
});
previewLayer(layerDescriptor);
previewLayers([layerDescriptor]);
};
return <XYZTMSEditor onSourceConfigChange={onSourceConfigChange} />;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const FlyoutBody = (props: Props) => {
}

const renderWizardArgs = {
previewLayer: props.previewLayer,
previewLayers: props.previewLayers,
mapColors: props.mapColors,
isIndexingTriggered: props.isIndexingTriggered,
onRemove: props.onRemove,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ interface Props {
interface State {
importView: boolean;
isIndexingSource: boolean;
layerDescriptor: LayerDescriptor | null;
layerImportAddReady: boolean;
layerWizard: LayerWizard | null;
}
Expand All @@ -36,7 +35,6 @@ export class AddLayerPanel extends Component<Props, State> {

state = {
layerWizard: null,
layerDescriptor: null, // TODO get this from redux store instead of storing locally
isIndexingSource: false,
importView: false,
layerImportAddReady: false,
Expand All @@ -56,21 +54,13 @@ export class AddLayerPanel extends Component<Props, State> {
}
}

_previewLayer = (layerDescriptor: LayerDescriptor | null, isIndexingSource?: boolean) => {
_previewLayers = (layerDescriptors: LayerDescriptor[], isIndexingSource?: boolean) => {
if (!this._isMounted) {
return;
}
if (!layerDescriptor) {
this.setState({
layerDescriptor: null,
isIndexingSource: false,
});
this.props.addPreviewLayers([]);
return;
}

this.setState({ layerDescriptor, isIndexingSource: !!isIndexingSource });
this.props.addPreviewLayers([layerDescriptor]);
this.setState({ isIndexingSource: layerDescriptors.length ? !!isIndexingSource : false });
this.props.addPreviewLayers(layerDescriptors);
};

_clearLayerData = ({ keepSourceType = false }: { keepSourceType: boolean }) => {
Expand All @@ -79,7 +69,6 @@ export class AddLayerPanel extends Component<Props, State> {
}

const newState: Partial<State> = {
layerDescriptor: null,
isIndexingSource: false,
};
if (!keepSourceType) {
Expand Down Expand Up @@ -125,7 +114,7 @@ export class AddLayerPanel extends Component<Props, State> {
});
const isNextBtnEnabled = this.state.importView
? this.props.isIndexingReady || this.props.isIndexingSuccess
: !!this.state.layerDescriptor;
: true;

return (
<Fragment>
Expand All @@ -140,7 +129,7 @@ export class AddLayerPanel extends Component<Props, State> {
onClear={() => this._clearLayerData({ keepSourceType: false })}
onRemove={() => this._clearLayerData({ keepSourceType: true })}
onWizardSelect={this._onWizardSelect}
previewLayer={this._previewLayer}
previewLayers={this._previewLayers}
/>

<FlyoutFooter
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/maps/public/selectors/map_selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ export const getSelectedLayer = createSelector(
}
);

export const hasPreviewLayers = createSelector(getLayerListRaw, (layerList) => {
return layerList.some((layerDescriptor) => {
return !!layerDescriptor.__isPreviewLayer;
export const hasPreviewLayers = createSelector(getLayerList, (layerList) => {
return layerList.some((layer) => {
return layer.isPreviewLayer();
});
});

Expand Down

0 comments on commit 16b08c3

Please sign in to comment.