Skip to content
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

Add two-line timestamp and remove dayjs #1333

Merged
merged 5 commits into from
Feb 17, 2022
Merged

Add two-line timestamp and remove dayjs #1333

merged 5 commits into from
Feb 17, 2022

Conversation

rogermparent
Copy link
Contributor

@rogermparent rogermparent commented Feb 17, 2022

This PR changes the experiment table's timestamp format to have two lines, one prominent one with the time and a smaller sub-line below it with the date. We've talked in meetings about using a consistent timestamp between products, but from looking at those products (DVC CLI and Studio) it seems like most use the date format we've had previously so whatever we go with will need to be something new.

The formatting is also changed to use native JS Date and its toLocaleDate and toLocaleTime methods. Since this removes the last remaining usage of dayjs, this PR also removes the library. The logic of using different formats depending on whether the date is today or before is also removed, and all dates are now displayed consistently regardless of their position relative to the current day.

I'm absolutely open to any criticism and/or requested changes, this is just a shot in the dark from what I assume would be a good way to display all the necessary information.

Newest demo:

new-timestamp-demo.mp4

Old demo:

new-timestamp-demo.mp4

Fixes #1270

@rogermparent rogermparent self-assigned this Feb 17, 2022
@rogermparent rogermparent added the product PR that affects product label Feb 17, 2022
Comment on lines +61 to +62
overflow: hidden;
text-overflow: ellipsis;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes ellipsis truncation in the nested timestamp divs

@@ -519,6 +521,7 @@ $spinner-color-light: #000;
padding: 0 $cell-padding;
align-items: center;
width: 100%;
height: 100%;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes vertical centering in cells whose contents aren't full height via line-height

Copy link
Member

@mattseddon mattseddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, some thoughts:

  1. Cli output time is 0 padded:

Screen Shot 2022-02-17 at 12 38 36 pm

  1. Left/right truncation of the Timestamp header/column looks odd (especially next to Experiments header):

Screen Shot 2022-02-17 at 12 38 26 pm

@mattseddon
Copy link
Member

For 2. probably makes more sense to change the header.

Comment on lines +28 to +35
const timeFormatter = new Intl.DateTimeFormat([], {
hour: '2-digit',
minute: '2-digit'
})
const dateFormatter = new Intl.DateTimeFormat([], {
dateStyle: 'medium'
})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -73,16 +80,21 @@ const getColumns = (columns: MetricOrParam[]): Column<Experiment>[] =>
if (!value || value === '') {
return null
}
const time = dayjs(value)
const date = new Date(value)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to push this further up into data parsing, but this will do for now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep definitely move it in case we need to use this timestamp somewhere else. We should also standardise all dates in the extension to look the same.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can follow up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do the follow-up for pushing new Date up into webview parsing, I'm not sure where else we display date timestamps though.

Comment on lines -76 to +89
<div className={styles.headerCellContentsWrapper}>
<span
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
data-testid="rendered-header"
style={provided.draggableProps.style}
className={cx(styles.cellContents, {
[styles.draggingColumn]: snapshot.isDragging,
[styles.staticColumn]: !snapshot.isDragging,
[styles.isDroppedColumn]: snapshot.isDropAnimating
})}
>
{column.render('Header')}
</span>
</div>
<span
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
data-testid="rendered-header"
style={provided.draggableProps.style}
className={cx(styles.cellContents, {
[styles.draggingColumn]: snapshot.isDragging,
[styles.staticColumn]: !snapshot.isDragging,
[styles.isDroppedColumn]: snapshot.isDropAnimating
})}
>
{column.render('Header')}
</span>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headerCellContentWrapper is pushed into header render functions so it can be left off of Timestamp to enable selective rtl/ltr truncation.

Comment on lines 34 to 38
return (
<div className={styles.headerCellContentsWrapper}>
<span title={name}>{name}</span>
</div>
)
Copy link
Contributor Author

@rogermparent rogermparent Feb 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headerCellContentsWrapper pushed here to apply to all normal headers.

@rogermparent
Copy link
Contributor Author

rogermparent commented Feb 17, 2022

  1. Cli output time is 0 padded:

  2. Left/right truncation of the Timestamp header/column looks odd (especially next to Experiments header):

For 2. probably makes more sense to change the header.

@mattseddon Good points! I did 1 with a slight tweak to time formatter options and 2 with a slightly larger refactor. On the same line of thought as matching CLI, I changed the date formatting to MMM, DD, YYYY like CLI has:
image

@sroy3
Copy link
Contributor

sroy3 commented Feb 17, 2022

Screen.Recording.2022-02-17.at.10.36.02.AM.mov

From the UI tests, seems like the header of experiment and timestamp aren't aligned vertically anymore.

@codeclimate
Copy link

codeclimate bot commented Feb 17, 2022

Code Climate has analyzed commit 6e78980 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (85% is the threshold).

This pull request will bring the total coverage in the repository to 96.2% (0.0% change).

View more on Code Climate.

@rogermparent
Copy link
Contributor Author

I re-added the same padding that normal headers have to the Experiment and Timestamp cells, then grabbed a screenshot from the latest Chromatic build to ensure that Timestamp and Experiment cells are now at the same vertical alignment:

image

There's still a diff highlight, I guess because the baseline got updated to the previous commit, but from that check I'd say the issue's been solved. Thanks for pointing it out @sroy3!

@rogermparent
Copy link
Contributor Author

Accepted the latest Chromatic diff myself and will merge, still open to any further changes in follow-ups!

@rogermparent rogermparent merged commit 9a53621 into master Feb 17, 2022
@rogermparent rogermparent deleted the new-timestamp branch February 17, 2022 19:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product PR that affects product
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Formatting for timestamps
3 participants