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] move source details to Panel header #29298

Merged
merged 11 commits into from
Jan 29, 2019
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ function mapStateToProps(state = {}) {
layerId: selectedLayer.getId(),
maxZoom: selectedLayer.getMaxZoom(),
minZoom: selectedLayer.getMinZoom(),
renderSourceDetails: selectedLayer.renderSourceDetails,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be careful for a couple small merge conflicts with https://github.com/elastic/kibana/pull/29294/files

renderSourceSettingsEditor: selectedLayer.renderSourceSettingsEditor
renderSourceSettingsEditor: selectedLayer.renderSourceSettingsEditor,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, I absolute hate that function syntax for a react component. so cluttered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But it is more performant since there are not state checks or life cycle methods

Copy link
Contributor

@thomasneirynck thomasneirynck Jan 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting. but if we want to avoid React internally to do this whole life-cycle loop (since internally, it does go through it even when using function-components), we would also need to re-implement how we include the component.

I just got this from:
https://medium.com/missive-app/45-faster-react-functional-components-now-3509a668e69f

*/

import React, { Component, Fragment } from 'react';
import React from 'react';

import {
EuiFlexGroup,
Expand All @@ -15,46 +15,35 @@ import {
EuiFieldText,
EuiRange,
EuiSpacer,
EuiLink,
} from '@elastic/eui';
import { ValidatedRange } from '../../../shared/components/validated_range';

export class SettingsPanel extends Component {
export function SettingsPanel(props) {

state = {
showSourceDetails: false,
}

toggleSourceDetails = () => {
this.setState((prevState) => ({
showSourceDetails: !prevState.showSourceDetails,
}));
}

onLabelChange = (event) => {
const onLabelChange = (event) => {
const label = event.target.value;
this.props.updateLabel(this.props.layerId, label);
}
props.updateLabel(props.layerId, label);
};

onMinZoomChange = (event) => {
const onMinZoomChange = (event) => {
const zoom = parseInt(event.target.value, 10);
this.props.updateMinZoom(this.props.layerId, zoom);
}
props.updateMinZoom(props.layerId, zoom);
};

onMaxZoomChange = (event) => {
const onMaxZoomChange = (event) => {
const zoom = parseInt(event.target.value, 10);
this.props.updateMaxZoom(this.props.layerId, zoom);
}
props.updateMaxZoom(props.layerId, zoom);
};

onAlphaChange = (alpha) => {
this.props.updateAlpha(this.props.layerId, alpha);
}
const onAlphaChange = (alpha) => {
props.updateAlpha(props.layerId, alpha);
};

onSourceChange = ({ propName, value }) => {
this.props.updateSourceProp(this.props.layerId, propName, value);
}
const onSourceChange = ({ propName, value }) => {
props.updateSourceProp(props.layerId, propName, value);
};

renderZoomSliders() {
const renderZoomSliders = () => {
return (
<EuiFormRow
helpText="Display layer when map is within zoom level range."
Expand All @@ -67,8 +56,8 @@ export class SettingsPanel extends Component {
<EuiRange
min={0}
max={24}
value={this.props.minZoom.toString()}
onChange={this.onMinZoomChange}
value={props.minZoom.toString()}
onChange={onMinZoomChange}
showInput
showRange
/>
Expand All @@ -81,8 +70,8 @@ export class SettingsPanel extends Component {
<EuiRange
min={0}
max={24}
value={this.props.maxZoom.toString()}
onChange={this.onMaxZoomChange}
value={props.maxZoom.toString()}
onChange={onMaxZoomChange}
showInput
showRange
/>
Expand All @@ -91,22 +80,22 @@ export class SettingsPanel extends Component {
</EuiFlexGroup>
</EuiFormRow>
);
}
};

renderLabel() {
const renderLabel = () => {
return (
<EuiFormRow
label="Layer display name"
>
<EuiFieldText
value={this.props.label}
onChange={this.onLabelChange}
value={props.label}
onChange={onLabelChange}
/>
</EuiFormRow>
);
}
};

renderAlphaSlider() {
const renderAlphaSlider = () => {
return (
<EuiFormRow
label="Layer transparency"
Expand All @@ -116,59 +105,35 @@ export class SettingsPanel extends Component {
min={.00}
max={1.00}
step={.05}
value={this.props.alpha}
onChange={this.onAlphaChange}
value={props.alpha}
onChange={onAlphaChange}
showLabels
showInput
showRange
/>
</div>
</EuiFormRow>
);
}
};

renderSourceDetails() {
if (!this.state.showSourceDetails) {
return null;
}
return (
<EuiPanel>
<EuiFlexGroup>
<EuiFlexItem>
<EuiTitle size="xs"><h5>Settings</h5></EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>

return (
<Fragment>
{this.props.renderSourceDetails()}
<EuiSpacer margin="m"/>
</Fragment>
);
}
<EuiSpacer margin="m"/>

render() {
return (
<EuiPanel>
<EuiFlexGroup>
<EuiFlexItem>
<EuiTitle size="xs"><h5>Settings</h5></EuiTitle>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiLink
onClick={this.toggleSourceDetails}
>
source details
</EuiLink>
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer margin="m"/>
{renderLabel()}

{this.renderSourceDetails()}
{renderZoomSliders()}

{this.renderLabel()}
{renderAlphaSlider()}

{this.renderZoomSliders()}
{props.renderSourceSettingsEditor({ onChange: onSourceChange })}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after merging this will become props.layer.renderSourceSettingsEditor().


{this.renderAlphaSlider()}

{this.props.renderSourceSettingsEditor({ onChange: this.onSourceChange })}

</EuiPanel>
);
}
</EuiPanel>
);
}
70 changes: 67 additions & 3 deletions x-pack/plugins/gis/public/components/layer_panel/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,38 @@ import {
EuiFlyoutBody,
EuiFlyoutFooter,
EuiSpacer,
EuiAccordion,
EuiText,
EuiLink,
} from '@elastic/eui';

export class LayerPanel extends React.Component {

state = {
displayName: null
static getDerivedStateFromProps(nextProps, prevState) {
const nextId = nextProps.selectedLayer.getId();
if (nextId !== prevState.prevId) {
return {
displayName: '',
immutableSourceProps: [],
hasLoadedSourcePropsForLayer: false,
prevId: nextId,
};
}

return null;
}

state = {}

componentDidMount() {
this._isMounted = true;
this.loadDisplayName();
this.loadImmutableSourceProperties();
}

componentDidUpdate() {
this.loadDisplayName();
this.loadImmutableSourceProperties();
}

componentWillUnmount() {
Expand All @@ -40,8 +61,24 @@ export class LayerPanel extends React.Component {

loadDisplayName = async () => {
const displayName = await this.props.selectedLayer.getDisplayName();
if (!this._isMounted || displayName === this.state.displayName) {
return;
}

this.setState({ displayName });
}

loadImmutableSourceProperties = async () => {
if (this.state.hasLoadedSourcePropsForLayer) {
return;
}

const immutableSourceProps = await this.props.selectedLayer.getImmutableSourceProperties();
if (this._isMounted) {
this.setState({ displayName });
this.setState({
immutableSourceProps,
hasLoadedSourcePropsForLayer: true,
});
}
}

Expand All @@ -60,6 +97,23 @@ export class LayerPanel extends React.Component {
);
}

_renderSourceProperties() {
return this.state.immutableSourceProps.map(({ label, value, link }) => {
function renderValue() {
if (link) {
return (<EuiLink href={link} target="_blank">{value}</EuiLink>);
}
return (<span>{value}</span>);
}
return (
<p key={label}>
<strong className="gisLayerDetails__label">{label}</strong>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove this class and remove the span around the value since I was trying to do some line-up trickery but it looks like it won't work in most cases including the screenshot you've got. So just let them line-up normally.

{renderValue()}
</p>
);
});
}

render() {
const { selectedLayer } = this.props;

Expand All @@ -81,6 +135,16 @@ export class LayerPanel extends React.Component {
</EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>
<EuiAccordion
id="accordion1"
buttonContent="Source details"
>
<EuiText color="subdued" size="s">
<div className="gisLayerDetails">
{this._renderSourceProperties()}
</div>
</EuiText>
</EuiAccordion>
</EuiFlyoutHeader>

<EuiFlyoutBody className="gisLayerPanel__body">
Expand Down
46 changes: 0 additions & 46 deletions x-pack/plugins/gis/public/shared/components/es_source_details.js

This file was deleted.

6 changes: 3 additions & 3 deletions x-pack/plugins/gis/public/shared/layers/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ export class AbstractLayer {
return this._style;
}

renderSourceDetails = () => {
return this._source.renderDetails();
};
async getImmutableSourceProperties() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice rename

return this._source.getImmutableProperties();
}

renderSourceSettingsEditor = ({ onChange }) => {
return this._source.renderSourceSettingsEditor({ onChange });
Expand Down
Loading