-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Migrate logs table to DataViews #99056
base: trunk
Are you sure you want to change the base?
Conversation
Jetpack Cloud live (direct link)
Automattic for Agencies live (direct link)
|
Here is how your PR affects size of JS and CSS bundles shipped to the user's browser: Sections (~2557 bytes added 📈 [gzipped])
Sections contain code specific for a given set of routes. Is downloaded and parsed only when a particular route is navigated to. Legend What is parsed and gzip size?Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory. Generated by performance advisor bot at iscalypsofastyet.com. |
client/sites/tools/logs/index.tsx
Outdated
// - DataViews: address the "show more" interaction. | ||
// - DataViews: spacing left/right. | ||
|
||
const { __ } = useI18n(); // Can we use translate instead? |
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.
How about importing from @wordpress/i18n
? What the difference between importing, using translate
or useI18n
? 🤔
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.
No idea why we use one or the other (there's also a translate
call 🤷 ). Right now, I'm just trying to make things work following what the existing component chain does. Later, I'll dig into the details.
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.
@wordpress/i18n is non-Reactive. It works in most cases, but if you change the locale or download language files after rendering, without refreshing the page, the UI won't refresh. Whereas translate = useTranslate()
from calypso-i18n
and @wordpress/react-i18n
are both Reactive and will rerender the consumer when anything related to translations changes.
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.
As discussed with @tyxla and others, It's seems now there's more pros to using @wordpress/i18n
than calypso-i18n
. Should we be doing a P2 post on this to get everyone on the same page and understand the long term plan / migration...
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.
Just to cnfirm, as @alshakero mentioned, In React context, we should be using { useI18n } from '@wordpress/react-i18n'
instead of @wordpress/i18n
to benefit from the changes in locale or async loaded translation chunks. @wordpress/i18n
is preferred only in non-React context. I did talk about it here.
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.
As discussed with @tyxla and others, It's seems now there's more pros to using @wordpress/i18n than calypso-i18n. Should we be doing a P2 post on this to get everyone on the same page and understand the long term plan / migration...
Interesting. Can you point me to where these discussions took place. I was/am under a different impression, also judging from the sentiment I got in a similar discussion pxLjZ-9Eg-p2
I've recently dealt with dozens of translation issues primarily stemming from devs using a variety of i18n formatters, either not having the same locale or even the right locale internally. It explicitly concerned numbers, but numbers are just as important. Having all these packages available for similar (but not identical) purposes isn't serving the goal.
As far as numbers go, I am unifying everything behind a single method: pxLjZ-9Ji-p2 And that method currently lives in i18n-calypso
. I am not even sure if I will pull it out right now, as the alternatives aren't exactly better. @wordpress/i18n
isn't reactive, @wordpress/react-18n
is an extremely minimal package, @automattic/i18n-utils
doesn't deal with internal state/locale definition, etc.
I would 100% urge everyone, for now, to stick with i18n-calypso in Calypso until we work out the replacement (if we ever do). Just "using another" without proper migration isn't helping the code, and, judging from what I've seen the past couple of weeks, it's not helping the user either (and it slipped from everyone's eyes for a long 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 may be missing something, but I don't understand why we need to be bound to i18n-calypso
for number formatting. Yes, that's where the old utility function was before, but is that a good enough reason? What prevents us from moving closer to step 4 of your original proposal, and instead of having to bind number formatting to i18n-calypso
, build it separately, and just allow it to take a locale in addition to the desired format? If we can make number formatting independent, then we would be able to use it with both i18n-calypso
and @wordpress/i18n
and @wordpress/react-i18n
?
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.
Well we are a couple of dozens of bugs ahead of my original proposal, all/most stemming from locale issues. Some similar situation exists (but not issues per se) with the JP formatter.
In my ideal scenario right now, numberFormat
works as translate
, with internal locale state. My fear with the alternative, of passing a browser-safe locale, is it won't be effective. People will insist on passing ant locale to it.
So internal locale state handling + optional locale param to encompass JP is what I'm shooting for. Make (keep) it stupid easy for most cases, expansive for others.
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.
Got it. In any case, separating the browser-safe locale retrieval from i18n-calypso
is something we can solve in the future. It's not a blocker for this PR, since all the works happens in Calypso's client and using i18n-calypso
is still fine.
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.
Yes, we'll come back to it. Not meaning this as a blocker. It just caught my attention, fighting with similar things.
A separate package imported into i18n-calypso
(to wrap the calls with its locale state) might be right. wp-calypso will continue using it from there, never import it separately. There's also a lot going on around setLocale
, not sure what it would mean to abstract it out somehow instead.
client/sites/tools/logs/index.tsx
Outdated
setView( ( oldView ) => ( { | ||
...oldView, | ||
...newView, | ||
type: 'table' as const, |
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.
Do we need this?
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.
Yes, if you don't add as const
, TS will view type
as a mutable string
and dataviews expect strictly table
, grid
and two other values I can't recall.
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.
Hi everyone! Just a drive by review trying to help and learn about dataviews.
client/sites/tools/logs/index.tsx
Outdated
// - DataViews: address the "show more" interaction. | ||
// - DataViews: spacing left/right. | ||
|
||
const { __ } = useI18n(); // Can we use translate instead? |
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.
@wordpress/i18n is non-Reactive. It works in most cases, but if you change the locale or download language files after rendering, without refreshing the page, the UI won't refresh. Whereas translate = useTranslate()
from calypso-i18n
and @wordpress/react-i18n
are both Reactive and will rerender the consumer when anything related to translations changes.
client/sites/tools/logs/index.tsx
Outdated
const moment = useLocalizedMoment(); | ||
const getLatestDateRange = useCallback( () => { | ||
const startTime = moment().subtract( 7, 'd' ); | ||
const endTime = moment(); | ||
return { startTime, endTime }; | ||
}, [ moment ] ); |
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 don't want to make your life harder. But@wordpress/dataviews is 340KB gzipped and moment is 73KB gzipped. It would be amazing if we follow up with some performance considerations (eg async loading, not using moment, etc..).
client/sites/tools/logs/index.tsx
Outdated
setView( ( oldView ) => ( { | ||
...oldView, | ||
...newView, | ||
type: 'table' as const, |
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.
Yes, if you don't add as const
, TS will view type
as a mutable string
and dataviews expect strictly table
, grid
and two other values I can't recall.
client/sites/tools/logs/index.tsx
Outdated
useEffect( () => { | ||
setView( ( view ) => ( { | ||
...view, | ||
sort: { | ||
field: getSortFieldForLogType( logType ), | ||
}, | ||
fields: getVisibleFieldsForLogType( logType ), | ||
} ) ); | ||
}, [ logType ] ); |
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.
From what I see here, having view
as a state is making your life harder. Maybe make all its dependencies states but the view itself can be a constructed in the end before returning.
const view = {
type: 'table' as const,
sort: { field: getSortFieldForLogType( logType ) },
fields: getVisibleFieldsForLogType( logType ),
}
import { sprintf } from '@wordpress/i18n'; | ||
import { useI18n } from '@wordpress/react-i18n'; | ||
import { translate } from 'i18n-calypso'; |
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 would use useTranslate
instead. See why here.
<span>{ translate( 'From' ) }</span> | ||
<DateTimePicker | ||
className="site-logs-toolbar__datepicker" | ||
id="from" |
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.
Do we need the id if it's wrapped by the label?
<span>{ translate( 'To' ) }</span> | ||
<DateTimePicker | ||
className="site-logs-toolbar__datepicker" | ||
id="to" |
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.
+1
client/sites/tools/logs/index.tsx
Outdated
@@ -251,3 +263,257 @@ export const SiteLogs = ( { | |||
</div> | |||
); | |||
}; | |||
|
|||
const EMPTY_ARRAY: Array< any > = []; | |||
const useDataLogs = ( { |
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 would put this in a separate file.
Cross-posting status from p5j4vm-51h-p2#comment-7495. Current status as of January 31st: all basic interactions are working.
|
65149e6
to
a1297b3
Compare
Nice work so far @oandregal! SpacingIt sounds like you’re already aware of this, but in the interest of being comprehensive, there are a couple spacing issues that need fixing:
Auto-refreshThe auto-refresh option is missing. Is it possible to place this in the toolbar above the table? Entry details behaviourI’ve explored a few different ways we can show the details for a specific log entry. I suspect the modal approach will be the easiest to implement short-term as it doesn’t require changes to DataViews. I’m quite taken by the drawer approach though. What do you think? ModalWe could add an action icon to the row that triggers a modal for viewing the full details related to a log entry. DrawerIn this approach clicking a log entry would pop-up a drawer at the bottom of the content pane with the full details. Users could resize and close this drawer as they wish. (Sort of like browser dev tools) Adding the drawer starts to make the content pane feel really crowded. Some of this will be relieved with the upcoming changes that simplify the site header and hide the sites list though. DropdownThis approach restores the current behaviour where selecting a log entry expands the row to display the full details. A nice advantage of this approach is that you can expand and compare multiple entries at the same time. Educational tipThe filter icon above the table can be easily missed, so I think it warrants spotlighting that some of the filters have moved. We’ve used a similar component before so hopefully there's something you can reuse. ![]() Cleaning up filtersWe current have filters spread over multiple levels which is not ideal. I think this is a limitation of current DataViews capabilities, but just wanted to call it out. ![]() In the future it would be nice if we could integrate the date pickers into the toolbar to clean up the filters. I don't think DataViews supports this at the moment though. (Please correct me if I’m wrong!) ![]() |
99ff7c1
to
8b02a4d
Compare
This PR modifies the release build for the following Calypso Apps: For info about this notification, see here: PCYsg-OT6-p2
To test WordPress.com changes, run |
8b02a4d
to
34fbdd3
Compare
34fbdd3
to
d163e3f
Compare
WORK IN PROGRESS: NOT TO MERGE.
Proposed Changes
Updates the existing log table list to use DataViews
Why are these changes being made?
We want to consolidate the listing interactions across our products into a single experience powered by DataViews.
Testing Instructions
yarn && yarn start
http://calypso.localhost:3000/sites
.Pre-merge Checklist