site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Ensure widgets in an area are combined beyond their row if all of them have the same special state

Open felixarntz opened this issue 5 years ago • 10 comments

This is a follow-up to #2252, covering a use-case that previously hasn't been considered but is relevant for e.g. the Site Kit module pages, see screenshot: Screen Shot 2021-04-26 at 10 52 34 AM

The logic to combine widgets in the same widget area with similar states normally only combines widgets which are visually in the same row. This should generally be maintained, however with one exception: If all widgets in the widget area have the same state, they should all be combined, resulting in a single full-width widget with that state.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • If all widgets within a widget area have the same special state (via getWidgetState, e.g. ReportZero, ModuleActivateCTA, CompleteModuleActivationCTA), they should all be combined into a single widget box which spans the full width of 12 columns.
    • So far, this does not happen because widgets are only combined if they are in a single row within the widget area (see screenshot). This behavior should be maintained generally, it's really only for the specific situation that all widgets in the widget area have the same state that the new behavior mentioned above should be implemented.
    • This basically requires changes to combineWidgets, e.g. a new loop before the main one that checks if all widgets have the same state and if so applies the required behavior (use override component based on the common state for one of the widgets and set the width to 12, then hide all other widgets).

Implementation Brief

In combine-widgets, before the main loop, add an additional loop which cycles through all the widgets and:

  • checks if all the widgets in the array share the same state (via widgetStates object, e.g. if they all return ReportZero, ModuleActivateCTA, CompleteModuleActivationCTA)
  • if they do all share the same state, then
    • one of the widgets should be full width (i.e. gridColumnWidths[i] is 12 and the others should be hidden (i.e. gridColumnWidths[i] is 0)
    • the returned overrideComponents array should contain the component state to be rendered, e.g.
    // Example where 3 widgets share the same state:
    return {
        overrideComponents: [ widgetStates[ widgets[ 0 ].slug ] ],
        gridColumnWidths: [ 12, 0, 0 ],
    };
    

Test Coverage

  • New tests will need to be added to the combineWidgets.test.js test file. All pre-existing tests should pass.

Visual Regression Changes

  • Module pages where all widgets share the same special state (ReportZero etc.) should now only display one widget. VRT will probably need to be updated as a result.

QA Brief

  • You will need the widgets.dashboard and widgets.moduleScreens features enabled.
  • Now you will need to put a given module in one of the following states: ReportZero, ModuleActivateCTA, CompleteModuleActivationCTA.
    • For example: edit the Analytics settings to point to a new account with no data to force the ReportZero state.
  • Check the module page and verify that all the widgets are combined as per the AC.
  • Check the Site Kit dashboard and verify there are no regressions, e.g. widget areas that contain widgets from multiple modules (the Search Funnel for example) are still combining correctly.
  • Check Storybook to verify there are no regressions there (under Widgets > Widget Area > Special Combination States).

Changelog entry

  • Enhance widgets to combine into one widget if all widgets in an area have the same special state.

felixarntz avatar Apr 26 '21 19:04 felixarntz

@felixarntz A couple of questions for the IB:

  • Design / UI question: If we are combining multiple rows / widgets into a single widget, what do we do about the header / footer for the combined widget? Currently they all obviously have different headers (e.g. 'Top content over...') and source link footers. I guess we do away with these?
  • Regarding using getWidgetState in combine-widgets: we already have a widgetStates object in scope that looks like e.g.:
{
    analyticsModuleOverview: {
        metadata: {
            moduleSlug: "analytics"
        },
        Component: ƒ ReportZero(_ref),
    },
    // ...
}

Can we not use that to establish if all the widgets are returning ReportZero etc.? Thanks!

johnPhillips avatar Apr 29 '21 11:04 johnPhillips

Regarding the headers: UX-wise, it seems it'd be best if we didn't show a header referencing particular type of data (or the date range) if we're still gathering data. Maybe we want to add a headerNoData or something prop that displays when no data is available?

Showing just the first header seems odd, and combining them is definitely redundant, so it seems adding a new "zero state" header for the whole area would be best. (Or just removing all the headers.)

tofumatt avatar Apr 29 '21 21:04 tofumatt

@johnPhillips Regarding the widgetStates variable, yes we can/should absolutely use that in combineWidgets. The ACs referring to getWidgetState was more at a high-level (since widgetStates is anyway populated by using getWidgetState multiple times.

About the widget headers, those won't be displayed anyway. Anytime that widgets are combined, none of them are actually displayed; only the override components are. And those override components are purely based on the shared state, i.e. what you would see here is a single white box that has the blue CTA in it (without any widget header). It is not actually one of the three widgets, so the concerns here shouldn't be a problem I think. cc @tofumatt

In other words, current IB ✅

felixarntz avatar May 03 '21 18:05 felixarntz

Thanks @felixarntz. Regarding headers / footers, I ended up verifying this by sketching it in locally, and you are right. Shouldn't be a problem:

Screenshot 2021-04-29 at 14 23 06

Thanks!

johnPhillips avatar May 04 '21 10:05 johnPhillips

On main I see the widgets not collapsed main-not-collapsed

On develop they do collapse :heavy_check_mark: That part looks good develop-is-collapsed

BUT there is a flash as the widgets are collapsed. I've throttled my network here to emphasise the flash https://www.loom.com/share/994d05fd7fdf40bd9dac9db2df19e78f

danielgent avatar May 28 '21 11:05 danielgent

@danielgent I'm not sure if that is a blocking factor here and might need to be handed as a future enhancement, although if simple to fix, would be great to do now.

aaemnnosttv avatar Jun 01 '21 07:06 aaemnnosttv

@danielgent @aaemnnosttv Apologies for overlooking this when I wrote the IB and implementation 🙈

So I'm seeing a couple of scenarios.

Scenario A On a clean cache (i.e. after changing the settings, which I am guessing would prompt fresh requests) I see:

  1. the three widgets all in a loading state,
  2. when they are calculated to be in the special state (Zero Report in my case), the three widgets are combined into one. It is this transition that is jarring on the eye.
Flash (loading) Combined
Screenshot 2021-05-28 at 14 53 19 Screenshot 2021-05-28 at 14 53 33

Scenario B Subsequent reloads come from the cache I guess, because now although there is a loading state it happens too fast to see, and instead we see the special states rendered first:

Flash (special states) Combined
Screenshot 2021-05-28 at 14 56 32 Screenshot 2021-05-28 at 14 56 46

This is because the widgetStates object is only populated one at a time:

// Loading
widgetStates: {}

// Next render cycle
widgetStates: {
  analyticsModuleOverview: {metadata: {…}, Component: ƒ}
}

// ...
widgetStates: {
  analyticsModuleOverview: {metadata: {…}, Component: ƒ}
  analyticsModulePopularPages: {metadata: {…}, Component: ƒ}
}

// ...
widgetStates: {
  analyticsModuleAcquisitionChannels: {metadata: {…}, Component: ƒ}
  analyticsModuleOverview: {metadata: {…}, Component: ƒ}
  analyticsModulePopularPages: {metadata: {…}, Component: ƒ}
}

So with the current implementation, all three have to be rendered before we can calculate that we can combine them. I'll investigate this now - perhaps I can make the algorithm more 'greedy' so that it combines special states until it hits a widget that doesn't match. Hopefully that will address Scenario B. I'll let you know how I get on.

With scenario A though: if all 3 widgets are loading, should we show some sort of combined 'loading' state to avoid the flash? That might be outside the scope of this issue, although I'm happy to investigate.

johnPhillips avatar Jun 01 '21 08:06 johnPhillips

@danielgent I have looked into the above and discussed with @aaemnnosttv and we were not sure we could see a straightforward way to improve it.

Stepping back, it's a trade-off between:

  • do we eagerly load widgets as soon as we have data (or otherwise), and incur a flash as described
  • do we have a Promise.all -type approach where we keep all the widgets in a loading state until we know exactly what to render. Here we would incur potentially long loading times (e.g. on the dashboard).

So the conclusion was that although this current implementation with the flash isn't perfect, it does fulfil the ACs. Changes to address the flash feel like they might need more thought / discussion and therefore be outside the scope of this particular issue.

Moving back to QA for a final pass if that's ok. Thanks for bringing this up though, it was a good catch.

CC @felixarntz - do let me know if you have any thoughts on this.

johnPhillips avatar Jun 01 '21 10:06 johnPhillips

Ready for a second pass @danielgent (on main)

aaemnnosttv avatar Jun 02 '21 17:06 aaemnnosttv

:heavy_check_mark: QA

danielgent avatar Jun 02 '21 18:06 danielgent