Skip to content

Commit 3cbe940

Browse files
fieldify left field
1 parent 64ceb0d commit 3cbe940

File tree

8 files changed

+34
-28
lines changed

8 files changed

+34
-28
lines changed

x-pack/legacy/plugins/maps/public/layers/fields/es_doc_field.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,8 @@ export class ESDocField extends AbstractField {
1818
}
1919

2020
async createTooltipProperty(value) {
21-
try {
22-
const indexPattern = await this._source.getIndexPattern();
23-
if (!indexPattern) {
24-
return null;
25-
}
26-
return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern);
27-
} catch (e) {
28-
return null;
29-
}
21+
const indexPattern = await this._source.getIndexPattern();
22+
return new ESTooltipProperty(this.getName(), this.getName(), value, indexPattern);
3023
}
3124

3225
async getType() {

x-pack/legacy/plugins/maps/public/layers/joins/inner_join.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ import { VectorStyle } from '../styles/vector_style';
1010

1111
export class InnerJoin {
1212

13-
constructor(joinDescriptor, inspectorAdapters) {
13+
constructor(joinDescriptor, leftSource) {
1414
this._descriptor = joinDescriptor;
15+
const inspectorAdapters = leftSource.getInspectorAdapters();
1516
this._rightSource = new ESTermSource(joinDescriptor.right, inspectorAdapters);
17+
this._leftField = this._descriptor.leftField ? leftSource.createField(joinDescriptor.leftField) : null;
1618
}
1719

1820
destroy() {
1921
this._rightSource.destroy();
2022
}
2123

2224
hasCompleteConfig() {
23-
if (this._descriptor.leftField && this._rightSource) {
25+
if (this._leftField && this._rightSource) {
2426
return this._rightSource.hasCompleteConfig();
2527
}
2628

@@ -45,7 +47,7 @@ export class InnerJoin {
4547
}
4648

4749
getLeftFieldName() {
48-
return this._descriptor.leftField;
50+
return this._leftField ? this._leftField.getName() : null;
4951
}
5052

5153
joinPropertiesToFeature(feature, propertiesMap, rightMetricFields) {
@@ -64,7 +66,7 @@ export class InnerJoin {
6466
});
6567
}
6668

67-
const joinKey = feature.properties[this._descriptor.leftField];
69+
const joinKey = feature.properties[this._leftField.getName()];
6870
const coercedKey = typeof joinKey === 'undefined' || joinKey === null ? null : joinKey.toString();
6971
if (propertiesMap && coercedKey !== null && propertiesMap.has(coercedKey)) {
7072
Object.assign(feature.properties, propertiesMap.get(coercedKey));

x-pack/legacy/plugins/maps/public/layers/sources/ems_file_source/ems_file_source.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ export class EMSFileSource extends AbstractVectorSource {
4545

4646
constructor(descriptor, inspectorAdapters) {
4747
super(EMSFileSource.createDescriptor(descriptor), inspectorAdapters);
48-
this._tooltipFields = this._descriptor.tooltipProperties.map(propertyKey => {
49-
return new EMSRegionLayerField({
50-
fieldName: propertyKey,
51-
source: this
52-
});
48+
this._tooltipFields = this._descriptor.tooltipProperties.map(propertyKey => this.createField(propertyKey));
49+
}
50+
51+
createField(fieldName) {
52+
return new EMSRegionLayerField({
53+
fieldName,
54+
source: this
5355
});
5456
}
5557

x-pack/legacy/plugins/maps/public/layers/sources/es_search_source/es_search_source.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ export class ESSearchSource extends AbstractESSource {
6868
topHitsSize: _.get(descriptor, 'topHitsSize', 1),
6969
}, inspectorAdapters);
7070

71-
this._tooltipFields = this._descriptor.tooltipProperties.map((property) => {
72-
return new ESDocField({
73-
fieldName: property,
74-
source: this
75-
});
71+
this._tooltipFields = this._descriptor.tooltipProperties.map((property) => this.createField(property));
72+
}
73+
74+
createField(fieldName) {
75+
return new ESDocField({
76+
fieldName,
77+
source: this
7678
});
7779
}
7880

x-pack/legacy/plugins/maps/public/layers/sources/es_source.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,4 +329,8 @@ export class AbstractESSource extends AbstractVectorSource {
329329

330330
return fieldFromIndexPattern.format.getConverterFor('text');
331331
}
332+
333+
createField() {
334+
throw new Error('Child must implement Source#createField');
335+
}
332336
}

x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import { AbstractESSource } from './es_source';
1010
import { Schemas } from 'ui/vis/editors/default/schemas';
1111
import { AggConfigs } from 'ui/agg_types';
1212
import { i18n } from '@kbn/i18n';
13-
import { ESTooltipProperty } from '../tooltips/es_tooltip_property';
1413
import { ES_SIZE_LIMIT } from '../../../common/constants';
1514
import { ESDocField } from '../fields/es_doc_field';
1615

x-pack/legacy/plugins/maps/public/layers/tooltips/join_tooltip_property.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ export class JoinTooltipProperty extends TooltipProperty {
3939
for (let i = 0; i < this._leftInnerJoins.length; i++) {
4040
const rightSource = this._leftInnerJoins[i].getRightJoinSource();
4141
const termField = rightSource.getTermField();
42-
const esTooltipProperty = await termField.createTooltipProperty(this._tooltipProperty.getRawValue());
43-
if (esTooltipProperty) {
44-
esFilters.push(...(await esTooltipProperty.getESFilters()));
42+
try {
43+
const esTooltipProperty = await termField.createTooltipProperty(this._tooltipProperty.getRawValue());
44+
if (esTooltipProperty) {
45+
esFilters.push(...(await esTooltipProperty.getESFilters()));
46+
}
47+
} catch(e) {
48+
console.error('Cannot create joined filter', e);
4549
}
4650
}
4751

x-pack/legacy/plugins/maps/public/layers/vector_layer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export class VectorLayer extends AbstractLayer {
9191
this._joins = [];
9292
if (options.layerDescriptor.joins) {
9393
options.layerDescriptor.joins.forEach((joinDescriptor) => {
94-
const join = new InnerJoin(joinDescriptor, this._source.getInspectorAdapters());
94+
const join = new InnerJoin(joinDescriptor, this._source);
9595
this._joins.push(join);
9696
});
9797
}

0 commit comments

Comments
 (0)