Skip to content

Commit

Permalink
more edits
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasneirynck committed Mar 6, 2020
1 parent 89d461d commit fae5e84
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ import { CATEGORICAL_DATA_TYPES, COLOR_MAP_TYPE } from '../../../../../../common
import { COLOR_GRADIENTS, COLOR_PALETTES } from '../../../color_utils';
import { i18n } from '@kbn/i18n';

function getDefaultColorMapType(fieldType) {
return CATEGORICAL_DATA_TYPES.includes(fieldType)
? COLOR_MAP_TYPE.CATEGORICAL
: COLOR_MAP_TYPE.ORDINAL;
}

export function DynamicColorForm({
fields,
onDynamicStyleChange,
Expand Down Expand Up @@ -47,7 +41,9 @@ export function DynamicColorForm({

const onFieldChange = async ({ field }) => {
const { name, origin, type: fieldType } = field;
const defaultColorMapType = getDefaultColorMapType(fieldType);
const defaultColorMapType = CATEGORICAL_DATA_TYPES.includes(fieldType)
? COLOR_MAP_TYPE.CATEGORICAL
: COLOR_MAP_TYPE.ORDINAL;
onDynamicStyleChange(styleProperty.getStyleName(), {
...styleOptions,
field: { name, origin },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class VectorStyleEditor extends Component {
dateFields: [],
numberFields: [],
fields: [],
styleableFields: [],
ordinalAndCategoricalFields: [],
defaultDynamicProperties: getDefaultDynamicProperties(),
defaultStaticProperties: getDefaultStaticProperties(),
supportedFeatures: undefined,
Expand Down Expand Up @@ -70,25 +70,19 @@ export class VectorStyleEditor extends Component {
const fieldPromises = fields.map(getFieldMeta);
const fieldsArrayAll = await Promise.all(fieldPromises);
if (this._isMounted && !_.isEqual(fieldsArrayAll, this.state.fields)) {
this.setState({ fields: fieldsArrayAll });
return;
}

const styleableFields = fieldsArrayAll.filter(field => {
return CATEGORICAL_DATA_TYPES.includes(field.type) || ORDINAL_DATA_TYPES.includes(field.type);
this.setState({
fields: fieldsArrayAll,
ordinalAndCategoricalFields: fieldsArrayAll.filter(field => {
return (
CATEGORICAL_DATA_TYPES.includes(field.type) || ORDINAL_DATA_TYPES.includes(field.type)
);
}),
dateFields: fieldsArrayAll.filter(field => field.type === 'date'),
numberFields: fieldsArrayAll.filter(field => field.type === 'number'),
});
if (this._isMounted && !_.isEqual(styleableFields, this.state.styleableFields)) {
this.setState({ styleableFields: styleableFields });
}

const dateFieldsArray = styleableFields.filter(field => field.type === 'date');
if (this._isMounted && !_.isEqual(dateFieldsArray, this.state.dateFields)) {
this.setState({ dateFields: dateFieldsArray });
}

const numberFieldsArray = styleableFields.filter(field => field.type === 'number');
if (this._isMounted && !_.isEqual(numberFieldsArray, this.state.numberFields)) {
this.setState({ numberFields: numberFieldsArray });
}
}

async _loadSupportedFeatures() {
Expand Down Expand Up @@ -166,7 +160,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.FILL_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.FILL_COLOR].options
}
Expand All @@ -187,7 +181,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.LINE_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.LINE_COLOR].options
}
Expand Down Expand Up @@ -243,7 +237,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_COLOR].options
}
Expand Down Expand Up @@ -276,7 +270,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.LABEL_BORDER_COLOR]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.LABEL_BORDER_COLOR].options
}
Expand Down Expand Up @@ -329,7 +323,7 @@ export class VectorStyleEditor extends Component {
onStaticStyleChange={this._onStaticStyleChange}
onDynamicStyleChange={this._onDynamicStyleChange}
styleProperty={this.props.styleProperties[VECTOR_STYLES.ICON]}
fields={this.state.styleableFields}
fields={this.state.ordinalAndCategoricalFields}
defaultStaticStyleOptions={
this.state.defaultStaticProperties[VECTOR_STYLES.ICON].options
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => {
});
});

test('Should read out categorical type correctly', async () => {
test('isCategorical should return true when type is categorical', async () => {
const categoricalColorStyle = makeProperty({
type: COLOR_MAP_TYPE.CATEGORICAL,
colorCategory: 'palette_0',
Expand All @@ -247,7 +247,7 @@ test('Should read out categorical type correctly', async () => {
expect(categoricalColorStyle.isCategorical()).toEqual(true);
});

test('Should read out ordinal correctly when type===undefined', async () => {
test('isOrdinal should return true when type is ordinal', async () => {
const ordinalColorStyle = makeProperty({
type: undefined,
color: 'Blues',
Expand Down

0 comments on commit fae5e84

Please sign in to comment.