Skip to content

Commit e4ccf19

Browse files
[Uptime] Fix/location map hide layer view control (#53568)
* hide layer control and added loc tags * update test * remove unused comment * remove capitalization * style fix * update types Co-authored-by: Elastic Machine <[email protected]>
1 parent 785b916 commit e4ccf19

File tree

6 files changed

+110
-18
lines changed

6 files changed

+110
-18
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import lowPolyLayerFeatures from '../low_poly_layer.json';
7+
import lowPolyLayerFeatures from '../../low_poly_layer.json';
88

99
export const mockDownPointsLayer = {
1010
id: 'down_points',
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { getLayerList } from './map_config';
7+
import { getLayerList } from '../map_config';
88
import { mockLayerList } from './__mocks__/mock';
9-
import { LocationPoint } from './embedded_map';
9+
import { LocationPoint } from '../embedded_map';
1010

1111
jest.mock('uuid', () => {
1212
return {
@@ -33,7 +33,7 @@ describe('map_config', () => {
3333

3434
describe('#getLayerList', () => {
3535
test('it returns the low poly layer', () => {
36-
const layerList = getLayerList(upPoints, downPoints);
36+
const layerList = getLayerList(upPoints, downPoints, { danger: '#BC261E', gray: '#000' });
3737
expect(layerList).toStrictEqual(mockLayerList);
3838
});
3939
});

x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/embedded_map.tsx

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

7-
import React, { useEffect, useState } from 'react';
7+
import React, { useEffect, useState, useContext } from 'react';
88
import uuid from 'uuid';
99
import styled from 'styled-components';
1010

@@ -15,6 +15,7 @@ import { MAP_SAVED_OBJECT_TYPE } from '../../../../../../maps/common/constants';
1515

1616
import { MapEmbeddable } from './types';
1717
import { getLayerList } from './map_config';
18+
import { UptimeSettingsContext } from '../../../../contexts';
1819

1920
export interface EmbeddedMapProps {
2021
upPoints: LocationPoint[];
@@ -45,6 +46,7 @@ const EmbeddedPanel = styled.div`
4546
`;
4647

4748
export const EmbeddedMap = ({ upPoints, downPoints }: EmbeddedMapProps) => {
49+
const { colors } = useContext(UptimeSettingsContext);
4850
const [embeddable, setEmbeddable] = useState<MapEmbeddable>();
4951
const embeddableRoot: React.RefObject<HTMLDivElement> = React.createRef();
5052
const factory = start.getEmbeddableFactory(MAP_SAVED_OBJECT_TYPE);
@@ -58,16 +60,18 @@ export const EmbeddedMap = ({ upPoints, downPoints }: EmbeddedMapProps) => {
5860
viewMode: 'view',
5961
isLayerTOCOpen: false,
6062
hideFilterActions: true,
61-
mapCenter: { lon: 11, lat: 47, zoom: 0 },
63+
mapCenter: { lon: 11, lat: 20, zoom: 0 },
6264
disableInteractive: true,
6365
disableTooltipControl: true,
6466
hideToolbarOverlay: true,
67+
hideLayerControl: true,
68+
hideViewControl: true,
6569
};
6670

6771
useEffect(() => {
6872
async function setupEmbeddable() {
6973
const mapState = {
70-
layerList: getLayerList(upPoints, downPoints),
74+
layerList: getLayerList(upPoints, downPoints, colors),
7175
title: i18n.MAP_TITLE,
7276
};
7377
// @ts-ignore
@@ -82,9 +86,9 @@ export const EmbeddedMap = ({ upPoints, downPoints }: EmbeddedMapProps) => {
8286

8387
useEffect(() => {
8488
if (embeddable) {
85-
embeddable.setLayerList(getLayerList(upPoints, downPoints));
89+
embeddable.setLayerList(getLayerList(upPoints, downPoints, colors));
8690
}
87-
}, [upPoints, downPoints, embeddable]);
91+
}, [upPoints, downPoints, embeddable, colors]);
8892

8993
useEffect(() => {
9094
if (embeddableRoot.current && embeddable) {

x-pack/legacy/plugins/uptime/public/components/functional/location_map/embeddables/map_config.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import { LocationPoint } from './embedded_map';
1212
* destination, and line layer for each of the provided indexPatterns
1313
*
1414
*/
15-
export const getLayerList = (upPoints: LocationPoint[], downPoints: LocationPoint[]) => {
16-
return [getLowPolyLayer(), getDownPointsLayer(downPoints), getUpPointsLayer(upPoints)];
15+
export const getLayerList = (
16+
upPoints: LocationPoint[],
17+
downPoints: LocationPoint[],
18+
{ gray, danger }: { gray: string; danger: string }
19+
) => {
20+
return [getLowPolyLayer(), getDownPointsLayer(downPoints, danger), getUpPointsLayer(upPoints)];
1721
};
1822

1923
export const getLowPolyLayer = () => {
@@ -62,7 +66,7 @@ export const getLowPolyLayer = () => {
6266
};
6367
};
6468

65-
export const getDownPointsLayer = (downPoints: LocationPoint[]) => {
69+
export const getDownPointsLayer = (downPoints: LocationPoint[], dangerColor: string) => {
6670
const features = downPoints?.map(point => ({
6771
type: 'feature',
6872
geometry: {
@@ -87,7 +91,7 @@ export const getDownPointsLayer = (downPoints: LocationPoint[]) => {
8791
fillColor: {
8892
type: 'STATIC',
8993
options: {
90-
color: '#BC261E',
94+
color: dangerColor,
9195
},
9296
},
9397
lineColor: {

x-pack/legacy/plugins/uptime/public/components/functional/location_map/location_map.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@
66

77
import React from 'react';
88
import styled from 'styled-components';
9+
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
10+
import { LocationStatusTags } from './location_status_tags';
911
import { EmbeddedMap, LocationPoint } from './embeddables/embedded_map';
12+
import { MonitorLocations } from '../../../../common/runtime_types';
1013

1114
const MapPanel = styled.div`
12-
height: 400px;
15+
height: 240px;
1316
width: 520px;
17+
margin-right: 10px;
1418
`;
1519

1620
interface LocationMapProps {
17-
monitorLocations: any;
21+
monitorLocations: MonitorLocations;
1822
}
1923

2024
export const LocationMap = ({ monitorLocations }: LocationMapProps) => {
@@ -31,8 +35,15 @@ export const LocationMap = ({ monitorLocations }: LocationMapProps) => {
3135
});
3236
}
3337
return (
34-
<MapPanel>
35-
<EmbeddedMap upPoints={upPoints} downPoints={downPoints} />
36-
</MapPanel>
38+
<EuiFlexGroup>
39+
<EuiFlexItem grow={false}>
40+
<LocationStatusTags locations={monitorLocations?.locations || []} />
41+
</EuiFlexItem>
42+
<EuiFlexItem grow={true}>
43+
<MapPanel>
44+
<EmbeddedMap upPoints={upPoints} downPoints={downPoints} />
45+
</MapPanel>
46+
</EuiFlexItem>
47+
</EuiFlexGroup>
3748
);
3849
};
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React, { useContext } from 'react';
8+
import styled from 'styled-components';
9+
import { EuiBadge, EuiText } from '@elastic/eui';
10+
import { UptimeSettingsContext } from '../../../contexts';
11+
import { MonitorLocation } from '../../../../common/runtime_types';
12+
13+
const TextStyle = styled.div`
14+
font-weight: 600;
15+
`;
16+
17+
const BadgeItem = styled.div`
18+
margin-bottom: 5px;
19+
`;
20+
21+
const TagContainer = styled.div`
22+
padding: 10px;
23+
max-height: 200px;
24+
overflow: hidden;
25+
`;
26+
27+
interface Props {
28+
locations: MonitorLocation[];
29+
}
30+
31+
export const LocationStatusTags = ({ locations }: Props) => {
32+
const {
33+
colors: { gray, danger },
34+
} = useContext(UptimeSettingsContext);
35+
36+
const upLocs: string[] = [];
37+
const downLocs: string[] = [];
38+
39+
locations.forEach((item: any) => {
40+
if (item.summary.down === 0) {
41+
upLocs.push(item.geo.name);
42+
} else {
43+
downLocs.push(item.geo.name);
44+
}
45+
});
46+
47+
return (
48+
<TagContainer>
49+
<span>
50+
{downLocs.map((item, ind) => (
51+
<BadgeItem key={ind}>
52+
<EuiBadge color={danger}>
53+
<EuiText size="m">
54+
<TextStyle>{item}</TextStyle>
55+
</EuiText>
56+
</EuiBadge>
57+
</BadgeItem>
58+
))}
59+
</span>
60+
<span>
61+
{upLocs.map((item, ind) => (
62+
<BadgeItem key={ind}>
63+
<EuiBadge color={gray}>
64+
<EuiText size="m">
65+
<TextStyle>{item}</TextStyle>
66+
</EuiText>
67+
</EuiBadge>
68+
</BadgeItem>
69+
))}
70+
</span>
71+
</TagContainer>
72+
);
73+
};

0 commit comments

Comments
 (0)