-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Maps] Update style when metrics change #83586
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
Merged
thomasneirynck
merged 35 commits into
elastic:master
from
thomasneirynck:maps/update_style
Dec 4, 2020
Merged
Changes from 34 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
6105ba7
init commit
thomasneirynck 47560f9
some type fixes
thomasneirynck f54ca8a
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 71e49df
add type check
thomasneirynck b7d8bbd
only take into account invalid dynamic fields
thomasneirynck c507a77
tmp debug
thomasneirynck e861f26
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck ffad517
ts type fixes
thomasneirynck e002047
retype
thomasneirynck ef1f225
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 9590abd
fix field-lookup after refactor
thomasneirynck e1e7ea0
type fixes
thomasneirynck c941774
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 54eacb3
add test covergage
thomasneirynck 001e0e1
add edge case test
thomasneirynck 6b70fcb
fix test for new behavior
thomasneirynck 361486a
fix rum test
thomasneirynck 67c1362
type fix
thomasneirynck 4f72d40
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck f794114
Merge branch 'master' into maps/update_style
thomasneirynck 09e8dba
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck 0efe401
revert uptime change
thomasneirynck 3f9ffdf
Merge branch 'master' into maps/update_style
kibanamachine 6ea286b
feedback
thomasneirynck 5d6fa3e
rearrange
thomasneirynck ac2f943
switch inner-outer loop
thomasneirynck bb65b1d
use foreach
thomasneirynck 17c987d
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck e87c721
simplify
thomasneirynck 1455ef9
Merge branch 'master' of github.com:elastic/kibana into maps/update_s…
thomasneirynck b09404f
tidy up
thomasneirynck f86ed22
type fix
thomasneirynck 98c8ab9
still perform correction, to deal with edge cases
thomasneirynck d732c7a
remove cruft
thomasneirynck 7616c62
remove unused exports
thomasneirynck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,8 @@ import { IVectorLayer } from '../classes/layers/vector_layer/vector_layer'; | |
| import { LAYER_STYLE_TYPE, LAYER_TYPE } from '../../common/constants'; | ||
| import { IVectorStyle } from '../classes/styles/vector/vector_style'; | ||
| import { notifyLicensedFeatureUsage } from '../licensed_features'; | ||
| import { IESAggField } from '../classes/fields/agg'; | ||
| import { IField } from '../classes/fields/field'; | ||
|
|
||
| export function trackCurrentLayerState(layerId: string) { | ||
| return { | ||
|
|
@@ -274,13 +276,37 @@ export function updateLayerOrder(newLayerOrder: number[]) { | |
| }; | ||
| } | ||
|
|
||
| export function updateMetricsProp(layerId: string, value: unknown) { | ||
| return async ( | ||
| dispatch: ThunkDispatch<MapStoreState, void, AnyAction>, | ||
| getState: () => MapStoreState | ||
| ) => { | ||
| const layer = getLayerById(layerId, getState()); | ||
| const previousFields = await (layer as IVectorLayer).getFields(); | ||
nreese marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| await dispatch({ | ||
| type: UPDATE_SOURCE_PROP, | ||
| layerId, | ||
| propName: 'metrics', | ||
| value, | ||
| }); | ||
| await dispatch(updateStyleProperties(layerId, previousFields as IESAggField[])); | ||
| dispatch(syncDataForLayerId(layerId)); | ||
| }; | ||
| } | ||
|
|
||
| export function updateSourceProp( | ||
| layerId: string, | ||
| propName: string, | ||
| value: unknown, | ||
| newLayerType?: LAYER_TYPE | ||
| ) { | ||
| return async (dispatch: ThunkDispatch<MapStoreState, void, AnyAction>) => { | ||
| if (propName === 'metrics') { | ||
| if (newLayerType) { | ||
| throw new Error('May not change layer-type when modifying metrics source-property'); | ||
| } | ||
| return await dispatch(updateMetricsProp(layerId, value)); | ||
| } | ||
| dispatch({ | ||
| type: UPDATE_SOURCE_PROP, | ||
| layerId, | ||
|
|
@@ -290,7 +316,6 @@ export function updateSourceProp( | |
| if (newLayerType) { | ||
| dispatch(updateLayerType(layerId, newLayerType)); | ||
| } | ||
| await dispatch(clearMissingStyleProperties(layerId)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. only needs to occur for metrics changes |
||
| dispatch(syncDataForLayerId(layerId)); | ||
| }; | ||
| } | ||
|
|
@@ -422,7 +447,7 @@ function removeLayerFromLayerList(layerId: string) { | |
| }; | ||
| } | ||
|
|
||
| export function clearMissingStyleProperties(layerId: string) { | ||
| export function updateStyleProperties(layerId: string, previousFields: IField[]) { | ||
thomasneirynck marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return async ( | ||
| dispatch: ThunkDispatch<MapStoreState, void, AnyAction>, | ||
| getState: () => MapStoreState | ||
|
|
@@ -441,8 +466,9 @@ export function clearMissingStyleProperties(layerId: string) { | |
| const { | ||
| hasChanges, | ||
| nextStyleDescriptor, | ||
| } = await (style as IVectorStyle).getDescriptorWithMissingStylePropsRemoved( | ||
| } = await (style as IVectorStyle).getDescriptorWithUpdatedStyleProps( | ||
| nextFields, | ||
| previousFields, | ||
| getMapColors(getState()) | ||
| ); | ||
| if (hasChanges && nextStyleDescriptor) { | ||
|
|
@@ -485,13 +511,13 @@ export function updateLayerStyleForSelectedLayer(styleDescriptor: StyleDescripto | |
|
|
||
| export function setJoinsForLayer(layer: ILayer, joins: JoinDescriptor[]) { | ||
| return async (dispatch: ThunkDispatch<MapStoreState, void, AnyAction>) => { | ||
| const previousFields = await (layer as IVectorLayer).getFields(); | ||
| await dispatch({ | ||
| type: SET_JOINS, | ||
| layer, | ||
| joins, | ||
| }); | ||
|
|
||
| await dispatch(clearMissingStyleProperties(layer.getId())); | ||
| await dispatch(updateStyleProperties(layer.getId(), previousFields)); | ||
| dispatch(syncDataForLayerId(layer.getId())); | ||
| }; | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
x-pack/plugins/maps/public/classes/styles/vector/style_fields_helper.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /* | ||
| * 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 { FIELD_ORIGIN, VECTOR_STYLES } from '../../../../common/constants'; | ||
| import { createStyleFieldsHelper, StyleFieldsHelper } from './style_fields_helper'; | ||
| import { AbstractField, IField } from '../../fields/field'; | ||
|
|
||
| class MockField extends AbstractField { | ||
| private readonly _dataType: string; | ||
| private readonly _supportsAutoDomain: boolean; | ||
| constructor({ dataType, supportsAutoDomain }: { dataType: string; supportsAutoDomain: boolean }) { | ||
| super({ fieldName: 'foobar_' + dataType, origin: FIELD_ORIGIN.SOURCE }); | ||
| this._dataType = dataType; | ||
| this._supportsAutoDomain = supportsAutoDomain; | ||
| } | ||
| async getDataType() { | ||
| return this._dataType; | ||
| } | ||
|
|
||
| supportsAutoDomain(): boolean { | ||
| return this._supportsAutoDomain; | ||
| } | ||
| } | ||
|
|
||
| describe('StyleFieldHelper', () => { | ||
| describe('isFieldDataTypeCompatibleWithStyleType', () => { | ||
| async function createHelper( | ||
| supportsAutoDomain: boolean | ||
| ): Promise<{ | ||
| styleFieldHelper: StyleFieldsHelper; | ||
| stringField: IField; | ||
| numberField: IField; | ||
| dateField: IField; | ||
| }> { | ||
| const stringField = new MockField({ | ||
| dataType: 'string', | ||
| supportsAutoDomain, | ||
| }); | ||
| const numberField = new MockField({ | ||
| dataType: 'number', | ||
| supportsAutoDomain, | ||
| }); | ||
| const dateField = new MockField({ | ||
| dataType: 'date', | ||
| supportsAutoDomain, | ||
| }); | ||
| return { | ||
| styleFieldHelper: await createStyleFieldsHelper([stringField, numberField, dateField]), | ||
| stringField, | ||
| numberField, | ||
| dateField, | ||
| }; | ||
| } | ||
|
|
||
| test('Should validate colors for all data types', async () => { | ||
| const { styleFieldHelper, stringField, numberField, dateField } = await createHelper(true); | ||
|
|
||
| [ | ||
| VECTOR_STYLES.FILL_COLOR, | ||
| VECTOR_STYLES.LINE_COLOR, | ||
| VECTOR_STYLES.LABEL_COLOR, | ||
| VECTOR_STYLES.LABEL_BORDER_COLOR, | ||
| ].forEach((styleType) => { | ||
| expect(styleFieldHelper.hasFieldForStyle(stringField, styleType)).toEqual(true); | ||
| expect(styleFieldHelper.hasFieldForStyle(numberField, styleType)).toEqual(true); | ||
| expect(styleFieldHelper.hasFieldForStyle(dateField, styleType)).toEqual(true); | ||
| }); | ||
| }); | ||
|
|
||
| test('Should validate sizes for all number types', async () => { | ||
| const { styleFieldHelper, stringField, numberField, dateField } = await createHelper(true); | ||
|
|
||
| [VECTOR_STYLES.LINE_WIDTH, VECTOR_STYLES.LABEL_SIZE, VECTOR_STYLES.ICON_SIZE].forEach( | ||
| (styleType) => { | ||
| expect(styleFieldHelper.hasFieldForStyle(stringField, styleType)).toEqual(false); | ||
| expect(styleFieldHelper.hasFieldForStyle(numberField, styleType)).toEqual(true); | ||
| expect(styleFieldHelper.hasFieldForStyle(dateField, styleType)).toEqual(true); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test('Should not validate sizes if autodomain is not enabled', async () => { | ||
| const { styleFieldHelper, stringField, numberField, dateField } = await createHelper(false); | ||
|
|
||
| [VECTOR_STYLES.LINE_WIDTH, VECTOR_STYLES.LABEL_SIZE, VECTOR_STYLES.ICON_SIZE].forEach( | ||
| (styleType) => { | ||
| expect(styleFieldHelper.hasFieldForStyle(stringField, styleType)).toEqual(false); | ||
| expect(styleFieldHelper.hasFieldForStyle(numberField, styleType)).toEqual(false); | ||
| expect(styleFieldHelper.hasFieldForStyle(dateField, styleType)).toEqual(false); | ||
| } | ||
| ); | ||
| }); | ||
|
|
||
| test('Should validate orientation only number types', async () => { | ||
| const { styleFieldHelper, stringField, numberField, dateField } = await createHelper(true); | ||
|
|
||
| [VECTOR_STYLES.ICON_ORIENTATION].forEach((styleType) => { | ||
| expect(styleFieldHelper.hasFieldForStyle(stringField, styleType)).toEqual(false); | ||
| expect(styleFieldHelper.hasFieldForStyle(numberField, styleType)).toEqual(true); | ||
| expect(styleFieldHelper.hasFieldForStyle(dateField, styleType)).toEqual(false); | ||
| }); | ||
| }); | ||
|
|
||
| test('Should not validate label_border_size', async () => { | ||
| const { styleFieldHelper, stringField, numberField, dateField } = await createHelper(true); | ||
|
|
||
| [VECTOR_STYLES.LABEL_BORDER_SIZE].forEach((styleType) => { | ||
| expect(styleFieldHelper.hasFieldForStyle(stringField, styleType)).toEqual(false); | ||
| expect(styleFieldHelper.hasFieldForStyle(numberField, styleType)).toEqual(false); | ||
| expect(styleFieldHelper.hasFieldForStyle(dateField, styleType)).toEqual(false); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.