Skip to content

Commit

Permalink
[Maps] disable style forms when they are not applied due to other sty…
Browse files Browse the repository at this point in the history
…le settings (#55858)

* [Maps] disable style forms when they are not applied due to other style settings

* disable label border color when label border is none

* disable symbol style inputs when symbol size is zero

Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
nreese and elasticmachine authored Jan 31, 2020
1 parent 5ed7be9 commit 38c7d3a
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import './components/color_gradient';
@import './vector/components/static_dynamic_style_row';
@import './vector/components/style_prop_editor';
@import './vector/components/color/color_stops';
@import './vector/components/symbol/icon_select';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.mapStyleFormDisabledTooltip {
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import { i18n } from '@kbn/i18n';

import { VECTOR_STYLES } from '../vector_style_defaults';

export function getDisabledByMessage(styleName) {
return i18n.translate('xpack.maps.styles.vector.disabledByMessage', {
defaultMessage: `Set '{styleLabel}' to enable`,
values: { styleLabel: getVectorStyleLabel(styleName) },
});
}

export function getVectorStyleLabel(styleName) {
switch (styleName) {
case VECTOR_STYLES.FILL_COLOR:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

import React from 'react';

import { EuiFormRow, EuiSelect } from '@elastic/eui';
import { EuiFormRow, EuiSelect, EuiToolTip } from '@elastic/eui';
import { LABEL_BORDER_SIZES, VECTOR_STYLES } from '../../vector_style_defaults';
import { getVectorStyleLabel } from '../get_vector_style_label';
import { getVectorStyleLabel, getDisabledByMessage } from '../get_vector_style_label';
import { i18n } from '@kbn/i18n';

const options = [
Expand Down Expand Up @@ -38,20 +38,26 @@ const options = [
},
];

export function VectorStyleLabelBorderSizeEditor({ handlePropertyChange, styleProperty }) {
export function VectorStyleLabelBorderSizeEditor({
disabled,
disabledBy,
handlePropertyChange,
styleProperty,
}) {
function onChange(e) {
const styleDescriptor = {
options: { size: e.target.value },
};
handlePropertyChange(styleProperty.getStyleName(), styleDescriptor);
}

return (
const labelBorderSizeForm = (
<EuiFormRow
label={getVectorStyleLabel(VECTOR_STYLES.LABEL_BORDER_SIZE)}
display="columnCompressed"
>
<EuiSelect
disabled={disabled}
options={options}
value={styleProperty.getOptions().size}
onChange={onChange}
Expand All @@ -62,4 +68,17 @@ export function VectorStyleLabelBorderSizeEditor({ handlePropertyChange, stylePr
/>
</EuiFormRow>
);

if (!disabled) {
return labelBorderSizeForm;
}

return (
<EuiToolTip
anchorClassName="mapStyleFormDisabledTooltip"
content={getDisabledByMessage(disabledBy)}
>
{labelBorderSizeForm}
</EuiToolTip>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
*/

import React, { Component, Fragment } from 'react';
import { getVectorStyleLabel } from './get_vector_style_label';
import { EuiFormRow, EuiSelect } from '@elastic/eui';
import { getVectorStyleLabel, getDisabledByMessage } from './get_vector_style_label';
import {
EuiFormRow,
EuiSelect,
EuiFlexGroup,
EuiFlexItem,
EuiFieldText,
EuiToolTip,
} from '@elastic/eui';
import { VectorStyle } from '../vector_style';
import { i18n } from '@kbn/i18n';

Expand Down Expand Up @@ -69,7 +76,7 @@ export class StylePropEditor extends Component {
: VectorStyle.STYLE_TYPE.STATIC
}
onChange={this._onTypeToggle}
disabled={this.props.fields.length === 0}
disabled={this.props.disabled || this.props.fields.length === 0}
aria-label={i18n.translate('xpack.maps.styles.staticDynamicSelect.ariaLabel', {
defaultMessage: 'Select to style by fixed value or by data value',
})}
Expand All @@ -83,17 +90,35 @@ export class StylePropEditor extends Component {
this._onFieldMetaOptionsChange
);

const staticDynamicSelect = this.renderStaticDynamicSelect();

const stylePropertyForm = this.props.disabled ? (
<EuiToolTip
anchorClassName="mapStyleFormDisabledTooltip"
content={getDisabledByMessage(this.props.disabledBy)}
>
<EuiFlexGroup gutterSize="none" justifyContent="flexEnd">
<EuiFlexItem grow={false}>{staticDynamicSelect}</EuiFlexItem>
<EuiFlexItem>
<EuiFieldText compressed disabled />
</EuiFlexItem>
</EuiFlexGroup>
</EuiToolTip>
) : (
<Fragment>
{React.cloneElement(this.props.children, {
staticDynamicSelect,
})}
{fieldMetaOptionsPopover}
</Fragment>
);

return (
<EuiFormRow
label={getVectorStyleLabel(this.props.styleProperty.getStyleName())}
display="rowCompressed"
>
<Fragment>
{React.cloneElement(this.props.children, {
staticDynamicSelect: this.renderStaticDynamicSelect(),
})}
{fieldMetaOptionsPopover}
</Fragment>
{stylePropertyForm}
</EuiFormRow>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

import React from 'react';

import { EuiFormRow, EuiButtonGroup } from '@elastic/eui';
import { EuiFormRow, EuiButtonGroup, EuiToolTip } from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { SYMBOLIZE_AS_TYPES } from '../../../../../../common/constants';
import { VECTOR_STYLES } from '../../vector_style_defaults';
import { getDisabledByMessage } from '../get_vector_style_label';

const SYMBOLIZE_AS_OPTIONS = [
{
Expand All @@ -27,7 +28,12 @@ const SYMBOLIZE_AS_OPTIONS = [
},
];

export function VectorStyleSymbolizeAsEditor({ styleProperty, handlePropertyChange }) {
export function VectorStyleSymbolizeAsEditor({
disabled,
disabledBy,
styleProperty,
handlePropertyChange,
}) {
const styleOptions = styleProperty.getOptions();
const selectedOption = SYMBOLIZE_AS_OPTIONS.find(({ id }) => {
return id === styleOptions.value;
Expand All @@ -42,14 +48,15 @@ export function VectorStyleSymbolizeAsEditor({ styleProperty, handlePropertyChan
handlePropertyChange(VECTOR_STYLES.SYMBOLIZE_AS, styleDescriptor);
};

return (
const symbolizeAsForm = (
<EuiFormRow
label={i18n.translate('xpack.maps.vector.symbolLabel', {
defaultMessage: 'Symbol type',
})}
display="columnCompressed"
>
<EuiButtonGroup
isDisabled={disabled}
buttonSize="compressed"
options={SYMBOLIZE_AS_OPTIONS}
idSelected={selectedOption ? selectedOption.id : undefined}
Expand All @@ -58,4 +65,17 @@ export function VectorStyleSymbolizeAsEditor({ styleProperty, handlePropertyChan
/>
</EuiFormRow>
);

if (!disabled) {
return symbolizeAsForm;
}

return (
<EuiToolTip
anchorClassName="mapStyleFormDisabledTooltip"
content={getDisabledByMessage(disabledBy)}
>
{symbolizeAsForm}
</EuiToolTip>
);
}
Loading

0 comments on commit 38c7d3a

Please sign in to comment.