Skip to content

Commit 133ca7f

Browse files
[Uptime] Added relative date info in cert status column (#67612)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent b2db19b commit 133ca7f

2 files changed

Lines changed: 70 additions & 6 deletions

File tree

x-pack/plugins/uptime/public/components/certificates/__tests__/__snapshots__/cert_status.test.tsx.snap

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/uptime/public/components/certificates/cert_status.tsx

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,95 @@
55
*/
66

77
import React from 'react';
8-
import { EuiHealth } from '@elastic/eui';
8+
import moment from 'moment';
9+
import styled from 'styled-components';
10+
import { EuiHealth, EuiText } from '@elastic/eui';
11+
import { FormattedMessage } from '@kbn/i18n/react';
12+
import { useSelector } from 'react-redux';
913
import { Cert } from '../../../common/runtime_types';
1014
import { useCertStatus } from '../../hooks';
1115
import * as labels from './translations';
1216
import { CERT_STATUS } from '../../../common/constants';
17+
import { selectDynamicSettings } from '../../state/selectors';
1318

1419
interface Props {
1520
cert: Cert;
1621
}
1722

23+
const DateText = styled(EuiText)`
24+
display: inline-block;
25+
margin-left: 5px;
26+
`;
27+
1828
export const CertStatus: React.FC<Props> = ({ cert }) => {
1929
const certStatus = useCertStatus(cert?.not_after, cert?.not_before);
2030

31+
const dss = useSelector(selectDynamicSettings);
32+
33+
const relativeDate = moment(cert?.not_after).fromNow();
34+
2135
if (certStatus === CERT_STATUS.EXPIRING_SOON) {
2236
return (
2337
<EuiHealth color="warning">
24-
<span>{labels.EXPIRES_SOON}</span>
38+
<span>
39+
{labels.EXPIRES_SOON}
40+
{' '}
41+
<DateText color="subdued" size="xs">
42+
{relativeDate}
43+
</DateText>
44+
</span>
2545
</EuiHealth>
2646
);
2747
}
2848
if (certStatus === CERT_STATUS.EXPIRED) {
2949
return (
3050
<EuiHealth color="danger">
31-
<span>{labels.EXPIRED}</span>
51+
<span>
52+
{labels.EXPIRED}
53+
{' '}
54+
<DateText color="subdued" size="xs">
55+
{relativeDate}
56+
</DateText>
57+
</span>
3258
</EuiHealth>
3359
);
3460
}
3561

3662
if (certStatus === CERT_STATUS.TOO_OLD) {
63+
const ageThreshold = dss.settings?.certAgeThreshold;
64+
65+
const oldRelativeDate = moment(cert?.not_before).add(ageThreshold, 'days').fromNow();
66+
3767
return (
3868
<EuiHealth color="danger">
39-
<span>{labels.TOO_OLD}</span>
69+
<span>
70+
{labels.TOO_OLD}
71+
<DateText color="subdued" size="xs">
72+
{oldRelativeDate}
73+
</DateText>
74+
</span>
4075
</EuiHealth>
4176
);
4277
}
4378

79+
const okRelativeDate = moment(cert?.not_after).fromNow(true);
80+
4481
return (
4582
<EuiHealth color="success">
46-
<span>{labels.OK}</span>
83+
<span>
84+
{labels.OK}
85+
{' '}
86+
<DateText color="subdued" size="xs">
87+
<FormattedMessage
88+
id="xpack.uptime.certs.status.ok.label"
89+
defaultMessage=" for {okRelativeDate}"
90+
description='Denotes an amount of time for which a cert is valid. Example: "OK for 2 days"'
91+
values={{
92+
okRelativeDate,
93+
}}
94+
/>
95+
</DateText>
96+
</span>
4797
</EuiHealth>
4898
);
4999
};

0 commit comments

Comments
 (0)