-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Changes from all commits
b3284c9
6dab983
539b6b6
d66603a
14ab31e
df670ce
e1e72ae
dfcf31c
2fa26b1
750425d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,45 +5,95 @@ | |||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
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 { FormattedMessage } from '@kbn/i18n/react'; | ||||||||||||||||||||||||||||||||||
import { useSelector } from 'react-redux'; | ||||||||||||||||||||||||||||||||||
import { Cert } from '../../../common/runtime_types'; | ||||||||||||||||||||||||||||||||||
import { useCertStatus } from '../../hooks'; | ||||||||||||||||||||||||||||||||||
import * as labels from './translations'; | ||||||||||||||||||||||||||||||||||
import { CERT_STATUS } from '../../../common/constants'; | ||||||||||||||||||||||||||||||||||
import { selectDynamicSettings } from '../../state/selectors'; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
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 dss = useSelector(selectDynamicSettings); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
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> | ||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
if (certStatus === CERT_STATUS.TOO_OLD) { | ||||||||||||||||||||||||||||||||||
const ageThreshold = dss.settings?.certAgeThreshold; | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const oldRelativeDate = moment(cert?.not_before).add(ageThreshold, 'days').fromNow(); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||
<EuiHealth color="danger"> | ||||||||||||||||||||||||||||||||||
<span>{labels.TOO_OLD}</span> | ||||||||||||||||||||||||||||||||||
<span> | ||||||||||||||||||||||||||||||||||
{labels.TOO_OLD} | ||||||||||||||||||||||||||||||||||
<DateText color="subdued" size="xs"> | ||||||||||||||||||||||||||||||||||
{oldRelativeDate} | ||||||||||||||||||||||||||||||||||
</DateText> | ||||||||||||||||||||||||||||||||||
</span> | ||||||||||||||||||||||||||||||||||
</EuiHealth> | ||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
const okRelativeDate = moment(cert?.not_after).fromNow(true); | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
return ( | ||||||||||||||||||||||||||||||||||
<EuiHealth color="success"> | ||||||||||||||||||||||||||||||||||
<span>{labels.OK}</span> | ||||||||||||||||||||||||||||||||||
<span> | ||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be translated, something like:
Suggested change
Alternatively you could extract the string to a label, but seems strange to do it for only one word. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||||||||||||||||||||||||||||||||||
{labels.OK} | ||||||||||||||||||||||||||||||||||
{' '} | ||||||||||||||||||||||||||||||||||
<DateText color="subdued" size="xs"> | ||||||||||||||||||||||||||||||||||
<FormattedMessage | ||||||||||||||||||||||||||||||||||
id="xpack.uptime.certs.status.ok.label" | ||||||||||||||||||||||||||||||||||
defaultMessage=" for {okRelativeDate}" | ||||||||||||||||||||||||||||||||||
description='Denotes an amount of time for which a cert is valid. Example: "OK for 2 days"' | ||||||||||||||||||||||||||||||||||
values={{ | ||||||||||||||||||||||||||||||||||
okRelativeDate, | ||||||||||||||||||||||||||||||||||
}} | ||||||||||||||||||||||||||||||||||
/> | ||||||||||||||||||||||||||||||||||
</DateText> | ||||||||||||||||||||||||||||||||||
</span> | ||||||||||||||||||||||||||||||||||
</EuiHealth> | ||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||
}; |
There was a problem hiding this comment.
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?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example:

There was a problem hiding this comment.
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.