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

Enhancement/2940 migrate storybook #3230

Merged
merged 33 commits into from
May 24, 2021

Conversation

asvinb
Copy link
Collaborator

@asvinb asvinb commented Apr 27, 2021

Summary

Addresses issue #2940

Relevant technical choices

  • Renamed the file DashboardSearchVisitorsWidget.js to DashboardUniqueVisitorsWidget.js since the latter exported the DashboardUniqueVisitorsWidget component.
  • WidgetAreaRenderer is being used in individual stories decorators as opposed to component decorators. No data flows in if it's the latter.
  • Updated the tests for modules to exclude *.stories.js files

Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 4.7 and PHP 5.6.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

@google-cla google-cla bot added the cla: yes label Apr 27, 2021
@asvinb asvinb marked this pull request as ready for review April 27, 2021 10:35
@github-actions
Copy link

github-actions bot commented Apr 27, 2021

Size Change: +1.23 kB (0%)

Total Size: 1.3 MB

Filename Size Change
./dist/assets/js/googlesitekit-activation.********************.js 35.5 kB +21 B (0%)
./dist/assets/js/googlesitekit-adminbar.********************.js 67.5 kB +29 B (0%)
./dist/assets/js/googlesitekit-api.********************.js 9.41 kB +18 B (0%)
./dist/assets/js/googlesitekit-dashboard-details.********************.js 79.1 kB +33 B (0%)
./dist/assets/js/googlesitekit-dashboard-splash.********************.js 49.4 kB +23 B (0%)
./dist/assets/js/googlesitekit-dashboard.********************.js 79.8 kB +31 B (0%)
./dist/assets/js/googlesitekit-datastore-forms.********************.js 9.09 kB +20 B (0%)
./dist/assets/js/googlesitekit-datastore-site.********************.js 12.6 kB +107 B (+1%)
./dist/assets/js/googlesitekit-datastore-ui.********************.js 9.04 kB +19 B (0%)
./dist/assets/js/googlesitekit-datastore-user.********************.js 16 kB +8 B (0%)
./dist/assets/js/googlesitekit-module.********************.js 79.9 kB +31 B (0%)
./dist/assets/js/googlesitekit-modules-adsense.********************.js 57.3 kB +165 B (0%)
./dist/assets/js/googlesitekit-modules-analytics-4.********************.js 16.9 kB +19 B (0%)
./dist/assets/js/googlesitekit-modules-analytics.********************.js 63.3 kB +176 B (0%)
./dist/assets/js/googlesitekit-modules-idea-hub.********************.js 11.4 kB +20 B (0%)
./dist/assets/js/googlesitekit-modules-optimize.********************.js 17.6 kB +32 B (0%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights.********************.js 24.3 kB +16 B (0%)
./dist/assets/js/googlesitekit-modules-search-console.********************.js 28.1 kB +24 B (0%)
./dist/assets/js/googlesitekit-modules-tagmanager.********************.js 31.6 kB +21 B (0%)
./dist/assets/js/googlesitekit-modules.********************.js 17.2 kB +20 B (0%)
./dist/assets/js/googlesitekit-settings.********************.js 87.2 kB +29 B (0%)
./dist/assets/js/googlesitekit-user-input.********************.js 84.6 kB +31 B (0%)
./dist/assets/js/googlesitekit-vendor.********************.js 272 kB +284 B (0%)
./dist/assets/js/googlesitekit-widgets.********************.js 11.5 kB +22 B (0%)
./dist/assets/js/googlesitekit-wp-dashboard.********************.js 67.4 kB +27 B (0%)
ℹ️ View Unchanged
Filename Size Change
./dist/assets/css/admin.css 36.2 kB 0 B
./dist/assets/css/adminbar.css 7.33 kB 0 B
./dist/assets/css/wpdashboard.css 4.43 kB 0 B
./dist/assets/js/analytics-advanced-tracking.js 769 B 0 B
./dist/assets/js/googlesitekit-base.********************.js 1.57 kB 0 B
./dist/assets/js/googlesitekit-data.********************.js 1.65 kB 0 B
./dist/assets/js/googlesitekit-datastore-location.********************.js 2.03 kB 0 B
./dist/assets/js/googlesitekit-i18n.js 3.92 kB 0 B
./dist/assets/js/runtime.********************.js 763 B 0 B

compressed-size-action

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Overall this looks awesome, thanks 👍🏻

A few notes:

  1. Looks like there's a linting error for the useEffect hook in WithRegistrySetup, but should be easy-to-fix.
  2. I know this isn't mentioned in the doc or the ACs/IBs, but think we can take this opportunity to differentiate the naming of story states better, starting here. The "Loaded" and "Loading" states are very different but their names are only a few letters apart; it's really hard to visually distinguish them in the list:

Screenshot 2021-04-28 at 22 47 44

Why don't we try something like "Ready" or "Available" instead of "Loaded" as the prefix for those stories? I think that'd make it way easier to read.

Thoughts @felixarntz, @aaemnnosttv, @eugene-manuilov?

tests/js/WithRegistrySetup.js Outdated Show resolved Hide resolved
@eugene-manuilov
Copy link
Collaborator

Why don't we try something like "Ready" or "Available" instead of "Loaded" as the prefix for those stories? I think that'd make it way easier to read.

@tofumatt sounds good to me. I think Ready is the best option for it.

Copy link
Collaborator

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

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

Thanks @asvinb ! I left a few comments regarding the current implementation. It looks like there is room to make these a bit more composable but not sure if there is a common decorator we can extract for all widgets in the Analytics module. If composition is easy without being overly verbose, we don't need to add many additional layers of abstraction.

I'm going to take a look at a potential solution for helping with the composition here, but this is off to a good start 👍

@aaemnnosttv
Copy link
Collaborator

@asvinb @tofumatt I pushed a branch to test my ideas about exposing functions to select args so that the underlying component maintains ownership of that so that we don't need to duplicate them in story definitions. Some bits are a bit rough/unfinished (missing docs/etc) but it seems like an improvement. I also added a little utility for generating a mock response and receiving the report for Analytics with the given options to make that a little cleaner as well.

Let me know what you think: enhancement/2940-migrate-storybook...poc/2940-alternate-widget-storybook

@tofumatt
Copy link
Collaborator

tofumatt commented May 5, 2021

@aaemnnosttv I like the approach, that seems like a good refactoring 👍🏻

Let's run with that idea for this—I can see how it'd be useful when we have multiple stories here.

@google-cla

This comment has been minimized.

@google-cla google-cla bot added cla: no and removed cla: yes labels May 6, 2021
@asvinb

This comment has been minimized.

@google-cla

This comment has been minimized.

@asvinb

This comment has been minimized.

@google-cla

This comment has been minimized.

1 similar comment
@google-cla

This comment has been minimized.

@google-cla
Copy link

google-cla bot commented May 14, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added cla: no and removed cla: yes labels May 14, 2021
@aaemnnosttv
Copy link
Collaborator

@googlebot I consent.

@google-cla google-cla bot added cla: yes and removed cla: no labels May 14, 2021
@aaemnnosttv
Copy link
Collaborator

@asvinb I pushed a few commits here to make a few corrections but also to add some important functionality which was missing in the global decorators related to enabled features (which we recently changed) so I think this is just about good to go, but I'd like to get @tofumatt, @felixarntz, and @eugene-manuilov to have a look over as well since this is setting some important precedents.

Basically, features can now be passed via Story parameters which should be set before the registry is created so that things like idea-hub's conditional registration will be easily controllable per-story.

@aaemnnosttv aaemnnosttv dismissed their stale review May 14, 2021 15:01

Changes addressed

Copy link
Collaborator

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

The new features parameters approach looks good to me. As discussed with @aaemnnosttv I think it'd be good to have an example of a story that relies on the features parameters here, but that's all!

.storybook/preview.js Outdated Show resolved Hide resolved
.storybook/preview.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@eugene-manuilov eugene-manuilov left a comment

Choose a reason for hiding this comment

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

Going to approve this, however, I can't say that I like the new implementation of the DashboardUniqueVisitorsWidget component 🤔. I understand why it has been changed that way, but IMO we sacrificed readability and maintainability for getting new storybooks working.

From my point of view, we should have separated the component into two: one for fetching data and passing it to another one, and one for rendering data passed from the first component. Then we would easily create stories for the second component to visualize it and would avoid a need to replicate the datastore environment for it.

Co-authored-by: Matthew Riley MacPherson <hi@tofumatt.com>
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

I agree with @eugene-manuilov's assessment, and wanna emphasize here that we shouldn't need to change the component to get the new CSF stories set up. The approach of manually passing the request data for the selector and generated response data based on it should be maintained like we have been doing it in the old stories.

import parseDimensionStringToDate from '../../util/parseDimensionStringToDate';
import { isZeroReport } from '../../util';
import { generateDateRangeArgs } from '../../util/report-date-range-args';

const { useSelect } = Data;

function DashboardUniqueVisitorsWidget( { WidgetReportZero, WidgetReportError } ) {
Copy link
Member

Choose a reason for hiding this comment

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

This file shouldn't be renamed (back), as this was intentionally done as part of #3064. I guess that originally PR missed renaming the component itself, so let's do that here then.

} ),
};
};

Copy link
Member

Choose a reason for hiding this comment

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

I agree with @eugene-manuilov, we shouldn't change this production code just to get the Storybook story setup simpler. Having exported functions in the same file as the component isn't good practice, so we shouldn't do that.

Let's provide the report options in Storybook manually the same way we do in the legacy versions of the story. This issue is not about changing that, it's only about migrating to the new proper way of CSF.

@felixarntz
Copy link
Member

@aaemnnosttv I just saw your comment in #3230 (comment), I don't think I agree though. We can certainly look into making some of this data more usable, but throwing those functions into the same file as the component and making the component code harder to understand is not worth the benefit of not duplicating the object with the data.

I suggest we keep it simple and focus on only the actual migration of this to CSF, rather than also changing the way we provide data for the selectors which wasn't really in scope here.

@aaemnnosttv
Copy link
Collaborator

Thanks for the feedback @felixarntz and @eugene-manuilov – I'll work on getting this straightened out tomorrow 👍

Copy link
Collaborator

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

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

Thanks all – this should be ready for another pass now 😄

Comment on lines +156 to +157
"@storybook/addon-viewport": "^6.2.9",
"@storybook/react": "^6.2.9",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure if this is necessary or not, but Storybook would get stuck in a HMR loop when starting on the previous version. Technically out of scope here but given the minor change (and problem that it fixes for me) I think it's okay.

Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

Excellent! One comment, but nothing blocking.

};
} );

const WidgetWithComponentProps = withWidgetComponentProps( 'widget-slug' )( DashboardSearchVisitorsWidget );
Copy link
Member

Choose a reason for hiding this comment

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

Maybe it would be more appropriate for this to be the real widget slug instead? Not really an issue though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

My preference is to use dummy values when it isn't necessary/significant. It's also one less place to change if the slug were to change 😄

@felixarntz felixarntz dismissed tofumatt’s stale review May 24, 2021 17:08

Feedback has been addressed.

@felixarntz felixarntz merged commit f4015c1 into develop May 24, 2021
@felixarntz felixarntz deleted the enhancement/2940-migrate-storybook branch May 24, 2021 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants