-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] Blended layer that switches between documents and clusters (#5…
…7879) (#60550) * [Maps] Blended layer that switches between documents and clusters * change layer type when scalingType changes * getSource * use cluster source when count exceeds value * ensure doc source stays in editor * start creating cluster style * pass all parts of style descriptor * get toggling between sources working * derive cluster style from document style * remove references to METRIC_TYPE * fix import * start typescripting blended_vector_layer * more typescript work * last of the TS errors * add migration to convert useTopTerm to scalingType * clean up * remove MapSavedObject work since its in a seperate PR now * fix EsSearchSource update editor jest test * fix map_selector jest test * move mutable state out of BlendedVectorLayer * one more change for removing mutable BlendedVectorLayer state * integrate newly merged MapSavedObjectAttributes type * review feedback * use data request for fetching feature count * add functional test * fix functional test * review feedback Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
e207703
commit 20396c1
Showing
49 changed files
with
1,214 additions
and
284 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
x-pack/legacy/plugins/maps/common/data_request_descriptor_types.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* 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. | ||
*/ | ||
/* eslint-disable @typescript-eslint/consistent-type-definitions */ | ||
|
||
// Global map state passed to every layer. | ||
export type MapFilters = { | ||
buffer: unknown; | ||
extent: unknown; | ||
filters: unknown[]; | ||
query: unknown; | ||
refreshTimerLastTriggeredAt: string; | ||
timeFilters: unknown; | ||
zoom: number; | ||
}; | ||
|
||
export type VectorLayerRequestMeta = MapFilters & { | ||
applyGlobalQuery: boolean; | ||
fieldNames: string[]; | ||
geogridPrecision: number; | ||
sourceQuery: unknown; | ||
sourceMeta: unknown; | ||
}; | ||
|
||
export type ESSearchSourceResponseMeta = { | ||
areResultsTrimmed?: boolean; | ||
sourceType?: string; | ||
|
||
// top hits meta | ||
areEntitiesTrimmed?: boolean; | ||
entityCount?: number; | ||
totalEntities?: number; | ||
}; | ||
|
||
// Partial because objects are justified downstream in constructors | ||
export type DataMeta = Partial<VectorLayerRequestMeta> & Partial<ESSearchSourceResponseMeta>; | ||
|
||
export type DataRequestDescriptor = { | ||
dataId: string; | ||
dataMetaAtStart?: DataMeta; | ||
dataRequestToken?: symbol; | ||
data?: object; | ||
dataMeta?: DataMeta; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
x-pack/legacy/plugins/maps/common/migrations/scaling_type.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* 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 { migrateUseTopHitsToScalingType } from './scaling_type'; | ||
|
||
describe('migrateUseTopHitsToScalingType', () => { | ||
test('Should handle missing layerListJSON attribute', () => { | ||
const attributes = { | ||
title: 'my map', | ||
}; | ||
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({ | ||
title: 'my map', | ||
}); | ||
}); | ||
|
||
test('Should migrate useTopHits: true to scalingType TOP_HITS for ES documents sources', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
sourceDescriptor: { | ||
type: 'ES_SEARCH', | ||
useTopHits: true, | ||
}, | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"sourceDescriptor":{"type":"ES_SEARCH","scalingType":"TOP_HITS"}}]', | ||
}); | ||
}); | ||
|
||
test('Should migrate useTopHits: false to scalingType LIMIT for ES documents sources', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
sourceDescriptor: { | ||
type: 'ES_SEARCH', | ||
useTopHits: false, | ||
}, | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"sourceDescriptor":{"type":"ES_SEARCH","scalingType":"LIMIT"}}]', | ||
}); | ||
}); | ||
|
||
test('Should set scalingType to LIMIT when useTopHits is not set', () => { | ||
const layerListJSON = JSON.stringify([ | ||
{ | ||
sourceDescriptor: { | ||
type: 'ES_SEARCH', | ||
}, | ||
}, | ||
]); | ||
const attributes = { | ||
title: 'my map', | ||
layerListJSON, | ||
}; | ||
expect(migrateUseTopHitsToScalingType({ attributes })).toEqual({ | ||
title: 'my map', | ||
layerListJSON: '[{"sourceDescriptor":{"type":"ES_SEARCH","scalingType":"LIMIT"}}]', | ||
}); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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 _ from 'lodash'; | ||
import { ES_SEARCH, SCALING_TYPES } from '../constants'; | ||
import { LayerDescriptor, ESSearchSourceDescriptor } from '../descriptor_types'; | ||
import { MapSavedObjectAttributes } from '../../../../../plugins/maps/common/map_saved_object_type'; | ||
|
||
function isEsDocumentSource(layerDescriptor: LayerDescriptor) { | ||
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type'); | ||
return sourceType === ES_SEARCH; | ||
} | ||
|
||
export function migrateUseTopHitsToScalingType({ | ||
attributes, | ||
}: { | ||
attributes: MapSavedObjectAttributes; | ||
}): MapSavedObjectAttributes { | ||
if (!attributes || !attributes.layerListJSON) { | ||
return attributes; | ||
} | ||
|
||
const layerList: LayerDescriptor[] = JSON.parse(attributes.layerListJSON); | ||
layerList.forEach((layerDescriptor: LayerDescriptor) => { | ||
if (isEsDocumentSource(layerDescriptor)) { | ||
const sourceDescriptor = layerDescriptor.sourceDescriptor as ESSearchSourceDescriptor; | ||
sourceDescriptor.scalingType = _.get(layerDescriptor, 'sourceDescriptor.useTopHits', false) | ||
? SCALING_TYPES.TOP_HITS | ||
: SCALING_TYPES.LIMIT; | ||
// @ts-ignore useTopHits no longer in type definition but that does not mean its not in live data | ||
// hence the entire point of this method | ||
delete sourceDescriptor.useTopHits; | ||
} | ||
}); | ||
|
||
return { | ||
...attributes, | ||
layerListJSON: JSON.stringify(layerList), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
x-pack/legacy/plugins/maps/public/actions/map_actions.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
* 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. | ||
*/ | ||
/* eslint-disable @typescript-eslint/consistent-type-definitions */ | ||
|
||
import { DataMeta, MapFilters } from '../../common/data_request_descriptor_types'; | ||
|
||
export type SyncContext = { | ||
startLoading(dataId: string, requestToken: symbol, meta: DataMeta): void; | ||
stopLoading(dataId: string, requestToken: symbol, data: unknown, meta: DataMeta): void; | ||
onLoadError(dataId: string, requestToken: symbol, errorMessage: string): void; | ||
updateSourceData(newData: unknown): void; | ||
isRequestStillActive(dataId: string, requestToken: symbol): boolean; | ||
registerCancelCallback(requestToken: symbol, callback: () => void): void; | ||
dataFilters: MapFilters; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.