|
5 | 5 | */ |
6 | 6 |
|
7 | 7 | 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'; |
9 | 13 | import { Cert } from '../../../common/runtime_types'; |
10 | 14 | import { useCertStatus } from '../../hooks'; |
11 | 15 | import * as labels from './translations'; |
12 | 16 | import { CERT_STATUS } from '../../../common/constants'; |
| 17 | +import { selectDynamicSettings } from '../../state/selectors'; |
13 | 18 |
|
14 | 19 | interface Props { |
15 | 20 | cert: Cert; |
16 | 21 | } |
17 | 22 |
|
| 23 | +const DateText = styled(EuiText)` |
| 24 | + display: inline-block; |
| 25 | + margin-left: 5px; |
| 26 | +`; |
| 27 | + |
18 | 28 | export const CertStatus: React.FC<Props> = ({ cert }) => { |
19 | 29 | const certStatus = useCertStatus(cert?.not_after, cert?.not_before); |
20 | 30 |
|
| 31 | + const dss = useSelector(selectDynamicSettings); |
| 32 | + |
| 33 | + const relativeDate = moment(cert?.not_after).fromNow(); |
| 34 | + |
21 | 35 | if (certStatus === CERT_STATUS.EXPIRING_SOON) { |
22 | 36 | return ( |
23 | 37 | <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> |
25 | 45 | </EuiHealth> |
26 | 46 | ); |
27 | 47 | } |
28 | 48 | if (certStatus === CERT_STATUS.EXPIRED) { |
29 | 49 | return ( |
30 | 50 | <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> |
32 | 58 | </EuiHealth> |
33 | 59 | ); |
34 | 60 | } |
35 | 61 |
|
36 | 62 | 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 | + |
37 | 67 | return ( |
38 | 68 | <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> |
40 | 75 | </EuiHealth> |
41 | 76 | ); |
42 | 77 | } |
43 | 78 |
|
| 79 | + const okRelativeDate = moment(cert?.not_after).fromNow(true); |
| 80 | + |
44 | 81 | return ( |
45 | 82 | <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> |
47 | 97 | </EuiHealth> |
48 | 98 | ); |
49 | 99 | }; |
0 commit comments