Skip to content

Commit 31c2595

Browse files
[Maps] Show joins disabled message (#70826) (#71473)
Show feedback in the layer-settings when the scaling-method does not support Term-joins.
1 parent 6c51ba8 commit 31c2595

File tree

19 files changed

+383
-169
lines changed

19 files changed

+383
-169
lines changed

x-pack/plugins/maps/common/descriptor_types/data_request_descriptor_types.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
/* eslint-disable @typescript-eslint/consistent-type-definitions */
77

8-
import { RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
8+
import { RENDER_AS, SORT_ORDER, SCALING_TYPES, SOURCE_TYPES } from '../constants';
99
import { MapExtent, MapQuery } from './map_descriptor';
1010
import { Filter, TimeRange } from '../../../../../src/plugins/data/common';
1111

@@ -26,10 +26,12 @@ type ESSearchSourceSyncMeta = {
2626
scalingType: SCALING_TYPES;
2727
topHitsSplitField: string;
2828
topHitsSize: number;
29+
sourceType: SOURCE_TYPES.ES_SEARCH;
2930
};
3031

3132
type ESGeoGridSourceSyncMeta = {
3233
requestType: RENDER_AS;
34+
sourceType: SOURCE_TYPES.ES_GEO_GRID;
3335
};
3436

3537
export type VectorSourceSyncMeta = ESSearchSourceSyncMeta | ESGeoGridSourceSyncMeta | null;
@@ -51,7 +53,6 @@ export type VectorStyleRequestMeta = MapFilters & {
5153

5254
export type ESSearchSourceResponseMeta = {
5355
areResultsTrimmed?: boolean;
54-
sourceType?: string;
5556

5657
// top hits meta
5758
areEntitiesTrimmed?: boolean;

x-pack/plugins/maps/common/descriptor_types/sources.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ export type ESPewPewSourceDescriptor = AbstractESAggSourceDescriptor & {
7777
};
7878

7979
export type ESTermSourceDescriptor = AbstractESAggSourceDescriptor & {
80-
indexPatternTitle: string;
81-
term: string; // term field name
80+
indexPatternTitle?: string;
81+
term?: string; // term field name
8282
whereQuery?: Query;
8383
};
8484

@@ -138,7 +138,7 @@ export type GeojsonFileSourceDescriptor = {
138138
};
139139

140140
export type JoinDescriptor = {
141-
leftField: string;
141+
leftField?: string;
142142
right: ESTermSourceDescriptor;
143143
};
144144

x-pack/plugins/maps/public/classes/layers/blended_vector_layer/blended_vector_layer.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function getClusterStyleDescriptor(
126126
),
127127
}
128128
: undefined;
129-
// @ts-ignore
129+
// @ts-expect-error
130130
clusterStyleDescriptor.properties[styleName] = {
131131
type: STYLE_TYPE.DYNAMIC,
132132
options: {
@@ -136,7 +136,7 @@ function getClusterStyleDescriptor(
136136
};
137137
} else {
138138
// copy static styles to cluster style
139-
// @ts-ignore
139+
// @ts-expect-error
140140
clusterStyleDescriptor.properties[styleName] = {
141141
type: STYLE_TYPE.STATIC,
142142
options: { ...styleProperty.getOptions() },
@@ -192,8 +192,8 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
192192
const requestMeta = sourceDataRequest.getMeta();
193193
if (
194194
requestMeta &&
195-
requestMeta.sourceType &&
196-
requestMeta.sourceType === SOURCE_TYPES.ES_GEO_GRID
195+
requestMeta.sourceMeta &&
196+
requestMeta.sourceMeta.sourceType === SOURCE_TYPES.ES_GEO_GRID
197197
) {
198198
isClustered = true;
199199
}
@@ -220,8 +220,12 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
220220
: displayName;
221221
}
222222

223-
isJoinable() {
224-
return false;
223+
showJoinEditor() {
224+
return true;
225+
}
226+
227+
getJoinsDisabledReason() {
228+
return this._documentSource.getJoinsDisabledReason();
225229
}
226230

227231
getJoins() {

x-pack/plugins/maps/public/classes/layers/layer.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ export interface ILayer {
7878
isPreviewLayer: () => boolean;
7979
areLabelsOnTop: () => boolean;
8080
supportsLabelsOnTop: () => boolean;
81+
showJoinEditor(): boolean;
82+
getJoinsDisabledReason(): string | null;
8183
}
8284
export type Footnote = {
8385
icon: ReactElement<any>;
@@ -141,28 +143,23 @@ export class AbstractLayer implements ILayer {
141143
}
142144

143145
static getBoundDataForSource(mbMap: unknown, sourceId: string): FeatureCollection {
144-
// @ts-ignore
146+
// @ts-expect-error
145147
const mbStyle = mbMap.getStyle();
146148
return mbStyle.sources[sourceId].data;
147149
}
148150

149151
async cloneDescriptor(): Promise<LayerDescriptor> {
150-
// @ts-ignore
151152
const clonedDescriptor = copyPersistentState(this._descriptor);
152153
// layer id is uuid used to track styles/layers in mapbox
153154
clonedDescriptor.id = uuid();
154155
const displayName = await this.getDisplayName();
155156
clonedDescriptor.label = `Clone of ${displayName}`;
156157
clonedDescriptor.sourceDescriptor = this.getSource().cloneDescriptor();
157158

158-
// todo: remove this
159-
// This should not be in AbstractLayer. It relies on knowledge of VectorLayerDescriptor
160-
// @ts-ignore
161159
if (clonedDescriptor.joins) {
162-
// @ts-ignore
160+
// @ts-expect-error
163161
clonedDescriptor.joins.forEach((joinDescriptor) => {
164162
// right.id is uuid used to track requests in inspector
165-
// @ts-ignore
166163
joinDescriptor.right.id = uuid();
167164
});
168165
}
@@ -173,8 +170,12 @@ export class AbstractLayer implements ILayer {
173170
return `${this.getId()}${MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER}${layerNameSuffix}`;
174171
}
175172

176-
isJoinable(): boolean {
177-
return this.getSource().isJoinable();
173+
showJoinEditor(): boolean {
174+
return this.getSource().showJoinEditor();
175+
}
176+
177+
getJoinsDisabledReason() {
178+
return this.getSource().getJoinsDisabledReason();
178179
}
179180

180181
isPreviewLayer(): boolean {
@@ -394,7 +395,6 @@ export class AbstractLayer implements ILayer {
394395
const requestTokens = this._dataRequests.map((dataRequest) => dataRequest.getRequestToken());
395396

396397
// Compact removes all the undefineds
397-
// @ts-ignore
398398
return _.compact(requestTokens);
399399
}
400400

@@ -478,7 +478,7 @@ export class AbstractLayer implements ILayer {
478478
}
479479

480480
syncVisibilityWithMb(mbMap: unknown, mbLayerId: string) {
481-
// @ts-ignore
481+
// @ts-expect-error
482482
mbMap.setLayoutProperty(mbLayerId, 'visibility', this.isVisible() ? 'visible' : 'none');
483483
}
484484

x-pack/plugins/maps/public/classes/sources/es_geo_grid_source/es_geo_grid_source.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
6363
getSyncMeta() {
6464
return {
6565
requestType: this._descriptor.requestType,
66+
sourceType: SOURCE_TYPES.ES_GEO_GRID,
6667
};
6768
}
6869

@@ -103,7 +104,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
103104
return true;
104105
}
105106

106-
isJoinable() {
107+
showJoinEditor() {
107108
return false;
108109
}
109110

@@ -307,7 +308,6 @@ export class ESGeoGridSource extends AbstractESAggSource {
307308
},
308309
meta: {
309310
areResultsTrimmed: false,
310-
sourceType: SOURCE_TYPES.ES_GEO_GRID,
311311
},
312312
};
313313
}

x-pack/plugins/maps/public/classes/sources/es_pew_pew_source/es_pew_pew_source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class ESPewPewSource extends AbstractESAggSource {
5151
return true;
5252
}
5353

54-
isJoinable() {
54+
showJoinEditor() {
5555
return false;
5656
}
5757

x-pack/plugins/maps/public/classes/sources/es_search_source/es_search_source.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class ESSearchSource extends AbstractESSource {
385385

386386
return {
387387
data: featureCollection,
388-
meta: { ...meta, sourceType: SOURCE_TYPES.ES_SEARCH },
388+
meta,
389389
};
390390
}
391391

@@ -540,6 +540,7 @@ export class ESSearchSource extends AbstractESSource {
540540
scalingType: this._descriptor.scalingType,
541541
topHitsSplitField: this._descriptor.topHitsSplitField,
542542
topHitsSize: this._descriptor.topHitsSize,
543+
sourceType: SOURCE_TYPES.ES_SEARCH,
543544
};
544545
}
545546

@@ -551,6 +552,14 @@ export class ESSearchSource extends AbstractESSource {
551552
path: geoField.name,
552553
};
553554
}
555+
556+
getJoinsDisabledReason() {
557+
return this._descriptor.scalingType === SCALING_TYPES.CLUSTERS
558+
? i18n.translate('xpack.maps.source.esSearch.joinsDisabledReason', {
559+
defaultMessage: 'Joins are not supported when scaling by clusters',
560+
})
561+
: null;
562+
}
554563
}
555564

556565
registerSource({

x-pack/plugins/maps/public/classes/sources/source.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ export interface ISource {
5454
isESSource(): boolean;
5555
renderSourceSettingsEditor({ onChange }: SourceEditorArgs): ReactElement<any> | null;
5656
supportsFitToBounds(): Promise<boolean>;
57-
isJoinable(): boolean;
57+
showJoinEditor(): boolean;
58+
getJoinsDisabledReason(): string | null;
5859
cloneDescriptor(): SourceDescriptor;
5960
getFieldNames(): string[];
6061
getApplyGlobalQuery(): boolean;
@@ -80,7 +81,6 @@ export class AbstractSource implements ISource {
8081
destroy(): void {}
8182

8283
cloneDescriptor(): SourceDescriptor {
83-
// @ts-ignore
8484
return copyPersistentState(this._descriptor);
8585
}
8686

@@ -148,10 +148,14 @@ export class AbstractSource implements ISource {
148148
return 0;
149149
}
150150

151-
isJoinable(): boolean {
151+
showJoinEditor(): boolean {
152152
return false;
153153
}
154154

155+
getJoinsDisabledReason() {
156+
return null;
157+
}
158+
155159
isESSource(): boolean {
156160
return false;
157161
}

x-pack/plugins/maps/public/classes/sources/vector_source/vector_source.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class AbstractVectorSource extends AbstractSource {
122122
return false;
123123
}
124124

125-
isJoinable() {
125+
showJoinEditor() {
126126
return true;
127127
}
128128

x-pack/plugins/maps/public/connected_components/layer_panel/__snapshots__/view.test.js.snap

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)