Skip to content

Commit 53b208e

Browse files
shahzad31andrewvc
authored andcommitted
[UX] Fix map color variance and apply proper filter for extended stats (#81106)
Fixes: #81208 correctly coloring the UX map
1 parent 633dc4f commit 53b208e

6 files changed

Lines changed: 61 additions & 22 deletions

File tree

x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/EmbeddedMap.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
ViewMode,
2121
isErrorEmbeddable,
2222
} from '../../../../../../../../src/plugins/embeddable/public';
23-
import { getLayerList } from './LayerList';
23+
import { useLayerList } from './useLayerList';
2424
import { useUrlParams } from '../../../../hooks/useUrlParams';
2525
import { RenderTooltipContentParams } from '../../../../../../maps/public';
2626
import { MapToolTip } from './MapToolTip';
@@ -55,6 +55,8 @@ export function EmbeddedMapComponent() {
5555

5656
const mapFilters = useMapFilters();
5757

58+
const layerList = useLayerList();
59+
5860
const [embeddable, setEmbeddable] = useState<
5961
MapEmbeddable | ErrorEmbeddable | undefined
6062
>();
@@ -148,7 +150,7 @@ export function EmbeddedMapComponent() {
148150

149151
if (embeddableObject && !isErrorEmbeddable(embeddableObject)) {
150152
embeddableObject.setRenderTooltipContent(renderTooltipContent);
151-
await embeddableObject.setLayerList(getLayerList());
153+
await embeddableObject.setLayerList(layerList);
152154
}
153155

154156
setEmbeddable(embeddableObject);

x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/MapToolTip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
REGION_NAME,
1919
TRANSACTION_DURATION_COUNTRY,
2020
TRANSACTION_DURATION_REGION,
21-
} from './LayerList';
21+
} from './useLayerList';
2222
import { RenderTooltipContentParams } from '../../../../../../maps/public';
2323
import { I18LABELS } from '../translations';
2424

x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__stories__/MapTooltip.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { storiesOf } from '@storybook/react';
88
import React from 'react';
99
import { EuiThemeProvider } from '../../../../../../../observability/public';
1010
import { MapToolTip } from '../MapToolTip';
11-
import { COUNTRY_NAME, TRANSACTION_DURATION_COUNTRY } from '../LayerList';
11+
import { COUNTRY_NAME, TRANSACTION_DURATION_COUNTRY } from '../useLayerList';
1212

1313
storiesOf('app/RumDashboard/VisitorsRegionMap', module)
1414
.addDecorator((storyFn) => <EuiThemeProvider>{storyFn()}</EuiThemeProvider>)

x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__tests__/__mocks__/regions_layer.mock.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ export const mockLayerList = [
2525
id: '3657625d-17b0-41ef-99ba-3a2b2938655c',
2626
indexPatternTitle: 'apm-*',
2727
term: 'client.geo.country_iso_code',
28+
whereQuery: {
29+
language: 'kuery',
30+
query:
31+
'transaction.type : "page-load" and service.name : "undefined"',
32+
},
2833
metrics: [
2934
{
3035
type: 'avg',
@@ -95,6 +100,11 @@ export const mockLayerList = [
95100
id: 'e62a1b9c-d7ff-4fd4-a0f6-0fdc44bb9e41',
96101
indexPatternTitle: 'apm-*',
97102
term: 'client.geo.region_iso_code',
103+
whereQuery: {
104+
language: 'kuery',
105+
query:
106+
'transaction.type : "page-load" and service.name : "undefined"',
107+
},
98108
metrics: [{ type: 'avg', field: 'transaction.duration.us' }],
99109
indexPatternId: 'apm_static_index_pattern_id',
100110
},

x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__tests__/LayerList.test.ts renamed to x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/__tests__/useLayerList.test.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { renderHook } from '@testing-library/react-hooks';
78
import { mockLayerList } from './__mocks__/regions_layer.mock';
8-
import { getLayerList } from '../LayerList';
9+
import { useLayerList } from '../useLayerList';
910

10-
describe('LayerList', () => {
11-
describe('getLayerList', () => {
12-
test('it returns the region layer', () => {
13-
const layerList = getLayerList();
14-
expect(layerList).toStrictEqual(mockLayerList);
15-
});
11+
describe('useLayerList', () => {
12+
test('it returns the region layer', () => {
13+
const { result } = renderHook(() => useLayerList());
14+
expect(result.current).toStrictEqual(mockLayerList);
1615
});
1716
});

x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/LayerList.ts renamed to x-pack/plugins/apm/public/components/app/RumDashboard/VisitorBreakdownMap/useLayerList.ts

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,14 @@ import {
2222
} from '../../../../../../maps/common/constants';
2323

2424
import { APM_STATIC_INDEX_PATTERN_ID } from '../../../../../../../../src/plugins/apm_oss/public';
25+
import { useUrlParams } from '../../../../hooks/useUrlParams';
26+
import {
27+
SERVICE_NAME,
28+
TRANSACTION_TYPE,
29+
} from '../../../../../common/elasticsearch_fieldnames';
30+
import { TRANSACTION_PAGE_LOAD } from '../../../../../common/transaction_types';
2531

26-
const ES_TERM_SOURCE: ESTermSourceDescriptor = {
32+
const ES_TERM_SOURCE_COUNTRY: ESTermSourceDescriptor = {
2733
type: 'ES_TERM_SOURCE',
2834
id: '3657625d-17b0-41ef-99ba-3a2b2938655c',
2935
indexPatternTitle: 'apm-*',
@@ -39,6 +45,26 @@ const ES_TERM_SOURCE: ESTermSourceDescriptor = {
3945
applyGlobalQuery: true,
4046
};
4147

48+
const ES_TERM_SOURCE_REGION: ESTermSourceDescriptor = {
49+
type: 'ES_TERM_SOURCE',
50+
id: 'e62a1b9c-d7ff-4fd4-a0f6-0fdc44bb9e41',
51+
indexPatternTitle: 'apm-*',
52+
term: 'client.geo.region_iso_code',
53+
metrics: [{ type: AGG_TYPE.AVG, field: 'transaction.duration.us' }],
54+
whereQuery: {
55+
query: 'transaction.type : "page-load"',
56+
language: 'kuery',
57+
},
58+
indexPatternId: APM_STATIC_INDEX_PATTERN_ID,
59+
};
60+
61+
const getWhereQuery = (serviceName: string) => {
62+
return {
63+
query: `${TRANSACTION_TYPE} : "${TRANSACTION_PAGE_LOAD}" and ${SERVICE_NAME} : "${serviceName}"`,
64+
language: 'kuery',
65+
};
66+
};
67+
4268
export const REGION_NAME = 'region_name';
4369
export const COUNTRY_NAME = 'name';
4470

@@ -56,7 +82,11 @@ interface VectorLayerDescriptor extends BaseVectorLayerDescriptor {
5682
sourceDescriptor: EMSFileSourceDescriptor;
5783
}
5884

59-
export function getLayerList() {
85+
export function useLayerList() {
86+
const { urlParams } = useUrlParams();
87+
88+
const { serviceName } = urlParams;
89+
6090
const baseLayer: LayerDescriptor = {
6191
sourceDescriptor: { type: 'EMS_TMS', isAutoSelect: true },
6292
id: 'b7af286d-2580-4f47-be93-9653d594ce7e',
@@ -69,6 +99,8 @@ export function getLayerList() {
6999
type: 'VECTOR_TILE',
70100
};
71101

102+
ES_TERM_SOURCE_COUNTRY.whereQuery = getWhereQuery(serviceName!);
103+
72104
const getLayerStyle = (fieldName: string): VectorStyleDescriptor => {
73105
return {
74106
type: 'VECTOR',
@@ -119,7 +151,7 @@ export function getLayerList() {
119151
joins: [
120152
{
121153
leftField: 'iso2',
122-
right: ES_TERM_SOURCE,
154+
right: ES_TERM_SOURCE_COUNTRY,
123155
},
124156
],
125157
sourceDescriptor: {
@@ -138,18 +170,13 @@ export function getLayerList() {
138170
type: 'VECTOR',
139171
};
140172

173+
ES_TERM_SOURCE_REGION.whereQuery = getWhereQuery(serviceName!);
174+
141175
const pageLoadDurationByAdminRegionLayer: VectorLayerDescriptor = {
142176
joins: [
143177
{
144178
leftField: 'region_iso_code',
145-
right: {
146-
type: 'ES_TERM_SOURCE',
147-
id: 'e62a1b9c-d7ff-4fd4-a0f6-0fdc44bb9e41',
148-
indexPatternTitle: 'apm-*',
149-
term: 'client.geo.region_iso_code',
150-
metrics: [{ type: AGG_TYPE.AVG, field: 'transaction.duration.us' }],
151-
indexPatternId: APM_STATIC_INDEX_PATTERN_ID,
152-
},
179+
right: ES_TERM_SOURCE_REGION,
153180
},
154181
],
155182
sourceDescriptor: {
@@ -166,6 +193,7 @@ export function getLayerList() {
166193
visible: true,
167194
type: 'VECTOR',
168195
};
196+
169197
return [
170198
baseLayer,
171199
pageLoadDurationByCountryLayer,

0 commit comments

Comments
 (0)