@@ -20,20 +20,16 @@ import { i18n } from '@kbn/i18n';
2020
2121import { EuiSpacer , EuiButtonGroup , EuiFormRow , EuiSwitch } from '@elastic/eui' ;
2222import {
23- CATEGORICAL_DATA_TYPES ,
24- ORDINAL_DATA_TYPES ,
2523 LABEL_BORDER_SIZES ,
2624 VECTOR_STYLES ,
2725 STYLE_TYPE ,
2826 VECTOR_SHAPE_TYPE ,
2927} from '../../../../../common/constants' ;
28+ import { createStyleFieldsHelper } from '../style_fields_helper' ;
3029
3130export class VectorStyleEditor extends Component {
3231 state = {
33- dateFields : [ ] ,
34- numberFields : [ ] ,
35- fields : [ ] ,
36- ordinalAndCategoricalFields : [ ] ,
32+ styleFields : [ ] ,
3733 defaultDynamicProperties : getDefaultDynamicProperties ( ) ,
3834 defaultStaticProperties : getDefaultStaticProperties ( ) ,
3935 supportedFeatures : undefined ,
@@ -56,33 +52,17 @@ export class VectorStyleEditor extends Component {
5652 }
5753
5854 async _loadFields ( ) {
59- const getFieldMeta = async ( field ) => {
60- return {
61- label : await field . getLabel ( ) ,
62- name : field . getName ( ) ,
63- origin : field . getOrigin ( ) ,
64- type : await field . getDataType ( ) ,
65- supportsAutoDomain : field . supportsAutoDomain ( ) ,
66- } ;
67- } ;
68-
69- //These are all fields (only used for text labeling)
70- const fields = await this . props . layer . getStyleEditorFields ( ) ;
71- const fieldPromises = fields . map ( getFieldMeta ) ;
72- const fieldsArrayAll = await Promise . all ( fieldPromises ) ;
73- if ( ! this . _isMounted || _ . isEqual ( fieldsArrayAll , this . state . fields ) ) {
55+ const styleFieldsHelper = await createStyleFieldsHelper (
56+ await this . props . layer . getStyleEditorFields ( )
57+ ) ;
58+ const styleFields = styleFieldsHelper . getStyleFields ( ) ;
59+ if ( ! this . _isMounted || _ . isEqual ( styleFields , this . state . styleFields ) ) {
7460 return ;
7561 }
7662
7763 this . setState ( {
78- fields : fieldsArrayAll ,
79- ordinalAndCategoricalFields : fieldsArrayAll . filter ( ( field ) => {
80- return (
81- CATEGORICAL_DATA_TYPES . includes ( field . type ) || ORDINAL_DATA_TYPES . includes ( field . type )
82- ) ;
83- } ) ,
84- dateFields : fieldsArrayAll . filter ( ( field ) => field . type === 'date' ) ,
85- numberFields : fieldsArrayAll . filter ( ( field ) => field . type === 'number' ) ,
64+ styleFields,
65+ styleFieldsHelper,
8666 } ) ;
8767 }
8868
@@ -109,12 +89,6 @@ export class VectorStyleEditor extends Component {
10989 }
11090 }
11191
112- _getOrdinalFields ( ) {
113- return [ ...this . state . dateFields , ...this . state . numberFields ] . filter ( ( field ) => {
114- return field . supportsAutoDomain ;
115- } ) ;
116- }
117-
11892 _handleSelectedFeatureChange = ( selectedFeature ) => {
11993 this . setState ( { selectedFeature } ) ;
12094 } ;
@@ -165,7 +139,7 @@ export class VectorStyleEditor extends Component {
165139 onStaticStyleChange = { this . _onStaticStyleChange }
166140 onDynamicStyleChange = { this . _onDynamicStyleChange }
167141 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . FILL_COLOR ] }
168- fields = { this . state . ordinalAndCategoricalFields }
142+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . FILL_COLOR ) }
169143 defaultStaticStyleOptions = {
170144 this . state . defaultStaticProperties [ VECTOR_STYLES . FILL_COLOR ] . options
171145 }
@@ -186,7 +160,7 @@ export class VectorStyleEditor extends Component {
186160 onStaticStyleChange = { this . _onStaticStyleChange }
187161 onDynamicStyleChange = { this . _onDynamicStyleChange }
188162 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . LINE_COLOR ] }
189- fields = { this . state . ordinalAndCategoricalFields }
163+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . LINE_COLOR ) }
190164 defaultStaticStyleOptions = {
191165 this . state . defaultStaticProperties [ VECTOR_STYLES . LINE_COLOR ] . options
192166 }
@@ -205,7 +179,7 @@ export class VectorStyleEditor extends Component {
205179 onStaticStyleChange = { this . _onStaticStyleChange }
206180 onDynamicStyleChange = { this . _onDynamicStyleChange }
207181 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . LINE_WIDTH ] }
208- fields = { this . _getOrdinalFields ( ) }
182+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . LINE_WIDTH ) }
209183 defaultStaticStyleOptions = {
210184 this . state . defaultStaticProperties [ VECTOR_STYLES . LINE_WIDTH ] . options
211185 }
@@ -225,7 +199,7 @@ export class VectorStyleEditor extends Component {
225199 onStaticStyleChange = { this . _onStaticStyleChange }
226200 onDynamicStyleChange = { this . _onDynamicStyleChange }
227201 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . LABEL_TEXT ] }
228- fields = { this . state . fields }
202+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . LABEL_TEXT ) }
229203 defaultStaticStyleOptions = {
230204 this . state . defaultStaticProperties [ VECTOR_STYLES . LABEL_TEXT ] . options
231205 }
@@ -242,7 +216,7 @@ export class VectorStyleEditor extends Component {
242216 onStaticStyleChange = { this . _onStaticStyleChange }
243217 onDynamicStyleChange = { this . _onDynamicStyleChange }
244218 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . LABEL_COLOR ] }
245- fields = { this . state . ordinalAndCategoricalFields }
219+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . LABEL_COLOR ) }
246220 defaultStaticStyleOptions = {
247221 this . state . defaultStaticProperties [ VECTOR_STYLES . LABEL_COLOR ] . options
248222 }
@@ -258,7 +232,7 @@ export class VectorStyleEditor extends Component {
258232 onStaticStyleChange = { this . _onStaticStyleChange }
259233 onDynamicStyleChange = { this . _onDynamicStyleChange }
260234 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . LABEL_SIZE ] }
261- fields = { this . _getOrdinalFields ( ) }
235+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . LABEL_SIZE ) }
262236 defaultStaticStyleOptions = {
263237 this . state . defaultStaticProperties [ VECTOR_STYLES . LABEL_SIZE ] . options
264238 }
@@ -275,7 +249,7 @@ export class VectorStyleEditor extends Component {
275249 onStaticStyleChange = { this . _onStaticStyleChange }
276250 onDynamicStyleChange = { this . _onDynamicStyleChange }
277251 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . LABEL_BORDER_COLOR ] }
278- fields = { this . state . ordinalAndCategoricalFields }
252+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . LABEL_BORDER_COLOR ) }
279253 defaultStaticStyleOptions = {
280254 this . state . defaultStaticProperties [ VECTOR_STYLES . LABEL_BORDER_COLOR ] . options
281255 }
@@ -309,7 +283,7 @@ export class VectorStyleEditor extends Component {
309283 onStaticStyleChange = { this . _onStaticStyleChange }
310284 onDynamicStyleChange = { this . _onDynamicStyleChange }
311285 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . ICON_ORIENTATION ] }
312- fields = { this . state . numberFields }
286+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . ICON_ORIENTATION ) }
313287 defaultStaticStyleOptions = {
314288 this . state . defaultStaticProperties [ VECTOR_STYLES . ICON_ORIENTATION ] . options
315289 }
@@ -328,7 +302,7 @@ export class VectorStyleEditor extends Component {
328302 onStaticStyleChange = { this . _onStaticStyleChange }
329303 onDynamicStyleChange = { this . _onDynamicStyleChange }
330304 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . ICON ] }
331- fields = { this . state . ordinalAndCategoricalFields }
305+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . ICON ) }
332306 defaultStaticStyleOptions = {
333307 this . state . defaultStaticProperties [ VECTOR_STYLES . ICON ] . options
334308 }
@@ -368,7 +342,7 @@ export class VectorStyleEditor extends Component {
368342 onStaticStyleChange = { this . _onStaticStyleChange }
369343 onDynamicStyleChange = { this . _onDynamicStyleChange }
370344 styleProperty = { this . props . styleProperties [ VECTOR_STYLES . ICON_SIZE ] }
371- fields = { this . _getOrdinalFields ( ) }
345+ fields = { this . state . styleFieldsHelper . getFieldsForStyle ( VECTOR_STYLES . ICON_SIZE ) }
372346 defaultStaticStyleOptions = {
373347 this . state . defaultStaticProperties [ VECTOR_STYLES . ICON_SIZE ] . options
374348 }
@@ -409,9 +383,9 @@ export class VectorStyleEditor extends Component {
409383 }
410384
411385 _renderProperties ( ) {
412- const { supportedFeatures, selectedFeature } = this . state ;
386+ const { supportedFeatures, selectedFeature, styleFieldsHelper } = this . state ;
413387
414- if ( ! supportedFeatures ) {
388+ if ( ! supportedFeatures || ! styleFieldsHelper ) {
415389 return null ;
416390 }
417391
0 commit comments