-
Notifications
You must be signed in to change notification settings - Fork 909
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
base: trunk
Are you sure you want to change the base?
Create frontend providers and widget factory #22008
Conversation
/** | ||
* @returns {WidgetTypeInfo[]} | ||
*/ | ||
static get widgetTypes() { | ||
return [ | ||
{ type: "seoScores" }, | ||
{ type: "readabilityScores" }, | ||
{ type: "topPages" }, | ||
]; | ||
} |
There was a problem hiding this comment.
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" ] } |
There was a problem hiding this comment.
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 } /> |
There was a problem hiding this comment.
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 ) { |
There was a problem hiding this comment.
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" ) ) { |
There was a problem hiding this comment.
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?
5f59d8d
to
d53e0ea
Compare
/** | ||
* @param {ContentType?} [contentType] The selected content type. | ||
* @param {Term?} [term] The selected term. | ||
* @returns {{contentType: string, taxonomy?: string, term?: string}} The score query parameters. | ||
*/ | ||
const getScoreQueryParams = ( contentType, term ) => { // eslint-disable-line complexity | ||
const params = { | ||
contentType: contentType?.name, | ||
}; | ||
if ( contentType?.taxonomy?.name && term?.name ) { | ||
params.taxonomy = contentType.taxonomy.name; | ||
params.term = term.name; | ||
} | ||
|
||
return params; | ||
}; | ||
|
||
/** | ||
* @param {?{scores: Score[]}} [data] The data. | ||
* @returns {?Score[]} scores The scores. | ||
*/ | ||
const prepareScoreData = ( data ) => data?.scores; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These might be moved to the dataProvider or props at a later stage, to actually make it reusable
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
a5b0191
to
7d5224e
Compare
Initial setup for architecture change * move data into data provider * use widget factory to create score widgets
...for the score retrieval * use base Widget * use data provider to get the endpoint * use remote data provider to fetch the scores * remove endpoint and headers
...to use the data provider. This fixes a bug where the admin.php would be hardcoded instead of retrieved from WP. Bonus: a little safeguard against mismatching translation tags.
Add the widget only when site kit is enabled, active and connected. Though the last part is not yet available, so commented that out and replaced with true for now.
dace88b
to
3e63593
Compare
3e63593
to
aa075c5
Compare
get( window, "wpseoScriptData.dashboard.siteKitConfiguration.feature_enabled", false ) && | ||
get( window, "wpseoScriptData.dashboard.siteKitConfiguration.isActive", false ) && | ||
// get( window, "wpseoScriptData.dashboard.siteKitConfiguration.isConnected", false ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs adaptation after: d7065dd is merged
Context
Summary
This PR can be summarized in the following changelog entry:
Relevant technical choices:
Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Regression for scores
The score fetching is refactored to go through the data providers.
add_filter( 'Yoast\WP\SEO\should_index_indexables', '__return_false' );
)Relevant test scenarios
Test instructions for QA when the code is in the RC
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
Other environments
[shopify-seo]
, added test instructions for Shopify and attached theShopify
label to this PR.Documentation
Quality assurance
Innovation
innovation
label.Fixes https://github.com/Yoast/reserved-tasks/issues/367