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] Ping List Disable expand row if no body present #54898

Merged
merged 10 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 5 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

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
@@ -0,0 +1,38 @@
/*
* 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.
*/

import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { EuiIcon, EuiLink, EuiText } from '@elastic/eui';

const bodyDocsLink =
'https://www.elastic.co/guide/en/beats/heartbeat/current/configuration-heartbeat-options.html#monitor-http-response';

export const DocLinkForBody = () => {
const docsLink = (
<EuiLink href={bodyDocsLink} target="_blank">
{i18n.translate('xpack.uptime.monitorList.geoName.helpLinkAnnotation', {
defaultMessage: 'Docs',
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
description: 'Docs link to set response body',
})}
&nbsp;
<EuiIcon size="s" type="popout" />
</EuiLink>
);

return (
<EuiText>
<FormattedMessage
id={'xpack.uptime.pingList.expandedRow.response_body.notRecorded'}
defaultMessage={
'Body not recorded. Read our {docsLink} for more information on recording response bodies.'
}
values={{ docsLink }}
/>
</EuiText>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
*/
// @ts-ignore formatNumber
import { formatNumber } from '@elastic/eui/lib/services/format';
import { EuiCodeBlock, EuiDescriptionList, EuiText } from '@elastic/eui';
import React, { Fragment } from 'react';
import {
EuiCallOut,
EuiCodeBlock,
EuiDescriptionList,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
EuiText,
} from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { Ping, HttpBody } from '../../../../common/graphql/types';
import { DocLinkForBody } from './doc_link_body';

interface Props {
ping: Ping;
Expand Down Expand Up @@ -52,20 +61,29 @@ export const PingListExpandedRowComponent = ({ ping }: Props) => {
}

// Show the body, if present
if (ping.http && ping.http.response && ping.http.response.body) {
if (ping.http?.response?.body) {
const body = ping.http.response.body;

listItems.push({
title: i18n.translate('xpack.uptime.pingList.expandedRow.response_body', {
defaultMessage: 'Response Body',
}),
description: (
<Fragment>
<>
<BodyDescription body={body} />
<BodyExcerpt content={body.content || ''} />
</Fragment>
<EuiSpacer size={'s'} />
{body.content ? <BodyExcerpt content={body.content || ''} /> : <DocLinkForBody />}
Copy link
Contributor

Choose a reason for hiding this comment

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

AFAICT we don't have a test case for this. The snapshot was updated, but there's no case where I see this rendered.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added the case for this in test file.

</>
),
});
}
return <EuiDescriptionList listItems={listItems} />;
return (
<EuiFlexGroup>
<EuiFlexItem>
<EuiCallOut color={ping?.error ? 'danger' : 'primary'}>
<EuiDescriptionList listItems={listItems} />
</EuiCallOut>
</EuiFlexItem>
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,14 @@ export const PingListComponent = ({
})
);

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

const hasStatus: boolean = pings.reduce(
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
(hasHttpStatus: boolean, currentPing: Ping) =>
hasHttpStatus || !!currentPing.http?.response?.status_code,
false
);

const columns: any[] = [
{
field: 'monitor.status',
Expand Down Expand Up @@ -172,55 +180,57 @@ export const PingListComponent = ({
}),
},
{
align: 'right',
align: hasStatus ? 'right' : 'center',
field: 'error.type',
name: i18n.translate('xpack.uptime.pingList.errorTypeColumnLabel', {
defaultMessage: 'Error type',
}),
render: (error: string) => error ?? '-',
},
];
const pings: Ping[] = data?.allPings?.pings ?? [];
const hasStatus: boolean = pings.reduce(
(hasHttpStatus: boolean, currentPing: Ping) =>
hasHttpStatus || !!currentPing.http?.response?.status_code,
false
);
if (hasStatus) {
columns.push({
field: 'http.response.status_code',
// Only add this column is there is any status present in list
...(hasStatus
? [
{
field: 'http.response.status_code',
align: 'right',
name: (
<SpanWithMargin>
{i18n.translate('xpack.uptime.pingList.responseCodeColumnLabel', {
defaultMessage: 'Response code',
})}
</SpanWithMargin>
),
render: (statusCode: string) => (
<SpanWithMargin>
<EuiBadge>{statusCode}</EuiBadge>
</SpanWithMargin>
),
},
]
: []),
{
align: 'right',
name: (
<SpanWithMargin>
{i18n.translate('xpack.uptime.pingList.responseCodeColumnLabel', {
defaultMessage: 'Response code',
})}
</SpanWithMargin>
),
render: (statusCode: string) => (
<SpanWithMargin>
<EuiBadge>{statusCode}</EuiBadge>{' '}
</SpanWithMargin>
),
});
}
width: '24px',
isExpander: true,
render: (item: Ping) => {
return (
<EuiButtonIcon
onClick={() => toggleDetails(item, itemIdToExpandedRowMap, setItemIdToExpandedRowMap)}
disabled={!item.error && !(item.http?.response?.body?.bytes > 0)}
aria-label={
itemIdToExpandedRowMap[item.id]
? i18n.translate('xpack.uptime.pingList.collapseRow', {
defaultMessage: 'Collapse',
})
: i18n.translate('xpack.uptime.pingList.expandRow', { defaultMessage: 'Expand' })
}
iconType={itemIdToExpandedRowMap[item.id] ? 'arrowUp' : 'arrowDown'}
/>
);
},
},
];

columns.push({
align: 'right',
width: '24px',
isExpander: true,
render: (item: Ping) => (
<EuiButtonIcon
onClick={() => toggleDetails(item, itemIdToExpandedRowMap, setItemIdToExpandedRowMap)}
aria-label={
itemIdToExpandedRowMap[item.id]
? i18n.translate('xpack.uptime.pingList.collapseRow', { defaultMessage: 'Collapse' })
: i18n.translate('xpack.uptime.pingList.expandRow', { defaultMessage: 'Expand' })
}
iconType={itemIdToExpandedRowMap[item.id] ? 'arrowUp' : 'arrowDown'}
/>
),
});
const pagination: Pagination = {
initialPageSize: 20,
pageIndex: 0,
Expand Down