Skip to content

Commit f97643f

Browse files
Standardize timestamp formatting using AcmTimestamp component across console UI (stolostron#4261)
* implements acmtimestamp Signed-off-by: vsanghishetty <vishali.kamenani@ymail.com> * Change N/A to language neutral - Signed-off-by: Kevin Cormier <kcormier@redhat.com> --------- Signed-off-by: vsanghishetty <vishali.kamenani@ymail.com> Signed-off-by: Kevin Cormier <kcormier@redhat.com> Co-authored-by: Kevin Cormier <kcormier@redhat.com>
1 parent 5a3b384 commit f97643f

File tree

3 files changed

+20
-23
lines changed

3 files changed

+20
-23
lines changed

frontend/src/routes/Governance/policies/policy-details/PolicyDetailsHistory.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Policy, PolicyStatusDetails } from '../../../../resources'
99
import { useRecoilValue, useSharedAtoms } from '../../../../shared-recoil'
1010
import { AcmEmptyState, AcmTable, AcmTablePaginationContextProvider, compareStrings } from '../../../../ui-components'
1111
import { getISOStringTimestamp } from '../../../../resources/utils'
12+
import AcmTimestamp from '../../../../lib/AcmTimestamp'
1213

1314
interface HistoryTableData {
1415
message: string
@@ -136,7 +137,7 @@ export function PolicyDetailsHistory(props: {
136137
{
137138
header: t('Last report'),
138139
sort: 'index',
139-
cell: (item: any) => (item.timestamp ? moment(item.timestamp, 'YYYY-MM-DDTHH:mm:ssZ').fromNow() : '-'),
140+
cell: (item: any) => (item.timestamp ? <AcmTimestamp timestamp={item.timestamp} /> : '-'),
140141
exportContent: (item: any) => {
141142
if (item.timestamp) {
142143
return getISOStringTimestamp(item.timestamp)

frontend/src/routes/Governance/policies/policy-details/PolicyDetailsOverview.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import { Alert, ButtonVariant, Icon, LabelGroup, PageSection, Stack, Text, TextVariants } from '@patternfly/react-core'
33
import { CheckCircleIcon, ExclamationCircleIcon, ExclamationTriangleIcon } from '@patternfly/react-icons'
44
import { AcmButton, AcmDescriptionList, AcmDrawerContext, AcmTable } from '../../../../ui-components'
5-
import moment from 'moment'
65
import { ReactNode, useCallback, useContext, useMemo, useState } from 'react'
76
import { Link, generatePath } from 'react-router-dom-v5-compat'
87
import { useRecoilValue, useSharedAtoms } from '../../../../shared-recoil'
@@ -32,6 +31,7 @@ import { ClusterPolicyViolationIcons } from '../../components/ClusterPolicyViola
3231
import { useGovernanceData } from '../../useGovernanceData'
3332
import { usePropagatedPolicies } from '../../common/useCustom'
3433
import { usePolicyDetailsContext } from './PolicyDetailsPage'
34+
import AcmTimestamp from '../../../../lib/AcmTimestamp'
3535

3636
interface TableData {
3737
apiVersion: string
@@ -125,7 +125,7 @@ export default function PolicyDetailsOverview() {
125125
},
126126
{
127127
key: t('Created'),
128-
value: moment(policy.metadata.creationTimestamp, 'YYYY-MM-DDTHH:mm:ssZ').fromNow(),
128+
value: policy.metadata.creationTimestamp ? <AcmTimestamp timestamp={policy.metadata.creationTimestamp} /> : '-',
129129
},
130130
{
131131
key: t('Automation'),

frontend/src/routes/Infrastructure/Clusters/DiscoveredClusters/DiscoveredClusters.tsx

+16-20
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
} from '../../../../ui-components'
1414
import { ActionList, ActionListItem, Bullseye, ButtonVariant, PageSection } from '@patternfly/react-core'
1515
import { ExternalLinkAltIcon } from '@patternfly/react-icons'
16-
import * as moment from 'moment'
1716
import { Fragment, useCallback, useMemo } from 'react'
1817
import { Trans, useTranslation } from '../../../../lib/acm-i18next'
1918
import { Link, useNavigate } from 'react-router-dom-v5-compat'
@@ -22,6 +21,7 @@ import { navigateToBackCancelLocation, NavigationPath } from '../../../../Naviga
2221
import { DiscoveredCluster, DiscoveryConfig, ProviderConnection, unpackProviderConnection } from '../../../../resources'
2322
import { useRecoilValue, useSharedAtoms } from '../../../../shared-recoil'
2423
import { getISOStringTimestamp } from '../../../../resources/utils'
24+
import AcmTimestamp from '../../../../lib/AcmTimestamp'
2525

2626
export default function DiscoveredClustersPage() {
2727
return (
@@ -224,11 +224,11 @@ export function DiscoveredClustersTable(props: {
224224
sort: 'spec.activityTimestamp',
225225
cell: (discoveredCluster) => (
226226
<span style={{ whiteSpace: 'nowrap' }} key="dcLastActive">
227-
{discoveredCluster.spec.activityTimestamp === undefined
228-
? ['N/A']
229-
: moment
230-
.duration(Math.abs(new Date().getTime() - new Date(discoveredCluster.spec.activityTimestamp).getTime()))
231-
.humanize()}
227+
{discoveredCluster.spec.activityTimestamp ? (
228+
<AcmTimestamp timestamp={discoveredCluster.spec.activityTimestamp} />
229+
) : (
230+
['-']
231+
)}
232232
</span>
233233
),
234234
exportContent: (discoveredCluster) => {
@@ -292,11 +292,11 @@ export function DiscoveredClustersTable(props: {
292292
sort: 'spec.creationTimestamp',
293293
cell: (discoveredCluster) => (
294294
<span style={{ whiteSpace: 'nowrap' }} key="dcCreationTimestamp">
295-
{discoveredCluster.spec.creationTimestamp === undefined
296-
? ['N/A']
297-
: moment
298-
.duration(Math.abs(new Date().getTime() - new Date(discoveredCluster.spec.creationTimestamp).getTime()))
299-
.humanize()}
295+
{discoveredCluster.spec.creationTimestamp ? (
296+
<AcmTimestamp timestamp={discoveredCluster.spec.creationTimestamp} />
297+
) : (
298+
['-']
299+
)}
300300
</span>
301301
),
302302
exportContent: (discoveredCluster) => {
@@ -310,15 +310,11 @@ export function DiscoveredClustersTable(props: {
310310
sort: 'metadata.creationTimestamp',
311311
cell: (discoveredCluster) => (
312312
<span style={{ whiteSpace: 'nowrap' }} key="dcObjCreationTimestamp">
313-
{discoveredCluster.spec.creationTimestamp === undefined
314-
? ['N/A']
315-
: moment
316-
.duration(
317-
Math.abs(
318-
new Date().getTime() - new Date(discoveredCluster.metadata.creationTimestamp ?? '').getTime()
319-
)
320-
)
321-
.humanize()}
313+
{discoveredCluster.metadata.creationTimestamp ? (
314+
<AcmTimestamp timestamp={discoveredCluster.metadata.creationTimestamp} />
315+
) : (
316+
['-']
317+
)}
322318
</span>
323319
),
324320
exportContent: (discoveredCluster) => {

0 commit comments

Comments
 (0)