-
Notifications
You must be signed in to change notification settings - Fork 900
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core/managed): switch to abbreviated timestamp format, add versi…
…on timestamps (#8610) * feat(core/managed): add RelativeTimestamp component * feat(core/managed): show createdAt timestamp on versions * feat(core/managed): use RelativeTimestamp for environment cards * feat(core/managed): add click to copy on created timestamp * feat(core/managed): add AbsoluteTimestamp component, use in ArtifactDetail Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
012b004
commit 34bc7e9
Showing
9 changed files
with
195 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
app/scripts/modules/core/src/managed/AbsoluteTimestamp.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { memo } from 'react'; | ||
import { DateTime } from 'luxon'; | ||
|
||
import { SETTINGS } from '../config'; | ||
import { CopyToClipboard } from '../utils'; | ||
|
||
export interface IAbsoluteTimestampProps { | ||
timestamp: DateTime; | ||
clickToCopy?: boolean; | ||
} | ||
|
||
const TIMEZONE = SETTINGS.feature.displayTimestampsInUserLocalTime ? undefined : SETTINGS.defaultTimeZone; | ||
|
||
export const AbsoluteTimestamp = memo( | ||
({ timestamp: timestampInOriginalZone, clickToCopy }: IAbsoluteTimestampProps) => { | ||
const timestamp = timestampInOriginalZone.setZone(TIMEZONE); | ||
|
||
const fullTimestamp = timestamp.toFormat('yyyy-MM-dd HH:mm:ss ZZZZ'); | ||
const formattedTimestamp = timestamp.toFormat('MMM d, y HH:mm'); | ||
const timestampElement = <span>{formattedTimestamp}</span>; | ||
|
||
if (clickToCopy) { | ||
return ( | ||
<span> | ||
{timestampElement} | ||
<CopyToClipboard text={fullTimestamp} toolTip={`${fullTimestamp} (click to copy)`} /> | ||
</span> | ||
); | ||
} else { | ||
return timestampElement; | ||
} | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
app/scripts/modules/core/src/managed/RelativeTimestamp.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { memo, useEffect, useState } from 'react'; | ||
import { DateTime, Duration } from 'luxon'; | ||
|
||
import { SETTINGS } from '../config'; | ||
import { CopyToClipboard } from '../utils'; | ||
import { useInterval, Tooltip } from '../presentation'; | ||
|
||
export interface IRelativeTimestampProps { | ||
timestamp: DateTime; | ||
clickToCopy?: boolean; | ||
} | ||
|
||
const TIMEZONE = SETTINGS.feature.displayTimestampsInUserLocalTime ? undefined : SETTINGS.defaultTimeZone; | ||
|
||
const formatTimestamp = (timestamp: DateTime, distance: Duration) => { | ||
if (distance.years || distance.months) { | ||
if (timestamp.year === DateTime.local().setZone(TIMEZONE).year) { | ||
return timestamp.toFormat('MMM d'); | ||
} else { | ||
return timestamp.toFormat('MMM d, y'); | ||
} | ||
} else if (distance.days) { | ||
return distance.toFormat('d') + 'd'; | ||
} else if (distance.hours) { | ||
return distance.toFormat('h') + 'h'; | ||
} else if (distance.minutes) { | ||
return distance.toFormat('m') + 'm'; | ||
} else if (distance.seconds) { | ||
return distance.toFormat('s') + 's'; | ||
} else { | ||
return null; | ||
} | ||
}; | ||
|
||
const getDistanceFromNow = (timestamp: DateTime) => | ||
timestamp.diffNow().negate().shiftTo('years', 'months', 'days', 'hours', 'minutes', 'seconds'); | ||
|
||
export const RelativeTimestamp = memo( | ||
({ timestamp: timestampInOriginalZone, clickToCopy }: IRelativeTimestampProps) => { | ||
const timestamp = timestampInOriginalZone.setZone(TIMEZONE); | ||
const [formattedTimestamp, setFormattedTimestamp] = useState( | ||
formatTimestamp(timestamp, getDistanceFromNow(timestamp)), | ||
); | ||
|
||
const updateTimestamp = () => { | ||
setFormattedTimestamp(formatTimestamp(timestamp, getDistanceFromNow(timestamp))); | ||
}; | ||
|
||
useInterval(updateTimestamp, 1000); | ||
useEffect(updateTimestamp, [timestamp]); | ||
|
||
if (!formattedTimestamp) { | ||
return null; | ||
} | ||
|
||
const absoluteTimestamp = timestamp.toFormat('yyyy-MM-dd HH:mm:ss ZZZZ'); | ||
const relativeTimestamp = ( | ||
<span className="text-regular text-italic" style={{ fontSize: 13, lineHeight: 1 }}> | ||
{formattedTimestamp} | ||
</span> | ||
); | ||
|
||
if (clickToCopy) { | ||
return ( | ||
<CopyToClipboard | ||
buttonInnerNode={relativeTimestamp} | ||
text={absoluteTimestamp} | ||
toolTip={`${absoluteTimestamp} (click to copy)`} | ||
/> | ||
); | ||
} else { | ||
return <Tooltip value={absoluteTimestamp}>{relativeTimestamp}</Tooltip>; | ||
} | ||
}, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.