Skip to content

Commit fe8df32

Browse files
committed
tslint cleanup
1 parent c5f4ab0 commit fe8df32

4 files changed

Lines changed: 38 additions & 25 deletions

File tree

x-pack/plugins/maps/public/classes/styles/color_palettes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function getColorRampCenterColor(colorPaletteId: string): string | null {
129129
// Returns an array of color stops
130130
// [ stop_input_1: number, stop_output_1: color, stop_input_n: number, stop_output_n: color ]
131131
export function getOrdinalMbColorRampStops(
132-
colorPaletteId: string,
132+
colorPaletteId: string | null,
133133
min: number,
134134
max: number
135135
): Array<number | string> | null {

x-pack/plugins/maps/public/classes/styles/vector/components/legend/category.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { VectorIcon } from './vector_icon';
1111

1212
interface Props {
1313
styleName: VECTOR_STYLES;
14-
label: ReactElement<any> | string;
14+
label: ReactElement<any> | string | number;
1515
color: string;
1616
isLinesOnly: boolean;
1717
isPointsOnly: boolean;

x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_color_property.test.tsx

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jest.mock('../components/vector_style_editor', () => ({
1313

1414
import React from 'react';
1515
import { shallow } from 'enzyme';
16+
import { Feature, Point } from 'geojson';
1617

1718
import { DynamicColorProperty } from './dynamic_color_property';
1819
import { COLOR_MAP_TYPE, VECTOR_STYLES } from '../../../../../common/constants';
@@ -21,18 +22,12 @@ import { ColorDynamicOptions } from '../../../../../common/descriptor_types';
2122
import { IVectorLayer } from '../../../layers/vector_layer/vector_layer';
2223
import { IField } from '../../../fields/field';
2324

24-
const defaultMockStyle = new MockStyle();
25-
26-
const makeProperty = (
27-
options: ColorDynamicOptions,
28-
mockStyle?: MockStyle = defaultMockStyle,
29-
field?: IField = mockField
30-
) => {
25+
const makeProperty = (options: ColorDynamicOptions, style?: MockStyle, field?: IField) => {
3126
return new DynamicColorProperty(
3227
options,
3328
VECTOR_STYLES.LINE_COLOR,
34-
field,
35-
(new MockLayer(mockStyle) as unknown) as IVectorLayer,
29+
field ? field : mockField,
30+
(new MockLayer(style ? style : new MockStyle()) as unknown) as IVectorLayer,
3631
() => {
3732
return (value: string | number | undefined) => value + '_format';
3833
}
@@ -168,14 +163,18 @@ describe('categorical', () => {
168163
});
169164
});
170165

171-
function makeFeatures(foobarPropValues) {
172-
return foobarPropValues.map((value) => {
166+
function makeFeatures(foobarPropValues: string[]) {
167+
return foobarPropValues.map((value: string) => {
173168
return {
174169
type: 'Feature',
170+
geometry: {
171+
type: 'Point',
172+
coordinates: [-10, 0],
173+
} as Point,
175174
properties: {
176175
foobar: value,
177176
},
178-
};
177+
} as Feature;
179178
});
180179
}
181180

@@ -228,7 +227,7 @@ test('Should pluck the categorical style-meta from fieldmeta', async () => {
228227
});
229228

230229
describe('supportsFieldMeta', () => {
231-
test('should support it when field does for ordinals', () => {
230+
test('should support fieldMeta when ordinal field supports fieldMeta', () => {
232231
const dynamicStyleOptions = {
233232
type: COLOR_MAP_TYPE.ORDINAL,
234233
fieldMetaOptions,
@@ -238,7 +237,7 @@ describe('supportsFieldMeta', () => {
238237
expect(styleProp.supportsFieldMeta()).toEqual(true);
239238
});
240239

241-
test('should support it when field does for categories', () => {
240+
test('should support fieldMeta when categorical field supports fieldMeta', () => {
242241
const dynamicStyleOptions = {
243242
type: COLOR_MAP_TYPE.CATEGORICAL,
244243
fieldMetaOptions,
@@ -248,7 +247,7 @@ describe('supportsFieldMeta', () => {
248247
expect(styleProp.supportsFieldMeta()).toEqual(true);
249248
});
250249

251-
test('should not support it when field does not', () => {
250+
test('should not support fieldMeta when field does not support fieldMeta', () => {
252251
const field = Object.create(mockField);
253252
field.supportsFieldMeta = function () {
254253
return false;
@@ -263,17 +262,26 @@ describe('supportsFieldMeta', () => {
263262
expect(styleProp.supportsFieldMeta()).toEqual(false);
264263
});
265264

266-
test('should not support it when field config not complete', () => {
265+
test('should not support fieldMeta when field is not provided', () => {
267266
const dynamicStyleOptions = {
268267
type: COLOR_MAP_TYPE.ORDINAL,
269268
fieldMetaOptions,
270269
};
271-
const styleProp = makeProperty(dynamicStyleOptions, undefined, null);
270+
271+
const styleProp = new DynamicColorProperty(
272+
dynamicStyleOptions,
273+
VECTOR_STYLES.LINE_COLOR,
274+
null,
275+
(new MockLayer(new MockStyle()) as unknown) as IVectorLayer,
276+
() => {
277+
return (value: string | number | undefined) => value + '_format';
278+
}
279+
);
272280

273281
expect(styleProp.supportsFieldMeta()).toEqual(false);
274282
});
275283

276-
test('should not support it when using custom ramp for ordinals', () => {
284+
test('should not support fieldMeta when using custom ramp for ordinal field', () => {
277285
const dynamicStyleOptions = {
278286
type: COLOR_MAP_TYPE.ORDINAL,
279287
useCustomColorRamp: true,
@@ -285,7 +293,7 @@ describe('supportsFieldMeta', () => {
285293
expect(styleProp.supportsFieldMeta()).toEqual(false);
286294
});
287295

288-
test('should not support it when using custom palette for categories', () => {
296+
test('should not support fieldMeta when using custom palette for categorical field', () => {
289297
const dynamicStyleOptions = {
290298
type: COLOR_MAP_TYPE.CATEGORICAL,
291299
useCustomColorPalette: true,
@@ -315,6 +323,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
315323
field: {},
316324
fieldMetaOptions,
317325
};
326+
// @ts-expect-error - test is verifing behavior when field is invalid.
318327
const colorProperty = makeProperty(dynamicStyleOptions);
319328
expect(colorProperty._getMbColor()).toBeNull();
320329
});
@@ -456,7 +465,9 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
456465
const dynamicStyleOptions = {
457466
type: COLOR_MAP_TYPE.CATEGORICAL,
458467
field: {},
468+
fieldMetaOptions,
459469
};
470+
// @ts-expect-error - test is verifing behavior when field is invalid.
460471
const colorProperty = makeProperty(dynamicStyleOptions);
461472
expect(colorProperty._getMbColor()).toBeNull();
462473
});
@@ -465,6 +476,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
465476
test('should return null when color palette is not provided', async () => {
466477
const dynamicStyleOptions = {
467478
type: COLOR_MAP_TYPE.CATEGORICAL,
479+
fieldMetaOptions,
468480
};
469481
const colorProperty = makeProperty(dynamicStyleOptions);
470482
expect(colorProperty._getMbColor()).toBeNull();
@@ -474,6 +486,7 @@ describe('get mapbox color expression (via internal _getMbColor)', () => {
474486
const dynamicStyleOptions = {
475487
type: COLOR_MAP_TYPE.CATEGORICAL,
476488
colorCategory: 'palette_0',
489+
fieldMetaOptions,
477490
};
478491
const colorProperty = makeProperty(dynamicStyleOptions);
479492
expect(colorProperty._getMbColor()).toEqual([

x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_color_property.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class DynamicColorProperty extends DynamicStyleProperty<ColorDynamicOptio
123123
},
124124
[]
125125
);
126-
const firstStopValue = colorStops[0];
126+
const firstStopValue = colorStops[0] as number;
127127
const lessThanFirstStopValue = firstStopValue - 1;
128128
return [
129129
'step',
@@ -138,7 +138,7 @@ export class DynamicColorProperty extends DynamicStyleProperty<ColorDynamicOptio
138138
}
139139

140140
const colorStops = getOrdinalMbColorRampStops(
141-
this._options.color,
141+
this._options.color ? this._options.color : null,
142142
rangeFieldMeta.min,
143143
rangeFieldMeta.max
144144
);
@@ -293,8 +293,8 @@ export class DynamicColorProperty extends DynamicStyleProperty<ColorDynamicOptio
293293
renderLegendDetailRow({ isPointsOnly, isLinesOnly, symbolId }: LegendProps) {
294294
const { stops, defaultColor } = this._getColorStops();
295295
const breaks = [];
296-
stops.forEach(({ stop, color }: OrdinalColorStop) => {
297-
if (stop) {
296+
stops.forEach(({ stop, color }: { stop: number | null; color: string }) => {
297+
if (stop !== null) {
298298
breaks.push({
299299
color,
300300
symbolId,

0 commit comments

Comments
 (0)