Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Maps] Blended layer that switches between documents and clusters #57879

Merged
merged 38 commits into from
Mar 18, 2020
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b369b1a
[Maps] Blended layer that switches between documents and clusters
nreese Feb 13, 2020
a1d170d
change layer type when scalingType changes
nreese Feb 14, 2020
9eb460a
getSource
nreese Feb 14, 2020
3e5010d
use cluster source when count exceeds value
nreese Feb 14, 2020
ca06b90
ensure doc source stays in editor
nreese Feb 14, 2020
433d693
start creating cluster style
nreese Feb 14, 2020
6a3b194
pass all parts of style descriptor
nreese Feb 14, 2020
536e060
get toggling between sources working
nreese Feb 15, 2020
3c8e9bb
merge with master
nreese Feb 18, 2020
9a2b4d0
derive cluster style from document style
nreese Feb 19, 2020
554631c
Merge branch 'master' of github.com:elastic/kibana into scaling_type
nreese Feb 26, 2020
1eb31f7
remove references to METRIC_TYPE
nreese Feb 26, 2020
18360b4
merge with master
nreese Mar 11, 2020
5eec22b
fix import
nreese Mar 12, 2020
c215ef4
Merge branch 'master' of github.com:elastic/kibana into scaling_type
nreese Mar 12, 2020
e18c9dd
start typescripting blended_vector_layer
nreese Mar 12, 2020
4d5e928
more typescript work
nreese Mar 12, 2020
8a0e24f
last of the TS errors
nreese Mar 12, 2020
b1650f4
merge with master
nreese Mar 12, 2020
4ab5e57
Merge branch 'master' of github.com:elastic/kibana into scaling_type
nreese Mar 13, 2020
8db2894
add migration to convert useTopTerm to scalingType
nreese Mar 13, 2020
9d6faa9
clean up
nreese Mar 13, 2020
ff8129b
remove MapSavedObject work since its in a seperate PR now
nreese Mar 13, 2020
08b0fb4
fix EsSearchSource update editor jest test
nreese Mar 14, 2020
56ef685
fix map_selector jest test
nreese Mar 14, 2020
b62cdd3
Merge branch 'master' into scaling_type
elasticmachine Mar 14, 2020
b55c67d
Merge branch 'master' into scaling_type
elasticmachine Mar 16, 2020
f70c0ba
Merge branch 'master' of github.com:elastic/kibana into scaling_type
nreese Mar 17, 2020
9dcb5eb
Merge branch 'scaling_type' of github.com:nreese/kibana into scaling_…
nreese Mar 17, 2020
11615d0
move mutable state out of BlendedVectorLayer
nreese Mar 17, 2020
7c5fa30
one more change for removing mutable BlendedVectorLayer state
nreese Mar 17, 2020
6e70f51
integrate newly merged MapSavedObjectAttributes type
nreese Mar 17, 2020
deca3c3
review feedback
nreese Mar 17, 2020
1207873
use data request for fetching feature count
nreese Mar 17, 2020
41a4bff
add functional test
nreese Mar 17, 2020
fe3499f
fix functional test
nreese Mar 18, 2020
5f3236c
review feedback
nreese Mar 18, 2020
7d0dc6b
Merge branch 'master' of github.com:elastic/kibana into scaling_type
nreese Mar 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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;
};

export type DataMeta = Partial<VectorLayerRequestMeta> & Partial<ESSearchSourceResponseMeta>;
nreese marked this conversation as resolved.
Show resolved Hide resolved

export type DataRequestDescriptor = {
dataId: string;
dataMetaAtStart?: DataMeta;
dataRequestToken?: symbol;
data?: object;
dataMeta?: DataMeta;
};
13 changes: 3 additions & 10 deletions x-pack/legacy/plugins/maps/common/descriptor_types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
*/
/* eslint-disable @typescript-eslint/consistent-type-definitions */

import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER } from './constants';
import { DataRequestDescriptor } from './data_request_descriptor_types';
import { AGG_TYPE, GRID_RESOLUTION, RENDER_AS, SORT_ORDER, SCALING_TYPES } from './constants';

export type AbstractSourceDescriptor = {
id?: string;
Expand Down Expand Up @@ -49,7 +50,7 @@ export type ESSearchSourceDescriptor = AbstractESSourceDescriptor & {
tooltipProperties?: string[];
sortField?: string;
sortOrder?: SORT_ORDER;
useTopHits?: boolean;
scalingType?: SCALING_TYPES;
nreese marked this conversation as resolved.
Show resolved Hide resolved
topHitsSplitField?: string;
topHitsSize?: number;
};
Expand Down Expand Up @@ -93,14 +94,6 @@ export type JoinDescriptor = {
right: ESTermSourceDescriptor;
};

export type DataRequestDescriptor = {
dataId: string;
dataMetaAtStart: object;
dataRequestToken: symbol;
data: object;
dataMeta: object;
};

export type LayerDescriptor = {
__dataRequests?: DataRequestDescriptor[];
__isInErrorState?: boolean;
Expand Down
56 changes: 56 additions & 0 deletions x-pack/legacy/plugins/maps/common/migrations/scaling_type.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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"}}]',
});
});
});
44 changes: 44 additions & 0 deletions x-pack/legacy/plugins/maps/common/migrations/scaling_type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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';

function isEsDocumentSource(layerDescriptor: LayerDescriptor) {
const sourceType = _.get(layerDescriptor, 'sourceDescriptor.type');
return sourceType === ES_SEARCH;
}

export function migrateUseTopHitsToScalingType({
attributes,
}: {
attributes: { layerListJSON?: string; title?: string };
}) {
if (!attributes || !attributes.layerListJSON) {
return attributes;
}

const layerList: LayerDescriptor[] = JSON.parse(attributes.layerListJSON);
layerList.forEach((layerDescriptor: LayerDescriptor) => {
if (isEsDocumentSource(layerDescriptor)) {
if (_.has(layerDescriptor, 'sourceDescriptor.useTopHits')) {
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),
};
}
6 changes: 4 additions & 2 deletions x-pack/legacy/plugins/maps/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { topHitsTimeToSort } from './common/migrations/top_hits_time_to_sort';
import { moveApplyGlobalQueryToSources } from './common/migrations/move_apply_global_query';
import { addFieldMetaOptions } from './common/migrations/add_field_meta_options';
import { migrateSymbolStyleDescriptor } from './common/migrations/migrate_symbol_style_descriptor';
import { migrateUseTopHitsToScalingType } from './common/migrations/scaling_type';

export const migrations = {
map: {
Expand Down Expand Up @@ -48,11 +49,12 @@ export const migrations = {
};
},
'7.7.0': doc => {
const attributes = migrateSymbolStyleDescriptor(doc);
const attributesPhase1 = migrateSymbolStyleDescriptor(doc);
const attributesPhase2 = migrateUseTopHitsToScalingType({ attributes: attributesPhase1 });

return {
...doc,
attributes,
attributes: attributesPhase2,
};
},
},
Expand Down
3 changes: 2 additions & 1 deletion x-pack/legacy/plugins/maps/public/actions/map_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,14 @@ export function onDataLoadError(layerId, dataId, requestToken, errorMessage) {
};
}

export function updateSourceProp(layerId, propName, value) {
export function updateSourceProp(layerId, propName, value, newLayerType) {
return async dispatch => {
dispatch({
type: UPDATE_SOURCE_PROP,
layerId,
propName,
value,
newLayerType,
});
await dispatch(clearMissingStyleProperties(layerId));
dispatch(syncDataForLayer(layerId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
EuiTextColor,
EuiTextAlign,
EuiButtonEmpty,
EuiFormRow,
EuiSwitch,
} from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -80,14 +78,6 @@ export class FilterEditor extends Component {
this._close();
};

_onFilterByMapBoundsChange = event => {
this.props.updateSourceProp(
this.props.layer.getId(),
'filterByMapBounds',
event.target.checked
);
};

_onApplyGlobalQueryChange = applyGlobalQuery => {
this.props.updateSourceProp(this.props.layer.getId(), 'applyGlobalQuery', applyGlobalQuery);
};
Expand Down Expand Up @@ -182,22 +172,6 @@ export class FilterEditor extends Component {
}

render() {
let filterByBoundsSwitch;
if (this.props.layer.getSource().isFilterByMapBoundsConfigurable()) {
filterByBoundsSwitch = (
<EuiFormRow display="rowCompressed">
<EuiSwitch
label={i18n.translate('xpack.maps.filterEditor.extentFilterLabel', {
defaultMessage: 'Dynamically filter for data in the visible map area',
})}
checked={this.props.layer.getSource().isFilterByMapBounds()}
onChange={this._onFilterByMapBoundsChange}
compressed
/>
</EuiFormRow>
);
}

return (
<Fragment>
<EuiTitle size="xs">
Expand All @@ -217,8 +191,6 @@ export class FilterEditor extends Component {

<EuiSpacer size="m" />

{filterByBoundsSwitch}

<GlobalFilterCheckbox
label={i18n.translate('xpack.maps.filterEditor.applyGlobalQueryCheckboxLabel', {
defaultMessage: `Apply global filter to layer data`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ function mapDispatchToProps(dispatch) {
fitToBounds: layerId => {
dispatch(fitToLayerExtent(layerId));
},
updateSourceProp: (id, propName, value) => dispatch(updateSourceProp(id, propName, value)),
updateSourceProp: (id, propName, value, newLayerType) =>
dispatch(updateSourceProp(id, propName, value, newLayerType)),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ export class LayerPanel extends React.Component {
}
}

_onSourceChange = ({ propName, value }) => {
this.props.updateSourceProp(this.props.selectedLayer.getId(), propName, value);
_onSourceChange = ({ propName, value, newLayerType }) => {
this.props.updateSourceProp(this.props.selectedLayer.getId(), propName, value, newLayerType);
};

_renderFilterSection() {
Expand Down
Loading