mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[Maps] fix cloned clustered documents layer returns error (#72975)
* [Maps] fix cloned clustered documents layer returns error * tslint
This commit is contained in:
parent
7d51b97806
commit
e1a3dccf03
2 changed files with 165 additions and 1 deletions
|
@ -0,0 +1,150 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { SCALING_TYPES, SOURCE_TYPES } from '../../../../common/constants';
|
||||
import { BlendedVectorLayer } from './blended_vector_layer';
|
||||
// @ts-expect-error
|
||||
import { ESSearchSource } from '../../sources/es_search_source';
|
||||
import { ESGeoGridSourceDescriptor } from '../../../../common/descriptor_types';
|
||||
|
||||
jest.mock('../../../kibana_services', () => {
|
||||
return {
|
||||
getIsDarkMode() {
|
||||
return false;
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const mapColors: string[] = [];
|
||||
|
||||
const notClusteredDataRequest = {
|
||||
data: { isSyncClustered: false },
|
||||
dataId: 'ACTIVE_COUNT_DATA_ID',
|
||||
};
|
||||
|
||||
const clusteredDataRequest = {
|
||||
data: { isSyncClustered: true },
|
||||
dataId: 'ACTIVE_COUNT_DATA_ID',
|
||||
};
|
||||
|
||||
const documentSourceDescriptor = ESSearchSource.createDescriptor({
|
||||
geoField: 'myGeoField',
|
||||
indexPatternId: 'myIndexPattern',
|
||||
scalingType: SCALING_TYPES.CLUSTERS,
|
||||
});
|
||||
|
||||
describe('getSource', () => {
|
||||
describe('isClustered: true', () => {
|
||||
test('should return cluster source', async () => {
|
||||
const blendedVectorLayer = new BlendedVectorLayer({
|
||||
source: new ESSearchSource(documentSourceDescriptor),
|
||||
layerDescriptor: BlendedVectorLayer.createDescriptor(
|
||||
{
|
||||
sourceDescriptor: documentSourceDescriptor,
|
||||
__dataRequests: [clusteredDataRequest],
|
||||
},
|
||||
mapColors
|
||||
),
|
||||
});
|
||||
|
||||
const source = blendedVectorLayer.getSource();
|
||||
expect(source.cloneDescriptor().type).toBe(SOURCE_TYPES.ES_GEO_GRID);
|
||||
});
|
||||
|
||||
test('cluster source applyGlobalQuery should be true when document source applyGlobalQuery is true', async () => {
|
||||
const blendedVectorLayer = new BlendedVectorLayer({
|
||||
source: new ESSearchSource(documentSourceDescriptor),
|
||||
layerDescriptor: BlendedVectorLayer.createDescriptor(
|
||||
{
|
||||
sourceDescriptor: documentSourceDescriptor,
|
||||
__dataRequests: [clusteredDataRequest],
|
||||
},
|
||||
mapColors
|
||||
),
|
||||
});
|
||||
|
||||
const source = blendedVectorLayer.getSource();
|
||||
expect((source.cloneDescriptor() as ESGeoGridSourceDescriptor).applyGlobalQuery).toBe(true);
|
||||
});
|
||||
|
||||
test('cluster source applyGlobalQuery should be false when document source applyGlobalQuery is false', async () => {
|
||||
const blendedVectorLayer = new BlendedVectorLayer({
|
||||
source: new ESSearchSource({
|
||||
...documentSourceDescriptor,
|
||||
applyGlobalQuery: false,
|
||||
}),
|
||||
layerDescriptor: BlendedVectorLayer.createDescriptor(
|
||||
{
|
||||
sourceDescriptor: documentSourceDescriptor,
|
||||
__dataRequests: [clusteredDataRequest],
|
||||
},
|
||||
mapColors
|
||||
),
|
||||
});
|
||||
|
||||
const source = blendedVectorLayer.getSource();
|
||||
expect((source.cloneDescriptor() as ESGeoGridSourceDescriptor).applyGlobalQuery).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isClustered: false', () => {
|
||||
test('should return document source', async () => {
|
||||
const blendedVectorLayer = new BlendedVectorLayer({
|
||||
source: new ESSearchSource(documentSourceDescriptor),
|
||||
layerDescriptor: BlendedVectorLayer.createDescriptor(
|
||||
{
|
||||
sourceDescriptor: documentSourceDescriptor,
|
||||
__dataRequests: [notClusteredDataRequest],
|
||||
},
|
||||
mapColors
|
||||
),
|
||||
});
|
||||
|
||||
const source = blendedVectorLayer.getSource();
|
||||
expect(source.cloneDescriptor().type).toBe(SOURCE_TYPES.ES_SEARCH);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('cloneDescriptor', () => {
|
||||
describe('isClustered: true', () => {
|
||||
test('Cloned layer descriptor sourceDescriptor should be document source', async () => {
|
||||
const blendedVectorLayer = new BlendedVectorLayer({
|
||||
source: new ESSearchSource(documentSourceDescriptor),
|
||||
layerDescriptor: BlendedVectorLayer.createDescriptor(
|
||||
{
|
||||
sourceDescriptor: documentSourceDescriptor,
|
||||
__dataRequests: [clusteredDataRequest],
|
||||
},
|
||||
mapColors
|
||||
),
|
||||
});
|
||||
|
||||
const clonedLayerDescriptor = await blendedVectorLayer.cloneDescriptor();
|
||||
expect(clonedLayerDescriptor.sourceDescriptor!.type).toBe(SOURCE_TYPES.ES_SEARCH);
|
||||
expect(clonedLayerDescriptor.label).toBe('Clone of myIndexPattern');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isClustered: false', () => {
|
||||
test('Cloned layer descriptor sourceDescriptor should be document source', async () => {
|
||||
const blendedVectorLayer = new BlendedVectorLayer({
|
||||
source: new ESSearchSource(documentSourceDescriptor),
|
||||
layerDescriptor: BlendedVectorLayer.createDescriptor(
|
||||
{
|
||||
sourceDescriptor: documentSourceDescriptor,
|
||||
__dataRequests: [notClusteredDataRequest],
|
||||
},
|
||||
mapColors
|
||||
),
|
||||
});
|
||||
|
||||
const clonedLayerDescriptor = await blendedVectorLayer.cloneDescriptor();
|
||||
expect(clonedLayerDescriptor.sourceDescriptor!.type).toBe(SOURCE_TYPES.ES_SEARCH);
|
||||
expect(clonedLayerDescriptor.label).toBe('Clone of myIndexPattern');
|
||||
});
|
||||
});
|
||||
});
|
|
@ -34,6 +34,7 @@ import {
|
|||
SizeDynamicOptions,
|
||||
DynamicStylePropertyOptions,
|
||||
StylePropertyOptions,
|
||||
LayerDescriptor,
|
||||
VectorLayerDescriptor,
|
||||
} from '../../../../common/descriptor_types';
|
||||
import { IStyle } from '../../styles/style';
|
||||
|
@ -216,7 +217,7 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
|
|||
}
|
||||
}
|
||||
|
||||
async getDisplayName(source: ISource) {
|
||||
async getDisplayName(source?: ISource) {
|
||||
const displayName = await super.getDisplayName(source);
|
||||
return this._isClustered
|
||||
? i18n.translate('xpack.maps.blendedVectorLayer.clusteredLayerName', {
|
||||
|
@ -242,6 +243,19 @@ export class BlendedVectorLayer extends VectorLayer implements IVectorLayer {
|
|||
return false;
|
||||
}
|
||||
|
||||
async cloneDescriptor(): Promise<LayerDescriptor> {
|
||||
const clonedDescriptor = await super.cloneDescriptor();
|
||||
|
||||
// Use super getDisplayName instead of instance getDisplayName to avoid getting 'Clustered Clone of Clustered'
|
||||
const displayName = await super.getDisplayName();
|
||||
clonedDescriptor.label = `Clone of ${displayName}`;
|
||||
|
||||
// sourceDescriptor must be document source descriptor
|
||||
clonedDescriptor.sourceDescriptor = this._documentSource.cloneDescriptor();
|
||||
|
||||
return clonedDescriptor;
|
||||
}
|
||||
|
||||
getSource() {
|
||||
return this._isClustered ? this._clusterSource : this._documentSource;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue