Skip to content

Commit

Permalink
[Maps] refactor StyleTabs into StyleSettings (elastic#35893)
Browse files Browse the repository at this point in the history
* [Maps] refactor StyleTabs into StyleSettings

* fix unit test
  • Loading branch information
nreese authored May 1, 2019
1 parent 85b082b commit 5550b3b
Show file tree
Hide file tree
Showing 14 changed files with 76 additions and 144 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
*/

import { connect } from 'react-redux';
import { StyleTabs } from './view';
import { StyleSettings } from './style_settings';
import { getSelectedLayer } from '../../../selectors/map_selectors';
import { updateLayerStyleForSelectedLayer } from '../../../actions/store_actions';

function mapDispatchToProps(dispatch) {
function mapStateToProps(state = {}) {
return {
updateStyle: styleDescriptor => {
dispatch(updateLayerStyleForSelectedLayer(styleDescriptor));
}
layer: getSelectedLayer(state)
};
}

function mapStateToProps(state, props) {
function mapDispatchToProps(dispatch) {
return {
layer: props.layer
updateStyleDescriptor: styleDescriptor => {
dispatch(updateLayerStyleForSelectedLayer(styleDescriptor));
}
};
}

const connectedFlyoutBody = connect(mapStateToProps, mapDispatchToProps)(StyleTabs);
export { connectedFlyoutBody as StyleTabs };
const connectedStyleSettings = connect(mapStateToProps, mapDispatchToProps)(StyleSettings);
export { connectedStyleSettings as StyleSettings };
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 React, { Fragment } from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
EuiTitle,
EuiPanel,
EuiSpacer,
} from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';

export function StyleSettings({ layer, updateStyleDescriptor }) {

const settingsEditor = layer.renderStyleEditor({ onStyleDescriptorChange: updateStyleDescriptor });

if (!settingsEditor) {
return null;
}

return (
<Fragment>
<EuiPanel>
<EuiFlexGroup>
<EuiFlexItem>
<EuiTitle size="xs">
<h5>
<FormattedMessage
id="xpack.maps.layerPanel.styleSettingsTitle"
defaultMessage="Layer Style"
/>
</h5>
</EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer size="m"/>

{settingsEditor}
</EuiPanel>

<EuiSpacer size="s" />
</Fragment>
);
}

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions x-pack/plugins/maps/public/components/layer_panel/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

import React, { Fragment } from 'react';

import { StyleTabs } from './style_tabs';
import { FilterEditor } from './filter_editor';
import { JoinEditor } from './join_editor';
import { FlyoutFooter } from './flyout_footer';
import { LayerErrors } from './layer_errors';
import { LayerSettings } from './layer_settings';
import { SourceSettings } from './source_settings';
import { StyleSettings } from './style_settings';
import {
EuiButtonIcon,
EuiFlexItem,
Expand Down Expand Up @@ -204,7 +204,7 @@ export class LayerPanel extends React.Component {

{this._renderJoinSection()}

<StyleTabs layer={selectedLayer}/>
<StyleSettings/>

</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('./style_tabs', () => ({
StyleTabs: () => {
return (<div>mockStyleTabs</div>);
jest.mock('./style_settings', () => ({
StyleSettings: () => {
return (<div>mockStyleSettings</div>);
}
}));

Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/maps/public/shared/layers/heatmap_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ export class HeatmapLayer extends AbstractLayer {
}
}

getSupportedStyles() {
return [HeatmapStyle];
}

getIndexPatternIds() {
return this._source.getIndexPatternIds();
}
Expand Down
9 changes: 2 additions & 7 deletions x-pack/plugins/maps/public/shared/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,6 @@ export class AbstractLayer {
};
}

getSupportedStyles() {
return [];
}

getCurrentStyle() {
return this._style;
}
Expand Down Expand Up @@ -250,7 +246,6 @@ export class AbstractLayer {
throw new Error('should implement Layer#getLayerTypeIconName');
}


async getBounds() {
return {
min_lon: -180,
Expand All @@ -260,8 +255,8 @@ export class AbstractLayer {
};
}

renderStyleEditor(Style, options) {
return Style.renderEditor(options);
renderStyleEditor({ onStyleDescriptorChange }) {
return this._style.renderEditor({ layer: this, onStyleDescriptorChange });
}

getIndexPatternIds() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,8 @@ export class AbstractStyle {
getDescriptor() {
return this._descriptor;
}

renderEditor(/* { layer, onStyleDescriptorChange } */) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ export class HeatmapStyle extends AbstractStyle {
this._descriptor = HeatmapStyle.createDescriptor();
}

static canEdit(styleInstance) {
return styleInstance.constructor === HeatmapStyle;
}

static createDescriptor() {
return {
type: HeatmapStyle.type,
Expand All @@ -33,10 +29,6 @@ export class HeatmapStyle extends AbstractStyle {
});
}

static renderEditor() {
return null;
}

setMBPaintProperties({ mbMap, layerId, propertyName, resolution }) {
let radius;
if (resolution === GRID_RESOLUTION.COARSE) {
Expand Down
4 changes: 0 additions & 4 deletions x-pack/plugins/maps/public/shared/layers/styles/tile_style.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export class TileStyle extends AbstractStyle {
this._descriptor = TileStyle.createDescriptor(styleDescriptor.properties);
}

static canEdit(styleInstance) {
return styleInstance.constructor === TileStyle;
}

static createDescriptor(properties = {}) {
return {
type: TileStyle.type,
Expand Down
11 changes: 3 additions & 8 deletions x-pack/plugins/maps/public/shared/layers/styles/vector_style.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ export class VectorStyle extends AbstractStyle {
};
}

static canEdit(styleInstance) {
return styleInstance.constructor === VectorStyle;
}

static createDescriptor(properties = {}) {
return {
type: VectorStyle.type,
Expand All @@ -55,13 +51,12 @@ export class VectorStyle extends AbstractStyle {

static description = '';

static renderEditor({ handleStyleChange, style, layer }) {

const styleProperties = { ...style.getProperties() };
renderEditor({ layer, onStyleDescriptorChange }) {
const styleProperties = { ...this.getProperties() };
const handlePropertyChange = (propertyName, settings) => {
styleProperties[propertyName] = settings;//override single property, but preserve the rest
const vectorStyleDescriptor = VectorStyle.createDescriptor(styleProperties);
handleStyleChange(vectorStyleDescriptor);
onStyleDescriptorChange(vectorStyleDescriptor);
};

return (
Expand Down
11 changes: 0 additions & 11 deletions x-pack/plugins/maps/public/shared/layers/vector_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,6 @@ export class VectorLayer extends AbstractLayer {
});
}

getSupportedStyles() {
return [VectorStyle];
}

getIcon() {
return this._style.getIcon();
}
Expand Down Expand Up @@ -479,13 +475,6 @@ export class VectorLayer extends AbstractLayer {
this._syncStylePropertiesWithMb(mbMap);
}

renderStyleEditor(Style, options) {
return Style.renderEditor({
layer: this,
...options
});
}

_getMbPointLayerId() {
return this.getId() + '_circle';
}
Expand Down

0 comments on commit 5550b3b

Please sign in to comment.