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

Update widget registration to optionally declare associated module(s) and update getWidgets to accept a new modules option #4807

Closed
aaemnnosttv opened this issue Feb 8, 2022 · 2 comments
Labels
P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature

Comments

@aaemnnosttv
Copy link
Collaborator

aaemnnosttv commented Feb 8, 2022

Feature Description

With dashboard sharing, it is important that users will only be able to see widgets on the dashboard for modules which have been shared with them. Currently, widget registration does not include awareness of the module (or modules) a widget is associated with.

This issue will update widget registration to allow for such (optional) association as well as extend the getWidgets selector to allow for selecting widgets optionally limited by some set of modules.

In the future, this will be integrated with getViewableModules in #4803 and #4813


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

Acceptance criteria

  • The registerWidget action on the core/widgets store, and its respective function on the Widgets instance returned by createWidgets should support a new optional settings.modules (string|string[]) of module slug(s)
    • Internally, this should be included in the registered widget settings, normalized as a list of strings
  • The getWidgets selector on the same store should be extended to receive an optional options object as its 3rd argument with options.modules as a string|string[] of module slug(s)
    • If provided, the widgets returned should be filtered to only include widgets that are registered for the given module(s) or widgets that are not associated with any module.
    • If a widget is registered with multiple modules (e.g. adsense and analytics), it should only be returned if all of its registered modules are in the list of modules provided in the option. (e.g. if option.modules was analytics, the widget would not be returned. If option.modules was ['analytics','search-console','adsense'], it would be, because both adsense and analytics were included)
  • Existing use of getWidgets should continue to work as today
  • Test coverage should be extended accordingly to cover these changes

Implementation Brief

  • In the assets/js/googlesitekit/widgets/datastore/widgets.js file:
    • Update the registerWidget action:
      • Add a new property modules to the incoming settings object (2nd parameter).
      • Normalize the modules variable to always be an array. of strings.
      • Add modules to the settings object defined in the action payload.
    • Update the getWidgets selector:
      • Add the new 3rd parameter options which is an object with the only modules property supported by now.
      • If options.modules is not empty, then filter returned widgets to return widgets that either have no modules assigned or all associated modules are included in the options.modules list. See more details in AC.
  • In the assets/js/googlesitekit/widgets/index.js file
    • Update jsdoc for the registerWidget function to define modules as a new property of the settings parameter.

Test Coverage

  • Add tests for new functionality.

QA Brief

  • Check the registerWidget action and the getWidgets selector to make sure that the implementation follows requirements defined in AC.
  • Verify that js tests for the aforementioned action and selector pass.

Changelog entry

  • N/A
@tofumatt
Copy link
Collaborator

tofumatt commented Mar 8, 2022

IB ✅

@hussain-t
Copy link
Collaborator

QA Verified ✅

  • Check the registerWidget action and the getWidgets selector to make sure that the implementation follows requirements defined in AC.
  • Verify that js tests for the aforementioned action and selector pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 High priority QA: Eng Requires specialized QA by an engineer Type: Enhancement Improvement of an existing feature
Projects
None yet
Development

No branches or pull requests

5 participants