-
Notifications
You must be signed in to change notification settings - Fork 2
Add local and utc popper to logs
#1970
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4ae70eb
Adding local and utc time on hover for logs
travjenkins d3a6095
Delay opening so they don't get spammed when moving mouse across screen
travjenkins 7b8b66c
switching time to mono like the other text
travjenkins 098c052
more accurate typing
travjenkins fc094cf
Making the html a _tad_ more semantic
travjenkins e8a1f09
Commenting why this is needed
travjenkins a92775e
Ensuring dates are valid
travjenkins 8a73a07
this should not be needed
travjenkins File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,93 @@ | ||
| import type { PopperProps } from '@mui/material'; | ||
| import type { MouseEvent, ReactNode } from 'react'; | ||
|
|
||
| import { useEffect, useRef, useState } from 'react'; | ||
|
|
||
| import { Box } from '@mui/material'; | ||
|
|
||
| import PopperWrapper from 'src/components/shared/PopperWrapper'; | ||
|
|
||
| interface Props { | ||
| children: ReactNode; | ||
| popperContent: ReactNode; | ||
| popperProps?: Partial<PopperProps>; | ||
| } | ||
|
|
||
| // Delay before opening so quick mouse-overs don't flash the popper. | ||
| const OPEN_DELAY_MS = 35; | ||
|
|
||
| // Delay before closing so the mouse can travel from the anchor into the popper | ||
| // without it disappearing. The popper renders in a portal so there is no DOM | ||
| // parent/child relationship between the two. | ||
| const CLOSE_DELAY_MS = 100; | ||
|
|
||
| function HoverPopper({ children, popperContent, popperProps }: Props) { | ||
| const [open, setOpen] = useState(false); | ||
| const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null); | ||
| const openTimer = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
| const closeTimer = useRef<ReturnType<typeof setTimeout> | null>(null); | ||
|
|
||
| const clearOpenTimer = () => { | ||
| if (openTimer.current !== null) { | ||
| clearTimeout(openTimer.current); | ||
| openTimer.current = null; | ||
| } | ||
| }; | ||
|
|
||
| const clearCloseTimer = () => { | ||
| if (closeTimer.current !== null) { | ||
| clearTimeout(closeTimer.current); | ||
| closeTimer.current = null; | ||
| } | ||
| }; | ||
|
|
||
| const scheduleClose = () => { | ||
| clearOpenTimer(); | ||
| clearCloseTimer(); | ||
| closeTimer.current = setTimeout(() => setOpen(false), CLOSE_DELAY_MS); | ||
| }; | ||
|
|
||
| const handleAnchorEnter = (event: MouseEvent<HTMLElement>) => { | ||
| clearCloseTimer(); | ||
| const target = event.currentTarget; | ||
| openTimer.current = setTimeout(() => { | ||
| setAnchorEl(target); | ||
| setOpen(true); | ||
| }, OPEN_DELAY_MS); | ||
| }; | ||
|
|
||
| useEffect( | ||
| () => () => { | ||
| clearOpenTimer(); | ||
| clearCloseTimer(); | ||
| }, | ||
| [] | ||
| ); | ||
|
|
||
| return ( | ||
| <> | ||
| <Box | ||
| component="span" | ||
| onMouseEnter={handleAnchorEnter} | ||
| onMouseLeave={scheduleClose} | ||
| > | ||
| {children} | ||
| </Box> | ||
| <PopperWrapper | ||
| anchorEl={anchorEl} | ||
| open={open} | ||
| setOpen={setOpen} | ||
| popperProps={popperProps} | ||
| > | ||
| <Box | ||
| onMouseEnter={clearCloseTimer} | ||
| onMouseLeave={scheduleClose} | ||
| > | ||
| {popperContent} | ||
| </Box> | ||
| </PopperWrapper> | ||
| </> | ||
| ); | ||
| } | ||
|
|
||
| export default HoverPopper; |
This file contains hidden or 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 hidden or 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,85 @@ | ||
| import type { DateTime } from 'luxon'; | ||
|
|
||
| import { Fragment } from 'react'; | ||
|
|
||
| import { Box, Divider, Typography } from '@mui/material'; | ||
|
|
||
| import { useIntl } from 'react-intl'; | ||
|
|
||
| import SingleLineCode from 'src/components/content/SingleLineCode'; | ||
| import { LOGS_DATE_FORMAT } from 'src/components/tables/cells/logs/shared'; | ||
|
|
||
| interface Props { | ||
| dateTime: DateTime; | ||
| showRelative?: boolean; | ||
| } | ||
|
|
||
| const labelSx = { | ||
| color: 'text.secondary', | ||
| fontWeight: 500, | ||
| textTransform: 'uppercase', | ||
| } as const; | ||
|
|
||
| interface Row { | ||
| labelId: string; | ||
| getValue: (dt: DateTime) => string; | ||
| } | ||
|
|
||
| const rows: Row[] = [ | ||
| { | ||
| labelId: 'common.timestamp.local.label', | ||
| getValue: (dt) => dt.toLocal().toFormat(LOGS_DATE_FORMAT), | ||
| }, | ||
| { | ||
| labelId: 'common.timestamp.utc.label', | ||
| getValue: (dt) => dt.toUTC().toFormat(LOGS_DATE_FORMAT), | ||
| }, | ||
| ]; | ||
|
|
||
| function TimestampPopperContent({ dateTime, showRelative }: Props) { | ||
| const intl = useIntl(); | ||
|
|
||
| return ( | ||
| <Box | ||
| onClick={(e) => e.stopPropagation()} // Make sure we stop otherwise the row is opened | ||
| component="dl" | ||
| sx={{ | ||
| 'alignItems': 'baseline', | ||
| 'display': 'grid', | ||
| 'gap': '2px 12px', | ||
| 'gridTemplateColumns': 'auto 1fr', | ||
| 'm': 0, | ||
| '& dd': { m: 0 }, | ||
| }} | ||
| > | ||
| {rows.map(({ labelId, getValue }) => ( | ||
| <Fragment key={labelId}> | ||
| <Typography component="dt" variant="caption" sx={labelSx}> | ||
| {intl.formatMessage({ id: labelId })} | ||
| </Typography> | ||
|
|
||
| <dd> | ||
| <SingleLineCode compact value={getValue(dateTime)} /> | ||
| </dd> | ||
| </Fragment> | ||
| ))} | ||
| {showRelative ? ( | ||
| <> | ||
| <Divider sx={{ gridColumn: '1 / -1', my: 0.5 }} /> | ||
| <Typography component="dt" /> | ||
| <Typography | ||
| component="dd" | ||
| sx={{ | ||
| m: 0, | ||
| textAlign: 'right', | ||
| }} | ||
| > | ||
| {dateTime.toRelative({ style: 'narrow' })} | ||
| </Typography> | ||
| </> | ||
| ) : null} | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| export default TimestampPopperContent; | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,26 +1,43 @@ | ||
| import { TableCell, Typography } from '@mui/material'; | ||
| import { Chip, TableCell } from '@mui/material'; | ||
|
|
||
| import { DateTime } from 'luxon'; | ||
|
|
||
| import HoverPopper from 'src/components/shared/HoverPopper'; | ||
| import TimestampPopperContent from 'src/components/shared/TimestampPopperContent'; | ||
| import { | ||
| BaseCellSx, | ||
| BaseTypographySx, | ||
| LOGS_DATE_FORMAT, | ||
| } from 'src/components/tables/cells/logs/shared'; | ||
|
|
||
| interface Props { | ||
| ts: string; | ||
| } | ||
|
|
||
| function TimestampCell({ ts }: Props) { | ||
| const formattedDateTime = DateTime.fromISO(ts, { | ||
| zone: 'UTC', | ||
| }).toFormat('yyyy-LL-dd HH:mm:ss.SSS ZZZZ'); | ||
| const dt = DateTime.fromISO(ts, { zone: 'UTC' }); | ||
|
|
||
| if (!dt.isValid) { | ||
| return <TableCell sx={BaseCellSx} component="div" />; | ||
| } | ||
|
|
||
| const formattedDateTime = dt.toFormat(LOGS_DATE_FORMAT); | ||
|
|
||
| return ( | ||
| <TableCell sx={BaseCellSx} component="div"> | ||
| <Typography noWrap sx={BaseTypographySx}> | ||
| {formattedDateTime.includes('Invalid') ? '' : formattedDateTime} | ||
| </Typography> | ||
| <HoverPopper | ||
| popperContent={ | ||
| <TimestampPopperContent dateTime={dt} showRelative /> | ||
| } | ||
| popperProps={{ placement: 'right' }} | ||
| > | ||
| <Chip | ||
| sx={BaseTypographySx} | ||
| label={formattedDateTime} | ||
| size="small" | ||
| variant="outlined" | ||
| /> | ||
|
Comment on lines
+34
to
+39
Member
Author
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. Switch to chip to maybe drive people to view timestamp as interactable |
||
| </HoverPopper> | ||
| </TableCell> | ||
| ); | ||
| } | ||
|
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| export const BaseTypographySx = { fontFamily: 'Monospace', textWrap: 'nowrap' }; | ||
| export const BaseCellSx = { maxWidth: 'min-content', py: 0 }; | ||
|
|
||
| export const LOGS_DATE_FORMAT = 'yyyy-LL-dd HH:mm:ss.SSS ZZZZ'; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This isn't perfect - but makes this line sliiiiightly more semantic