Automattic / wp-calypso

The JavaScript and API powered WordPress.com
https://developer.wordpress.com
GNU General Public License v2.0
12.41k stars 1.99k forks source link

Design picker: extract DesignGrid component #51229

Closed razvanpapadopol closed 3 years ago

razvanpapadopol commented 3 years ago

What

Extract design grid from DesignSelector step component in Gutenboarding.

Why

We need to re-use the component in other flows.

A/C

Follow-up

Bonus points for extracting the component to an @automattic package. Discussion about the dependencies that needs extracting: p1616496332043300/1616488729.039900-slack-C0KDTA48Y and p1616512365044500/1616488729.039900-slack-C0KDTA48Y

ciampo commented 3 years ago

In order to fully extract the Design Picker to a separate package (@automattic/design-picker) , the following files/components need to be extracted too:

To a new package @automattic/calypso-a11y (which needs to be created):

To @automattic/components:

To @automattic/onboarding:

To @automattic/design-picker:

ciampo commented 3 years ago

Update: I spent today working on this task, and I reached a point where my changes were getting a bit out of control.

I think that we under-estimated the complexity of this extraction (we gave it an 8, but I believe it's at least a 13, if not a 21 depending on how proper we want this extraction to be):


In the light of the above, I propose to split this issue into these smaller issues//PR:

  1. Extract client/lib/a11y to a separate new package (@automattic/calypso-a11y)
  2. [Requires 1] Extract <JetpackLogo /> to @automattic/components
  3. Extract <Badge /> component to the @automattic/onboarding
  4. Potentially extract the automattic/onboard store to the @automattic/data-stores package (which would extract the Design type and solve the problem of its dependency from the the FontPair type). Alternatively, find a solution to de-couple the Design type from the FontPair type
  5. [Requires 1-4] Extract <DesignPicker /> component to a separate new package (@automattic/design-picker). This would require:
    • extracting available-designs.ts, available-designs-config.json and potentially the randomisation logic (see above)
    • extracting the interactions with the onboard store that involve the designs (likely into hooks)
    • extracting the <MShotsImage /> component
    • finally extracting the <DesignPicker /> component
      1. Make <DesignPicker /> support different themes
      2. Write integration tests

This current issue could serve as no. 5, while we would need to open new issues for the remaining points.

razvanpapadopol commented 3 years ago

Thanks, @ciampo, for this thorough analysis.

When working on this we should keep in mind that we want a component (or package) that is decoupled from any stateful data structure (eg: Onboard store) and has a simple API so it can be used in other contexts as well (more importantly, in /start Onboarding flow at the moment). So I'd still propose the API from https://github.com/Automattic/wp-calypso/pull/51226 to which we can add the theme.

locale: string;
onSelect: ( design: Design ) => void;
designs?: Design[];
isGridMinimal?: boolean;

While most of your points look valid, here are a few clarifications:

The Design type requires the FontPair type, which is still in client/landing/gutenboarding/constants.ts — which probably doesn't belong to the @automattic/design-picker component, since it's used mainly outside the design picker component.

It seems like FontPair is being used also directly with the DesignSelector when setting default fonts for a design. See https://github.com/Automattic/wp-calypso/blob/trunk/client/landing/gutenboarding/onboarding-block/design-selector/index.tsx#L87

Since FontPair type describes the fonts property of the Design objects found in the file available-designs-config.json that we are extracting, it should be extracted as well to the package and then imported where it's needed.


They are both stored in the automattic/onboard store, which is also a candidate for extraction to @automattic/data-stores

As we previously discussed, the Onboard store belongs to Gutenboarding and it handles user selection and progress during the onboarding. @automattic/data-stores package (see Readme) is used to fetch data from various WordPress.com REST API endpoints so the only stateful information stored there should be about data fetching (request, response, loading, error). Actually, we should also take the Launch store out of @automattic/data-stores https://github.com/Automattic/wp-calypso/issues/51363.


It feels like designs-related calls to the onboard data-store (setSelectedDesign, getSelectedDesign, hasPaidDesign, getRandomizedDesigns) should be moved to the @automattic/design-picker too

From these, the first 3 are tightly embedded in the consumer app (Gutenboarding) so I'd say we could plan to move only getRandomizedDesigns in a follow-up. For now, Gutenboarding could continue to handle this locally by importing the result of available-designs.ts from @automattic/design-picker and then passing designs as a prop to DesignPicker.


Now, about the next steps:

ciampo commented 3 years ago

TODO:

Timeline: