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] Added relative date info in cert status column #67612

Merged
merged 10 commits into from
Jun 9, 2020

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 @@ -5,7 +5,9 @@
*/

import React from 'react';
import { EuiHealth } from '@elastic/eui';
import moment from 'moment';
import styled from 'styled-components';
import { EuiHealth, EuiText } from '@elastic/eui';
import { Cert } from '../../../common/runtime_types';
import { useCertStatus } from '../../hooks';
import * as labels from './translations';
Expand All @@ -15,20 +17,39 @@ interface Props {
cert: Cert;
}

const DateText = styled(EuiText)`
display: inline-block;
margin-left: 5px;
`;

export const CertStatus: React.FC<Props> = ({ cert }) => {
const certStatus = useCertStatus(cert?.not_after, cert?.not_before);

const relativeDate = moment(cert?.not_after).fromNow();

if (certStatus === CERT_STATUS.EXPIRING_SOON) {
return (
<EuiHealth color="warning">
<span>{labels.EXPIRES_SOON}</span>
<span>
{labels.EXPIRES_SOON}
{' '}
<DateText color="subdued" size="xs">
{relativeDate}
</DateText>
</span>
</EuiHealth>
);
}
if (certStatus === CERT_STATUS.EXPIRED) {
return (
<EuiHealth color="danger">
<span>{labels.EXPIRED}</span>
<span>
{labels.EXPIRED}
{' '}
<DateText color="subdued" size="xs">
{relativeDate}
</DateText>
</span>
</EuiHealth>
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it a deliberate choice to omit the relative date from CERT_STATUS.TOO_OLD case?

Copy link
Contributor

Choose a reason for hiding this comment

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

Example:
image

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 took care of it.

Expand All @@ -41,9 +62,18 @@ export const CertStatus: React.FC<Props> = ({ cert }) => {
);
}

const okRelativeDate = moment(cert?.not_after).fromNow(true);

return (
<EuiHealth color="success">
<span>{labels.OK}</span>
<span>
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be translated, something like:

Suggested change
<span>
<span>
{labels.OK}
<DateText color="subdued" size="xs">
<FormattedMessage
id="xpack.uptime.certs.status.ok"
defaultMessage=" for {okRelativeDate}"
description={
'Denotes an amount of time for which a cert is valid. Example: "OK for 2 days"'
}
values={{
okRelativeDate,
}}
/>
</DateText>
</span>

Alternatively you could extract the string to a label, but seems strange to do it for only one word.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

{labels.OK}
{' '}
<DateText color="subdued" size="xs">
{'for '}
{okRelativeDate}
</DateText>
</span>
</EuiHealth>
);
};