-
Notifications
You must be signed in to change notification settings - Fork 8.6k
[Maps] Safe-erase text-field #94873
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 12 commits into
elastic:master
from
thomasneirynck:maps/text_field_disable
Apr 5, 2021
Merged
[Maps] Safe-erase text-field #94873
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2e3002a
disable text field
thomasneirynck 34e2bfa
use undefiend
thomasneirynck 6eaeeee
reenable
thomasneirynck 7a26e5a
Merge branch 'master' of github.com:elastic/kibana into maps/text_fie…
thomasneirynck 212cf06
add unit test
thomasneirynck b84a26f
Merge branch 'master' of github.com:elastic/kibana into maps/text_fie…
thomasneirynck 1574a1d
Merge branch 'master' into maps/text_field_disable
kibanamachine 57d4d09
Merge branch 'master' into maps/text_field_disable
kibanamachine 37e073d
Merge branch 'master' into maps/text_field_disable
kibanamachine 07db18d
Merge branch 'master' of github.com:elastic/kibana into maps/text_fie…
thomasneirynck f3c97a6
add test
thomasneirynck 468395c
Merge branch 'master' into maps/text_field_disable
kibanamachine 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
109 changes: 109 additions & 0 deletions
109
x-pack/plugins/maps/public/classes/styles/vector/properties/dynamic_text_property.test.tsx
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,109 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| jest.mock('../components/vector_style_editor', () => ({ | ||
| VectorStyleEditor: () => { | ||
| return <div>mockVectorStyleEditor</div>; | ||
| }, | ||
| })); | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| // @ts-ignore | ||
| import { DynamicTextProperty } from './dynamic_text_property'; | ||
| import { RawValue, VECTOR_STYLES } from '../../../../../common/constants'; | ||
| import { IField } from '../../../fields/field'; | ||
| import { Map as MbMap } from 'mapbox-gl'; | ||
| import { mockField, MockLayer, MockStyle } from './test_helpers/test_util'; | ||
| import { IVectorLayer } from '../../../layers/vector_layer'; | ||
|
|
||
| export class MockMbMap { | ||
| _paintPropertyCalls: unknown[]; | ||
| _lastTextFieldValue: unknown | undefined; | ||
|
|
||
| constructor(lastTextFieldValue?: unknown) { | ||
| this._paintPropertyCalls = []; | ||
| this._lastTextFieldValue = lastTextFieldValue; | ||
| } | ||
| setLayoutProperty(layerId: string, propName: string, value: undefined | 'string') { | ||
| if (propName !== 'text-field') { | ||
| throw new Error('should only use to test `text-field`'); | ||
| } | ||
| this._lastTextFieldValue = value; | ||
| this._paintPropertyCalls.push([layerId, value]); | ||
| } | ||
|
|
||
| getLayoutProperty(layername: string, propName: string): unknown | undefined { | ||
| if (propName !== 'text-field') { | ||
| throw new Error('should only use to test `text-field`'); | ||
| } | ||
| return this._lastTextFieldValue; | ||
| } | ||
|
|
||
| getPaintPropertyCalls(): unknown[] { | ||
| return this._paintPropertyCalls; | ||
| } | ||
| } | ||
|
|
||
| const makeProperty = (mockStyle: MockStyle, field: IField | null) => { | ||
| return new DynamicTextProperty( | ||
| {}, | ||
| VECTOR_STYLES.LABEL_TEXT, | ||
| field, | ||
| (new MockLayer(mockStyle) as unknown) as IVectorLayer, | ||
| () => { | ||
| return (value: RawValue) => value + '_format'; | ||
| } | ||
| ); | ||
| }; | ||
|
|
||
| describe('syncTextFieldWithMb', () => { | ||
| describe('with field', () => { | ||
| test('Should set', async () => { | ||
| const dynamicTextProperty = makeProperty(new MockStyle({ min: 0, max: 100 }), mockField); | ||
| const mockMbMap = (new MockMbMap() as unknown) as MbMap; | ||
|
|
||
| dynamicTextProperty.syncTextFieldWithMb('foobar', mockMbMap); | ||
|
|
||
| // @ts-expect-error | ||
| expect(mockMbMap.getPaintPropertyCalls()).toEqual([ | ||
| ['foobar', ['coalesce', ['get', '__kbn__dynamic__foobar__labelText'], '']], | ||
| ]); | ||
| }); | ||
| }); | ||
|
|
||
| describe('without field', () => { | ||
| test('Should clear', async () => { | ||
| const dynamicTextProperty = makeProperty(new MockStyle({ min: 0, max: 100 }), null); | ||
| const mockMbMap = (new MockMbMap([ | ||
| 'foobar', | ||
| ['coalesce', ['get', '__kbn__dynamic__foobar__labelText'], ''], | ||
| ]) as unknown) as MbMap; | ||
|
|
||
| dynamicTextProperty.syncTextFieldWithMb('foobar', mockMbMap); | ||
|
|
||
| // @ts-expect-error | ||
| expect(mockMbMap.getPaintPropertyCalls()).toEqual([['foobar', undefined]]); | ||
| }); | ||
|
|
||
| test('Should not clear when already cleared', async () => { | ||
| // This verifies a weird edge-case in mapbox-gl, where setting the `text-field` layout-property to null causes tiles to be invalidated. | ||
| // This triggers a refetch of the tile during panning and zooming | ||
| // This affects vector-tile rendering in tiled_vector_layers with custom vector_styles | ||
| // It does _not_ affect EMS, since that does not have a code-path where a `text-field` need to be resynced. | ||
| // Do not remove this logic without verifying that mapbox-gl does not re-issue tile-requests for previously requested tiles | ||
|
|
||
| const dynamicTextProperty = makeProperty(new MockStyle({ min: 0, max: 100 }), null); | ||
| const mockMbMap = (new MockMbMap(undefined) as unknown) as MbMap; | ||
|
|
||
| dynamicTextProperty.syncTextFieldWithMb('foobar', mockMbMap); | ||
|
|
||
| // @ts-expect-error | ||
| expect(mockMbMap.getPaintPropertyCalls()).toEqual([]); | ||
| }); | ||
| }); | ||
| }); | ||
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
70 changes: 70 additions & 0 deletions
70
x-pack/plugins/maps/public/classes/styles/vector/properties/static_text_property.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,70 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| import { StaticTextProperty } from './static_text_property'; | ||
| import { VECTOR_STYLES } from '../../../../../common/constants'; | ||
| import { Map as MbMap } from 'mapbox-gl'; | ||
|
|
||
| export class MockMbMap { | ||
| _paintPropertyCalls: unknown[]; | ||
| _lastTextFieldValue: unknown | undefined; | ||
|
|
||
| constructor(lastTextFieldValue?: unknown) { | ||
| this._paintPropertyCalls = []; | ||
| this._lastTextFieldValue = lastTextFieldValue; | ||
| } | ||
| setLayoutProperty(layerId: string, propName: string, value: undefined | 'string') { | ||
| if (propName !== 'text-field') { | ||
| throw new Error('should only use to test `text-field`'); | ||
| } | ||
| this._lastTextFieldValue = value; | ||
| this._paintPropertyCalls.push([layerId, value]); | ||
| } | ||
|
|
||
| getLayoutProperty(layername: string, propName: string): unknown | undefined { | ||
| if (propName !== 'text-field') { | ||
| throw new Error('should only use to test `text-field`'); | ||
| } | ||
| return this._lastTextFieldValue; | ||
| } | ||
|
|
||
| getPaintPropertyCalls(): unknown[] { | ||
| return this._paintPropertyCalls; | ||
| } | ||
| } | ||
|
|
||
| const makeProperty = (value: string) => { | ||
| return new StaticTextProperty({ value }, VECTOR_STYLES.LABEL_TEXT); | ||
| }; | ||
|
|
||
| describe('syncTextFieldWithMb', () => { | ||
| test('Should set with value', async () => { | ||
| const dynamicTextProperty = makeProperty('foo'); | ||
| const mockMbMap = (new MockMbMap() as unknown) as MbMap; | ||
|
|
||
| dynamicTextProperty.syncTextFieldWithMb('foobar', mockMbMap); | ||
|
|
||
| // @ts-expect-error | ||
| expect(mockMbMap.getPaintPropertyCalls()).toEqual([['foobar', 'foo']]); | ||
| }); | ||
|
|
||
| test('Should not clear when already cleared', async () => { | ||
| // This verifies a weird edge-case in mapbox-gl, where setting the `text-field` layout-property to null causes tiles to be invalidated. | ||
| // This triggers a refetch of the tile during panning and zooming | ||
| // This affects vector-tile rendering in tiled_vector_layers with custom vector_styles | ||
| // It does _not_ affect EMS, since that does not have a code-path where a `text-field` need to be resynced. | ||
| // Do not remove this logic without verifying that mapbox-gl does not re-issue tile-requests for previously requested tiles | ||
|
|
||
| const dynamicTextProperty = makeProperty(''); | ||
| const mockMbMap = (new MockMbMap(undefined) as unknown) as MbMap; | ||
|
|
||
| dynamicTextProperty.syncTextFieldWithMb('foobar', mockMbMap); | ||
|
|
||
| // @ts-expect-error | ||
| expect(mockMbMap.getPaintPropertyCalls()).toEqual([]); | ||
| }); | ||
| }); |
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
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.