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

[Uptime] Handle locations with names but no geo data #55234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Expand Up @@ -12,6 +12,7 @@ import { start } from '../../../../../../../../../src/legacy/core_plugins/embedd
import * as i18n from './translations';
// @ts-ignore
import { MAP_SAVED_OBJECT_TYPE } from '../../../../../../maps/common/constants';
import { Location } from '../../../../../common/runtime_types';

import { MapEmbeddable } from './types';
import { getLayerList } from './map_config';
Expand All @@ -22,10 +23,7 @@ export interface EmbeddedMapProps {
downPoints: LocationPoint[];
}

export interface LocationPoint {
lat: string;
lon: string;
}
export type LocationPoint = Required<Location>;

const EmbeddedPanel = styled.div`
z-index: auto;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import lowPolyLayerFeatures from './low_poly_layer.json';
import { LocationPoint } from './embedded_map';
import { LocationPoint } from './embedded_map.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My editor automatically did that.. I don't know what the typical convention is but I've seen it elsewhere in Kibana too.

import { UptimeAppColors } from '../../../../uptime_app';

/**
Expand All @@ -16,7 +16,7 @@ import { UptimeAppColors } from '../../../../uptime_app';
export const getLayerList = (
upPoints: LocationPoint[],
downPoints: LocationPoint[],
{ gray, danger }: Pick<UptimeAppColors, 'gray' | 'danger'>
{ danger }: Pick<UptimeAppColors, 'danger'>
) => {
return [getLowPolyLayer(), getDownPointsLayer(downPoints, danger), getUpPointsLayer(upPoints)];
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styled from 'styled-components';
import { EuiFlexGroup, EuiFlexItem, EuiErrorBoundary } from '@elastic/eui';
import { LocationStatusTags } from './location_status_tags';
import { EmbeddedMap, LocationPoint } from './embeddables/embedded_map';
import { MonitorLocations } from '../../../../common/runtime_types';
import { MonitorLocations, MonitorLocation } from '../../../../common/runtime_types';
import { UNNAMED_LOCATION } from '../../../../common/constants';
import { LocationMissingWarning } from './location_missing';

Expand All @@ -32,15 +32,23 @@ export const LocationMap = ({ monitorLocations }: LocationMapProps) => {
let isGeoInfoMissing = false;

if (monitorLocations?.locations) {
monitorLocations.locations.forEach((item: any) => {
if (item.geo?.name !== UNNAMED_LOCATION) {
if (item.summary.down === 0) {
upPoints.push(item.geo.location);
monitorLocations.locations.forEach((item: MonitorLocation) => {
if (item.geo?.name === UNNAMED_LOCATION || !item.geo?.location) {
isGeoInfoMissing = true;
} else if (
item.geo?.name !== UNNAMED_LOCATION &&
!!item.geo.location.lat &&
!!item.geo.location.lon
) {
// TypeScript doesn't infer that the above checks in this block's condition
// ensure that lat and lon are defined when we try to pass the location object directly,
// but if we destructure the values it does. Improvement to this block is welcome.
const { lat, lon } = item.geo.location;
if (item?.summary?.down === 0) {
upPoints.push({ lat, lon });
} else {
downPoints.push(item.geo.location);
downPoints.push({ lat, lon });
}
} else if (item.geo?.name === UNNAMED_LOCATION) {
isGeoInfoMissing = true;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,18 @@ export const elasticsearchMonitorsAdapter: UMMonitorsAdapter = {
const result = await callES('search', params);
const locations = result?.aggregations?.location?.buckets ?? [];

const getGeo = (locGeo: any) => {
const getGeo = (locGeo: { name: string; location?: string }) => {
if (locGeo) {
const { name, location } = locGeo;
const latLon = location.trim().split(',');
const latLon = location?.trim().split(',');
return {
name,
location: {
lat: latLon[0],
lon: latLon[1],
},
location: latLon
? {
lat: latLon[0],
lon: latLon[1],
}
: undefined,
};
} else {
return {
Expand Down