-
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): add AbsoluteTimestamp component, use in ArtifactD…
…etail
- Loading branch information
Erik Munson
committed
Sep 30, 2020
1 parent
9419811
commit fe79e8c
Showing
2 changed files
with
37 additions
and
9 deletions.
There are no files selected for viewing
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