Skip to content

Commit

Permalink
Handle locations with names but no geo data.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Jan 17, 2020
1 parent d082c03 commit f40ece0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,15 @@ 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';
import { UptimeThemeContext } from '../../../../contexts';

export interface EmbeddedMapProps {
upPoints: LocationPoint[];
downPoints: LocationPoint[];
}

export interface LocationPoint {
lat: string;
lon: string;
upPoints: Location[];
downPoints: Location[];
}

const EmbeddedPanel = styled.div`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import React from 'react';
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 { EmbeddedMap } from './embeddables/embedded_map';
import { Location, MonitorLocations, MonitorLocation } from '../../../../common/runtime_types';
import { UNNAMED_LOCATION } from '../../../../common/constants';
import { LocationMissingWarning } from './location_missing';

Expand All @@ -26,21 +26,21 @@ interface LocationMapProps {
}

export const LocationMap = ({ monitorLocations }: LocationMapProps) => {
const upPoints: LocationPoint[] = [];
const downPoints: LocationPoint[] = [];
const upPoints: Location[] = [];
const downPoints: Location[] = [];

let isGeoInfoMissing = false;

if (monitorLocations?.locations) {
monitorLocations.locations.forEach((item: any) => {
if (item.geo?.name !== UNNAMED_LOCATION) {
if (item.summary.down === 0) {
monitorLocations.locations.forEach((item: MonitorLocation) => {
if (item.geo?.name === UNNAMED_LOCATION || !item.geo?.location) {
isGeoInfoMissing = true;
} else if (item.geo?.name !== UNNAMED_LOCATION) {
if (item?.summary?.down === 0) {
upPoints.push(item.geo.location);
} else {
downPoints.push(item.geo.location);
}
} 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

0 comments on commit f40ece0

Please sign in to comment.