-
Notifications
You must be signed in to change notification settings - Fork 15
Convert date cell to single line #2153
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
app/table/columns/common.tsx
Outdated
| <span>{format(date, 'PP')}</span> | ||
| <span className="text-quaternary">{format(date, 'p')}</span> | ||
| </time> | ||
| ) |
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.
I'm realizing date-fns is very literal and doesn't seem to do any locale-based formatting. I think we should use toLocaleString() and get decent results, i.e., the same as we're currently getting in English but better for other languages. Something like this:
const dateStr = date.toLocaleString(undefined, { month: 'short', day: 'numeric', year: 'numeric' })
const timeStr = date.toLocaleString(undefined, { hour: 'numeric', minute: 'numeric' }))
In the math function we use navigator.language where I've put undefined here, but it seems like undefined is really the right way. The only problem is that the way I've tested this is to mock navigator.language, so if we use undefined instead that approach won't work in the tests. Maybe we should be using playwright instead to test the locale rendering. They make it really easy:
import { test, expect } from '@playwright/test';
test.describe('french language block', () => {
test.use({ locale: 'fr-FR' });
test('example', async ({ page }) => {
// ...
});
});https://playwright.dev/docs/test-use-options#configuration-scopes
To summarize, I think you should:
- Replace these
date-fnsformatcalls withtoLocaleString(undefined, ...) - Check a displayed date in exactly one table in
de-DEor whatever using the Playwright local setting feature - Don't worry about the number formatting functions, I'll make an issue to switch those to use
undefinedinstead ofnavigator.languageand change the way we test it
app/components/TimeAgo.tsx
Outdated
| <div className="flex flex-col"> | ||
| <span className="text-tertiary">{tooltipText}</span> | ||
| <span>{format(datetime, 'MMM d, yyyy p')}</span> | ||
| <span>{toLocaleDateString(datetime)}</span> |
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.
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.
| <span>{toLocaleDateString(date, locale)}</span> | ||
| <span className="text-quaternary">{toLocaleTimeString(date, locale)}</span> | ||
| </time> | ||
| ) |
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.
stylish
|
I have a few Playwright tests to update as well; coming soonish |
david-crespo
left a comment
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.
Looks great! Tests should be simple, I think just looking at one page where there is a date should be fine.
app/util/date.ts
Outdated
| const timeOptions = { | ||
| hour: 'numeric', | ||
| minute: 'numeric', | ||
| } satisfies Intl.DateTimeFormatOptions |
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.
Heh, check this out: I was just reading the MDN page and noticed the style shortcuts section: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#datestyle
I think we can reduce these to timeStyle: 'short' and dateStyle: 'medium'! That is clean.
const dateOptions = { dateStyle: 'medium' } satisfies Intl.DateTimeFormatOptions
const timeOptions = { timeStyle: 'short' } satisfies Intl.DateTimeFormatOptions
Oddly it does change both the German and Japanese results. Seems fine to me?
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.
Oh, interesting. Funny that it changes the German syntax. I don't have strong feelings on it, but agree the shorter configuration syntax is nice. Will get that in.
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.
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.
Even though it looks worse (maybe) I like the idea of taking the details out of our hands — in theory they should know better than we do what’s idiomatic in each locale.
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.
Makes sense; I agree with that.
oxidecomputer/console@2ba444c...6334f0d * [6334f0db](oxidecomputer/console@6334f0db) bump omicron to latest main (no changes) * [46dbd9c8](oxidecomputer/console@46dbd9c8) oxidecomputer/console#2158 * [e94929ab](oxidecomputer/console@e94929ab) try 300ms minTime on RefreshButton SpinnerLoader * [b6da4154](oxidecomputer/console@b6da4154) oxidecomputer/console#2161 * [788389a8](oxidecomputer/console@788389a8) oxidecomputer/console#2157 * [fed9f4d4](oxidecomputer/console@fed9f4d4) oxidecomputer/console#2159 * [aa75f577](oxidecomputer/console@aa75f577) oxidecomputer/console#2160 * [eeb32a78](oxidecomputer/console@eeb32a78) oxidecomputer/console#2153 * [522d3ab1](oxidecomputer/console@522d3ab1) oxidecomputer/console#2156 * [c726356f](oxidecomputer/console@c726356f) oxidecomputer/console#2155 * [e2b0a7d0](oxidecomputer/console@e2b0a7d0) oxidecomputer/console#2151 * [a5af899a](oxidecomputer/console@a5af899a) oxidecomputer/console#2154 * [73263a4e](oxidecomputer/console@73263a4e) of course I didn't push to main without running the tests, why do you ask * [ea108b7e](oxidecomputer/console@ea108b7e) put firewall rules tab first on vpc detail
oxidecomputer/console@2ba444c...6334f0d * [6334f0db](oxidecomputer/console@6334f0db) bump omicron to latest main (no changes) * [46dbd9c8](oxidecomputer/console@46dbd9c8) oxidecomputer/console#2158 * [e94929ab](oxidecomputer/console@e94929ab) try 300ms minTime on RefreshButton SpinnerLoader * [b6da4154](oxidecomputer/console@b6da4154) oxidecomputer/console#2161 * [788389a8](oxidecomputer/console@788389a8) oxidecomputer/console#2157 * [fed9f4d4](oxidecomputer/console@fed9f4d4) oxidecomputer/console#2159 * [aa75f577](oxidecomputer/console@aa75f577) oxidecomputer/console#2160 * [eeb32a78](oxidecomputer/console@eeb32a78) oxidecomputer/console#2153 * [522d3ab1](oxidecomputer/console@522d3ab1) oxidecomputer/console#2156 * [c726356f](oxidecomputer/console@c726356f) oxidecomputer/console#2155 * [e2b0a7d0](oxidecomputer/console@e2b0a7d0) oxidecomputer/console#2151 * [a5af899a](oxidecomputer/console@a5af899a) oxidecomputer/console#2154 * [73263a4e](oxidecomputer/console@73263a4e) of course I didn't push to main without running the tests, why do you ask * [ea108b7e](oxidecomputer/console@ea108b7e) put firewall rules tab first on vpc detail






We're working to tighten up the data tables (vertically), so are moving the date cell from two lines to one line.
Currently, it looks like this:

With this PR, it now looks like this:

On smaller screens, the date wraps:
