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

Create frontend providers and widget factory #22008

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

Conversation

igorschoester
Copy link
Member

Context

Summary

This PR can be summarized in the following changelog entry:

  • Refactors the dashboard widgets to get their behavior via a widget factory.
  • Adds the top pages widget.

Relevant technical choices:

  • Remove inner knowledge of widgets from the dashboard into a widget factory that knows how to supply the widgets with what they need
  • Add data provider to control data knowledge.
  • Add remote data provider to control how to fetch data.

Test instructions

Test instructions for the acceptance test before the PR gets merged

This PR can be acceptance tested by following these steps:

Relevant test scenarios

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Default Block/Gutenberg/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

QA can test this PR by following these steps:

Impact check

This PR affects the following parts of the plugin, which may require extra testing:

UI changes

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change. For example, comments in the Relevant technical choices, comments in the code, documentation on Confluence / shared Google Drive / Yoast developer portal, or other.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #

Initial setup for architecture change
* move data into data provider
* use widget factory to create score widgets
@igorschoester igorschoester added the changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog label Jan 30, 2025
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed and moved into the top-pages-widget

Copy link
Member Author

Choose a reason for hiding this comment

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

Seems like a friendly hook for more data/error/isPending widgets. However, I'm not sure how caching/debouncing should be incorperated yet.

Comment on lines +26 to +35
/**
* @returns {WidgetTypeInfo[]}
*/
static get widgetTypes() {
return [
{ type: "seoScores" },
{ type: "readabilityScores" },
{ type: "topPages" },
];
}
Copy link
Member Author

@igorschoester igorschoester Jan 30, 2025

Choose a reason for hiding this comment

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

Maybe remove? As it is not needed yet, if ever

@@ -75,11 +83,10 @@ domReady( () => {
element={
<SidebarLayout>
<Dashboard
contentTypes={ contentTypes }
widgetFactory={ widgetFactory }
initialWidgets={ [ "seoScores", "readabilityScores", "topPages" ] }
Copy link
Member Author

Choose a reason for hiding this comment

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

Need feature flag check before adding topPages

const removeWidget = useCallback( ( type ) => {
setWidgets( ( currentWidgets ) => currentWidgets.filter( ( widget ) => widget.type !== type ) );
}, [] );

return (
<>
<PageTitle userName={ userName } features={ features } links={ links } />
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this be a widget too?

* @returns {JSX.Element|null} The widget or null.
*/
// eslint-disable-next-line no-unused-vars
createWidget( widget, onRemove ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

onRemove is not yet used. Should be under the widget menu eventually, right?

Probably nice to have some RemoveWidget base that handles this in the future?

createWidget( widget, onRemove ) {
switch ( widget.type ) {
case "seoScores":
if ( ! this.#dataProvider.hasFeature( "indexables" ) && this.#dataProvider.hasFeature( "seoAnalysis" ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Should this move into the Widget? And is it worth an Widget layer if more need this?

@coveralls
Copy link

Pull Request Test Coverage Report for Build 3d652004229e620f1733c4f841d99340fc7e612d

Details

  • 0 of 99 (0.0%) changed or added relevant lines in 11 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.1%) to 54.443%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/js/src/dashboard/widgets/table-widget.js 0 1 0.0%
src/dashboard/infrastructure/endpoints/search-rankings/top-query-endpoint.php 0 1 0.0%
packages/js/src/general/initialize.js 0 3 0.0%
packages/js/src/dashboard/services/remote-data-provider.js 0 6 0.0%
packages/js/src/dashboard/widgets/widget.js 0 6 0.0%
packages/js/src/dashboard/components/dashboard.js 0 9 0.0%
packages/js/src/dashboard/widgets/score-widget.js 0 11 0.0%
packages/js/src/dashboard/services/data-provider.js 0 12 0.0%
packages/js/src/dashboard/services/widget-factory.js 0 12 0.0%
packages/js/src/dashboard/widgets/top-pages-widget.js 0 18 0.0%
Files with Coverage Reduction New Missed Lines %
packages/js/src/dashboard/components/dashboard.js 1 0.0%
packages/js/src/general/initialize.js 1 0.0%
Totals Coverage Status
Change from base Build fedc1b286bb15dc44c2150ae129cd3beba01321d: -0.1%
Covered Lines: 30186
Relevant Lines: 55868

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: non-user-facing Needs to be included in the 'Non-userfacing' category in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants