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

Migrate logs table to DataViews #99056

Draft
wants to merge 37 commits into
base: trunk
Choose a base branch
from
Draft

Conversation

oandregal
Copy link
Contributor

@oandregal oandregal commented Jan 29, 2025

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
  • Visit http://calypso.localhost:3000/sites.
  • Select a site to open the preview panel.
  • Select a site that has the "Logs" tab active (e.g.: atomic).
  • Verify that the table listing is using DataViews and works as expected.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • Have you written new tests for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
    • For UI changes, have we tested the change in various languages (for example, ES, PT, FR, or DE)? The length of text and words vary significantly between languages.
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-aUh-p2)?

@oandregal oandregal requested review from a team as code owners January 29, 2025 19:33
@oandregal oandregal requested a review from southp January 29, 2025 19:33
@matticbot matticbot added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Jan 29, 2025
@oandregal oandregal marked this pull request as draft January 29, 2025 19:33
@oandregal oandregal changed the base branch from trunk to renovate/wordpress-monorepo January 29, 2025 19:35
@oandregal oandregal changed the title Update/logs to dataviews Migrate logs table to DataViews Jan 29, 2025
@matticbot
Copy link
Contributor

matticbot commented Jan 29, 2025

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

Sections (~2557 bytes added 📈 [gzipped])

name        parsed_size           gzip_size
site-logs       +6654 B  (+0.5%)    +1288 B  (+0.3%)
site-tools      +6626 B  (+0.4%)    +1269 B  (+0.3%)

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.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@sirbrillig sirbrillig removed the request for review from a team January 29, 2025 20:51
// - DataViews: address the "show more" interaction.
// - DataViews: spacing left/right.

const { __ } = useI18n(); // Can we use translate instead?
Copy link
Member

@ntsekouras ntsekouras Jan 30, 2025

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? 🤔

Copy link
Contributor Author

@oandregal oandregal Jan 30, 2025

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.

Copy link
Member

@alshakero alshakero Jan 31, 2025

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.

Copy link
Contributor

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...

Copy link
Member

@tyxla tyxla Feb 6, 2025

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.

Copy link
Contributor

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).

Copy link
Member

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?

Copy link
Contributor

@chriskmnds chriskmnds Feb 7, 2025

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.

Copy link
Member

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.

Copy link
Contributor

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.

setView( ( oldView ) => ( {
...oldView,
...newView,
type: 'table' as const,
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Member

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.

@aneeshd16 aneeshd16 removed request for a team and southp January 30, 2025 20:59
Copy link
Member

@alshakero alshakero left a 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.

// - DataViews: address the "show more" interaction.
// - DataViews: spacing left/right.

const { __ } = useI18n(); // Can we use translate instead?
Copy link
Member

@alshakero alshakero Jan 31, 2025

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.

Comment on lines 361 to 272
const moment = useLocalizedMoment();
const getLatestDateRange = useCallback( () => {
const startTime = moment().subtract( 7, 'd' );
const endTime = moment();
return { startTime, endTime };
}, [ moment ] );
Copy link
Member

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..).

setView( ( oldView ) => ( {
...oldView,
...newView,
type: 'table' as const,
Copy link
Member

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.

Comment on lines 418 to 426
useEffect( () => {
setView( ( view ) => ( {
...view,
sort: {
field: getSortFieldForLogType( logType ),
},
fields: getVisibleFieldsForLogType( logType ),
} ) );
}, [ logType ] );
Copy link
Member

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';
Copy link
Member

@alshakero alshakero Jan 31, 2025

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"
Copy link
Member

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"
Copy link
Member

Choose a reason for hiding this comment

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

+1

@@ -251,3 +263,257 @@ export const SiteLogs = ( {
</div>
);
};

const EMPTY_ARRAY: Array< any > = [];
const useDataLogs = ( {
Copy link
Member

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.

@oandregal
Copy link
Contributor Author

Cross-posting status from p5j4vm-51h-p2#comment-7495.

Current status as of January 31st: all basic interactions are working.

  • The only major interaction missing is “expand row to read more”. The DataViews native approach would be implementing it via a modal action.
  • It needs style tweaks and fixes (spacing, date header, empty states for filters, etc.).
  • In terms of data filters & sorting, there’s parity with the existing implementation. The current endpoint doesn’t support sorting by fields other than the timestamp, searching by text, filtering by multiple values (e.g., “severity is any of: …”), or adding more filters (e.g., filter by kind or name) — some of these would be valuable, but I consider them follow-up PRs.
  • Code-wise, I just made it work. I’ve reused as many pieces as I could from the current implementation, but it’s not ready — I’ll address this next while design feedback comes.

@oandregal oandregal force-pushed the renovate/wordpress-monorepo branch from 65149e6 to a1297b3 Compare February 4, 2025 09:53
Base automatically changed from renovate/wordpress-monorepo to trunk February 4, 2025 11:21
@matt-west
Copy link
Contributor

Nice work so far @oandregal!

Spacing

It sounds like you’re already aware of this, but in the interest of being comprehensive, there are a couple spacing issues that need fixing:

  • The DataViews table should span the entire width of the content page. There’s currently some left + right padding.
  • The padding above the Logs title in the header is also inconsistent with other pages.

Auto-refresh

The auto-refresh option is missing. Is it possible to place this in the toolbar above the table?

image

Entry details behaviour

I’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?

Modal

We could add an action icon to the row that triggers a modal for viewing the full details related to a log entry.

image

Drawer

In 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.

image

Dropdown

This 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.

image

Educational tip

The 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.

Screenshot 2025-02-04 at 13 36 45

Cleaning up filters

We 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.

Screenshot 2025-02-04 at 13 38 40

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!)

Screenshot 2025-02-04 at 13 40 24

@oandregal oandregal force-pushed the update/logs-to-dataviews branch 2 times, most recently from 99ff7c1 to 8b02a4d Compare February 6, 2025 22:19
@matticbot
Copy link
Contributor

matticbot commented Feb 6, 2025

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • blaze-dashboard
  • notifications
  • odyssey-stats
  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug update/logs-to-dataviews on your sandbox.

@oandregal oandregal force-pushed the update/logs-to-dataviews branch from 8b02a4d to 34fbdd3 Compare February 7, 2025 12:01
@oandregal oandregal force-pushed the update/logs-to-dataviews branch from 34fbdd3 to d163e3f Compare February 7, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Sites [Status] In Progress [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Migrate the Logs table to DataViews
8 participants