Skip to content

Commit

Permalink
[Maps] Show joins disabled message (#70826) (#71473)
Browse files Browse the repository at this point in the history
Show feedback in the layer-settings when the scaling-method does not support Term-joins.
  • Loading branch information
thomasneirynck authored Jul 13, 2020
1 parent 6c51ba8 commit 31c2595
Show file tree
Hide file tree
Showing 19 changed files with 383 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { RENDER_AS, SORT_ORDER, SCALING_TYPES } from '../constants';
import { RENDER_AS, SORT_ORDER, SCALING_TYPES, SOURCE_TYPES } from '../constants';
import { MapExtent, MapQuery } from './map_descriptor';
import { Filter, TimeRange } from '../../../../../src/plugins/data/common';

Expand All @@ -26,10 +26,12 @@ type ESSearchSourceSyncMeta = {
scalingType: SCALING_TYPES;
topHitsSplitField: string;
topHitsSize: number;
sourceType: SOURCE_TYPES.ES_SEARCH;
};

type ESGeoGridSourceSyncMeta = {
requestType: RENDER_AS;
sourceType: SOURCE_TYPES.ES_GEO_GRID;
};

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

export type ESSearchSourceResponseMeta = {
areResultsTrimmed?: boolean;
sourceType?: string;

// top hits meta
areEntitiesTrimmed?: boolean;
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/maps/common/descriptor_types/sources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export type ESPewPewSourceDescriptor = AbstractESAggSourceDescriptor & {
};

export type ESTermSourceDescriptor = AbstractESAggSourceDescriptor & {
indexPatternTitle: string;
term: string; // term field name
indexPatternTitle?: string;
term?: string; // term field name
whereQuery?: Query;
};

Expand Down Expand Up @@ -138,7 +138,7 @@ export type GeojsonFileSourceDescriptor = {
};

export type JoinDescriptor = {
leftField: string;
leftField?: string;
right: ESTermSourceDescriptor;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function getClusterStyleDescriptor(
),
}
: undefined;
// @ts-ignore
// @ts-expect-error
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.DYNAMIC,
options: {
Expand All @@ -136,7 +136,7 @@ function getClusterStyleDescriptor(
};
} else {
// copy static styles to cluster style
// @ts-ignore
// @ts-expect-error
clusterStyleDescriptor.properties[styleName] = {
type: STYLE_TYPE.STATIC,
options: { ...styleProperty.getOptions() },
Expand Down Expand Up @@ -192,8 +192,8 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
const requestMeta = sourceDataRequest.getMeta();
if (
requestMeta &&
requestMeta.sourceType &&
requestMeta.sourceType === SOURCE_TYPES.ES_GEO_GRID
requestMeta.sourceMeta &&
requestMeta.sourceMeta.sourceType === SOURCE_TYPES.ES_GEO_GRID
) {
isClustered = true;
}
Expand All @@ -220,8 +220,12 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
: displayName;
}

isJoinable() {
return false;
showJoinEditor() {
return true;
}

getJoinsDisabledReason() {
return this._documentSource.getJoinsDisabledReason();
}

getJoins() {
Expand Down
22 changes: 11 additions & 11 deletions x-pack/plugins/maps/public/classes/layers/layer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export interface ILayer {
isPreviewLayer: () => boolean;
areLabelsOnTop: () => boolean;
supportsLabelsOnTop: () => boolean;
showJoinEditor(): boolean;
getJoinsDisabledReason(): string | null;
}
export type Footnote = {
icon: ReactElement<any>;
Expand Down Expand Up @@ -141,28 +143,23 @@ export class AbstractLayer implements ILayer {
}

static getBoundDataForSource(mbMap: unknown, sourceId: string): FeatureCollection {
// @ts-ignore
// @ts-expect-error
const mbStyle = mbMap.getStyle();
return mbStyle.sources[sourceId].data;
}

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

// todo: remove this
// This should not be in AbstractLayer. It relies on knowledge of VectorLayerDescriptor
// @ts-ignore
if (clonedDescriptor.joins) {
// @ts-ignore
// @ts-expect-error
clonedDescriptor.joins.forEach((joinDescriptor) => {
// right.id is uuid used to track requests in inspector
// @ts-ignore
joinDescriptor.right.id = uuid();
});
}
Expand All @@ -173,8 +170,12 @@ export class AbstractLayer implements ILayer {
return `${this.getId()}${MB_SOURCE_ID_LAYER_ID_PREFIX_DELIMITER}${layerNameSuffix}`;
}

isJoinable(): boolean {
return this.getSource().isJoinable();
showJoinEditor(): boolean {
return this.getSource().showJoinEditor();
}

getJoinsDisabledReason() {
return this.getSource().getJoinsDisabledReason();
}

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

// Compact removes all the undefineds
// @ts-ignore
return _.compact(requestTokens);
}

Expand Down Expand Up @@ -478,7 +478,7 @@ export class AbstractLayer implements ILayer {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
getSyncMeta() {
return {
requestType: this._descriptor.requestType,
sourceType: SOURCE_TYPES.ES_GEO_GRID,
};
}

Expand Down Expand Up @@ -103,7 +104,7 @@ export class ESGeoGridSource extends AbstractESAggSource {
return true;
}

isJoinable() {
showJoinEditor() {
return false;
}

Expand Down Expand Up @@ -307,7 +308,6 @@ export class ESGeoGridSource extends AbstractESAggSource {
},
meta: {
areResultsTrimmed: false,
sourceType: SOURCE_TYPES.ES_GEO_GRID,
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class ESPewPewSource extends AbstractESAggSource {
return true;
}

isJoinable() {
showJoinEditor() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ export class ESSearchSource extends AbstractESSource {

return {
data: featureCollection,
meta: { ...meta, sourceType: SOURCE_TYPES.ES_SEARCH },
meta,
};
}

Expand Down Expand Up @@ -540,6 +540,7 @@ export class ESSearchSource extends AbstractESSource {
scalingType: this._descriptor.scalingType,
topHitsSplitField: this._descriptor.topHitsSplitField,
topHitsSize: this._descriptor.topHitsSize,
sourceType: SOURCE_TYPES.ES_SEARCH,
};
}

Expand All @@ -551,6 +552,14 @@ export class ESSearchSource extends AbstractESSource {
path: geoField.name,
};
}

getJoinsDisabledReason() {
return this._descriptor.scalingType === SCALING_TYPES.CLUSTERS
? i18n.translate('xpack.maps.source.esSearch.joinsDisabledReason', {
defaultMessage: 'Joins are not supported when scaling by clusters',
})
: null;
}
}

registerSource({
Expand Down
10 changes: 7 additions & 3 deletions x-pack/plugins/maps/public/classes/sources/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export interface ISource {
isESSource(): boolean;
renderSourceSettingsEditor({ onChange }: SourceEditorArgs): ReactElement<any> | null;
supportsFitToBounds(): Promise<boolean>;
isJoinable(): boolean;
showJoinEditor(): boolean;
getJoinsDisabledReason(): string | null;
cloneDescriptor(): SourceDescriptor;
getFieldNames(): string[];
getApplyGlobalQuery(): boolean;
Expand All @@ -80,7 +81,6 @@ export class AbstractSource implements ISource {
destroy(): void {}

cloneDescriptor(): SourceDescriptor {
// @ts-ignore
return copyPersistentState(this._descriptor);
}

Expand Down Expand Up @@ -148,10 +148,14 @@ export class AbstractSource implements ISource {
return 0;
}

isJoinable(): boolean {
showJoinEditor(): boolean {
return false;
}

getJoinsDisabledReason() {
return null;
}

isESSource(): boolean {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export class AbstractVectorSource extends AbstractSource {
return false;
}

isJoinable() {
showJoinEditor() {
return true;
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { updateSourceProp } from '../../actions';
function mapStateToProps(state = {}) {
const selectedLayer = getSelectedLayer(state);
return {
key: selectedLayer ? `${selectedLayer.getId()}${selectedLayer.isJoinable()}` : '',
key: selectedLayer ? `${selectedLayer.getId()}${selectedLayer.showJoinEditor()}` : '',
selectedLayer,
};
}
Expand Down
Loading

0 comments on commit 31c2595

Please sign in to comment.