-
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.
Merge branch 'master' into enhancement/update-esdocs-datasource
- Loading branch information
Showing
70 changed files
with
3,076 additions
and
545 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.