Skip to content

Commit

Permalink
update columns (elastic#51892)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Dec 9, 2019
1 parent 2a026a8 commit 8fefc1d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 36 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@

import React from 'react';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';
<<<<<<< HEAD:x-pack/legacy/plugins/uptime/public/components/functional/__tests__/ping_list.test.tsx
import { PingResults, Ping } from '../../../../common/graphql/types';
import { PingListComponent, BaseLocationOptions, toggleDetails } from '../ping_list';
=======
import { PingResults, Ping } from '../../../../../common/graphql/types';
import { PingListComponent, AllLocationOption, toggleDetails } from '../ping_list';
>>>>>>> 6af9f9bea6... update columns (#51892):x-pack/legacy/plugins/uptime/public/components/functional/ping_list/__tests__/ping_list.test.tsx
import { EuiComboBoxOptionProps } from '@elastic/eui';
import { ExpandedRowMap } from '../monitor_list/types';
import { ExpandedRowMap } from '../../monitor_list/types';

describe('PingList component', () => {
let pingList: { allPings: PingResults };
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* 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.
*/

export * from './ping_list';
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import moment from 'moment';
import React, { Fragment, useEffect, useState } from 'react';
// @ts-ignore formatNumber
import { formatNumber } from '@elastic/eui/lib/services/format';
import { Ping, PingResults } from '../../../common/graphql/types';
import { convertMicrosecondsToMilliseconds as microsToMillis } from '../../lib/helper';
import { UptimeGraphQLQueryProps, withUptimeGraphQL } from '../higher_order';
import { pingsQuery } from '../../queries';
import { LocationName } from './location_name';
import { Criteria, Pagination } from './monitor_list';
import { PingListExpandedRowComponent } from './ping_list/expanded_row';
import { Ping, PingResults } from '../../../../common/graphql/types';
import { convertMicrosecondsToMilliseconds as microsToMillis } from '../../../lib/helper';
import { UptimeGraphQLQueryProps, withUptimeGraphQL } from '../../higher_order';
import { pingsQuery } from '../../../queries';
import { LocationName } from './../location_name';
import { Criteria, Pagination } from './../monitor_list';
import { PingListExpandedRowComponent } from './expanded_row';

interface PingListQueryResult {
allPings?: PingResults;
Expand Down Expand Up @@ -84,6 +84,10 @@ export const PingListComponent = ({
}: Props) => {
const [itemIdToExpandedRowMap, setItemIdToExpandedRowMap] = useState<ExpandedRowMap>({});

useEffect(() => {
onUpdateApp();
}, [selectedOption]);

const statusOptions: EuiComboBoxOptionProps[] = [
{
label: i18n.translate('xpack.uptime.pingList.statusOptions.allStatusOptionLabel', {
Expand Down Expand Up @@ -142,8 +146,7 @@ export const PingListComponent = ({
),
},
{
align: 'left',
dataType: 'number',
align: 'center',
field: 'observer.geo.name',
name: i18n.translate('xpack.uptime.pingList.locationNameColumnLabel', {
defaultMessage: 'Location',
Expand Down Expand Up @@ -171,36 +174,31 @@ export const PingListComponent = ({
}),
},
{
align: 'left',
align: 'right',
field: 'error.type',
name: i18n.translate('xpack.uptime.pingList.errorTypeColumnLabel', {
defaultMessage: 'Error type',
}),
render: (error: string) => error ?? '-',
},
];
useEffect(() => {
onUpdateApp();
}, [selectedOption]);
let pings: Ping[] = [];
if (data && data.allPings && data.allPings.pings) {
pings = data.allPings.pings;
const hasStatus: boolean = pings.reduce(
(hasHttpStatus: boolean, currentPing: Ping) =>
hasHttpStatus || !!get(currentPing, 'http.response.status_code'),
false
);
if (hasStatus) {
columns.push({
field: 'http.response.status_code',
// @ts-ignore "align" property missing on type definition for column type
align: 'right',
name: i18n.translate('xpack.uptime.pingList.responseCodeColumnLabel', {
defaultMessage: 'Response code',
}),
render: (statusCode: string) => <EuiBadge>{statusCode}</EuiBadge>,
});
}

const pings: Ping[] = data?.allPings?.pings ?? [];

const hasStatus: boolean = pings.some(
(currentPing: Ping) => !!currentPing?.http?.response?.status_code
);
if (hasStatus) {
columns.push({
field: 'http.response.status_code',
align: 'right',
name: i18n.translate('xpack.uptime.pingList.responseCodeColumnLabel', {
defaultMessage: 'Response code',
}),
render: (statusCode: string) => <EuiBadge>{statusCode}</EuiBadge>,
});
}

columns.push({
align: 'right',
width: '40px',
Expand Down

0 comments on commit 8fefc1d

Please sign in to comment.