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

Implement settings edit screen #9047

Merged
merged 22 commits into from
Aug 2, 2024
Merged

Conversation

ankitrox
Copy link
Collaborator

@ankitrox ankitrox commented Jul 19, 2024

Summary

Addresses issue:

Relevant technical choices

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

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

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

@ankitrox ankitrox changed the title Enhancement/8841 settings screen Implement settings edit screen Jul 19, 2024
@ankitrox ankitrox marked this pull request as ready for review July 22, 2024 10:34
Copy link

github-actions bot commented Jul 22, 2024

Build files for 6d3de25 have been deleted.

Copy link

github-actions bot commented Jul 24, 2024

Size Change: +490 B (+0.03%)

Total Size: 1.69 MB

Filename Size Change
./dist/assets/js/googlesitekit-activation-********************.js 23.8 kB -2 B (-0.01%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 59.8 kB -5 B (-0.01%)
./dist/assets/js/googlesitekit-adminbar-********************.js 34.5 kB +3 B (+0.01%)
./dist/assets/js/googlesitekit-api-********************.js 10 kB -1 B (-0.01%)
./dist/assets/js/googlesitekit-components-gm2-********************.js 5.96 kB +2 B (+0.03%)
./dist/assets/js/googlesitekit-data-********************.js 2.35 kB -1 B (-0.04%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.08 kB +1 B (+0.05%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 77.4 kB -11 B (-0.01%)
./dist/assets/js/googlesitekit-main-dashboard-********************.js 147 kB -7 B (0%)
./dist/assets/js/googlesitekit-modules-ads-********************.js 29.5 kB +7 B (+0.02%)
./dist/assets/js/googlesitekit-modules-adsense-********************.js 114 kB +11 B (+0.01%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 165 kB -3 B (0%)
./dist/assets/js/googlesitekit-modules-********************.js 22.1 kB +3 B (+0.01%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 22.5 kB -2 B (-0.01%)
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 17.6 kB +477 B (+2.78%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 59 kB +8 B (+0.01%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 32 kB +15 B (+0.05%)
./dist/assets/js/googlesitekit-settings-********************.js 74.4 kB -1 B (0%)
./dist/assets/js/googlesitekit-splash-********************.js 74.2 kB -1 B (0%)
./dist/assets/js/googlesitekit-user-input-********************.js 48.9 kB +4 B (+0.01%)
./dist/assets/js/googlesitekit-vendor-********************.js 321 kB -4 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 81.5 kB -2 B (0%)
./dist/assets/js/runtime-********************.js 1.3 kB -1 B (-0.08%)
ℹ️ View Unchanged
Filename Size
./dist/assets/css/googlesitekit-admin-css-********************.min.css 56.5 kB
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.8 kB
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 846 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 8.2 kB
./dist/assets/js/31-********************.js 2.76 kB
./dist/assets/js/32-********************.js 2.25 kB
./dist/assets/js/33-********************.js 3.64 kB
./dist/assets/js/34-********************.js 935 B
./dist/assets/js/35-********************.js 892 B
./dist/assets/js/36-********************.js 3.12 kB
./dist/assets/js/analytics-advanced-tracking-********************.js 901 B
./dist/assets/js/googlesitekit-components-gm3-********************.js 10.1 kB
./dist/assets/js/googlesitekit-consent-mode-********************.js 25.6 kB
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.03 kB
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.4 kB
./dist/assets/js/googlesitekit-datastore-ui-********************.js 9.97 kB
./dist/assets/js/googlesitekit-datastore-user-********************.js 25.1 kB
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 646 B
./dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 624 B
./dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 630 B
./dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 712 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 675 B
./dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 634 B
./dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 657 B
./dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 633 B
./dist/assets/js/googlesitekit-i18n-********************.js 3.93 kB
./dist/assets/js/googlesitekit-notifications-********************.js 4.04 kB
./dist/assets/js/googlesitekit-polyfills-********************.js 376 B
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 61.8 kB

compressed-size-action

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

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

Hi @ankitrox, this is generally working well, however there are a few changes needed. Please see my comments.

decorators: [
( Story, { args } ) => {
const setupRegistry = ( registry ) => {
enabledFeatures.add( 'rrmModule' );
Copy link
Collaborator

Choose a reason for hiding this comment

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

You should be able to use the WithRegistrySetup.features prop instead of adding the feature here via enabledFeatures.

Suggested change
enabledFeatures.add( 'rrmModule' );

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry @techanvil , but this does not seem to work as intended because WithRegistrySetup has signature

WithRegistrySetup( { func, children } ) {
...

}

which does not seem to receive and do anything with features prop.

Copy link
Collaborator

@techanvil techanvil Aug 1, 2024

Choose a reason for hiding this comment

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

Oh, yes, you're right. Sorry about that. We actually have this in a few places, which are obviously incorrect and we should fix. E.g.

return (
<WithRegistrySetup
func={ setupRegistry }
features={ parameters.features || [] }

return (
<WithRegistrySetup
func={ setupRegistry }
features={ parameters.features || [] }
>

Looking into it, the reason those stories are still working as expected is because the features are set in the parameters for the story, for example:

PaxConnected.parameters = {
features: [ 'adsPax' ],
};

Providing features in parameters will automatically enable the features due to this decorator which is applied to all stories:

// Features must be set up before test registry is initialized.
( Story, { parameters } ) => {
const { features = [], route } = parameters;
const isFirstMount = useFirstMountState();
useUnmount( () => enabledFeatures.clear() );
if ( isFirstMount ) {
setEnabledFeatures( features );
}
return (
<WithTestRegistry features={ features } route={ route }>
<Story />
</WithTestRegistry>
);
},

What is means is that rather that my suggested fix you can instead apply the following to provide the features to all stories in this file:

export default {
	title: 'Modules/ReaderRevenueManager/Components/Settings/SettingsEdit',
	parameters: {
		features: [ 'rrmModule' ],
	},

Could you please apply the above instead of my suggestions? One thing we don't tend to do is reference enabledFeatures directly in stories, because we have various abstractions around it.

I've created a story to remove up the existing attempted use of WithRegistrySetup.features: #9115

Cc @10upsimon

};

return (
<WithRegistrySetup func={ setupRegistry }>
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above:

Suggested change
<WithRegistrySetup func={ setupRegistry }>
<WithRegistrySetup func={ setupRegistry } features={ [ 'rrmModule' ] }>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same as above


export default {
title: 'Modules/ReaderRevenueManager/Settings/SettingsEdit',
component: SettingsEdit,
title: 'Modules/ReaderRevenueManager/Components/Settings/SettingsEdit',
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert this change to title so the SettingsEdit stories are next to SettingsView in the Storybook menu:

Suggested change
title: 'Modules/ReaderRevenueManager/Components/Settings/SettingsEdit',
title: 'Modules/ReaderRevenueManager/Settings/SettingsEdit',

image

},
};

export const PublicationSelectedWithOnboardingStateNotice = Template.bind( {} );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm... You could rename this to PublicationSelectedPendingVerification, and create a similar story with a publication in the ONBOARDING_ACTION_REQUIRED state called PublicationSelectedActionRequired.

Then, you could remove the scenarios (but not the stories) for the PublicationOnboardingStateNotice component, because they will both effectively be covered here.

I realise it means backing out a bit of work that was just added, but the net result will be better coverage for the SettingsEdit component, and one less scenario in our VRT suite, which we are always looking to make more efficient.

Comment on lines 74 to 76
muteFetch( settingsEndpoint );
muteFetch( publicationsEndpoint );
muteFetch( listModulesEndpoint );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Our JS tests should generally not need to know about the underlying REST endpoints, unless they are explicitly testing the network behaviour.

Please can you rewrite this test to populate the relevant data rather than muting these endpoints. For example, rather than muting settingsEndpoint, you can restore the following call:

		registry
			.dispatch( MODULES_READER_REVENUE_MANAGER )
			.receiveGetSettings( {} );

We're already populating the list of publications via receiveGetPublications() in the setup, so muting publicationsEndpoint is redundant and can simply be removed. The same applies to the listModulesEndpoint, the modules are already being populated via provideModules().

Suggested change
muteFetch( settingsEndpoint );
muteFetch( publicationsEndpoint );
muteFetch( listModulesEndpoint );

@@ -72,6 +72,7 @@ protected function get_default() {
'publicationID' => '',
'publicationOnboardingState' => '',
'publicationOnboardingStateLastSyncedAtMs' => 0,
'ownerID' => 0,
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is very minor, but please can you move ownerID to the top of the list of fields to be consistent with settings for other modules. For example:

protected function get_default() {
return array(
'ownerID' => 0,

await waitForRegistry();

// Ensure publication select is rendered.
expect( container.querySelector( '.mdc-select' ) ).toBeInTheDocument();
Copy link
Collaborator

Choose a reason for hiding this comment

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

We try to follow the general principles behind the Testing Library / RTL, whereby we interact with the components "in the way the user would use it" as much as possible. This means we prefer the getByRole(), getByText() etc. queries to querying the DOM using selectors.

In this case, we can use getByRole() instead of querying for .mdc-select:

Suggested change
expect( container.querySelector( '.mdc-select' ) ).toBeInTheDocument();
expect( getByRole( 'menu', { hidden: true } ) ).toBeInTheDocument();

Comment on lines 93 to 95
container.querySelector(
'.googlesitekit-publication-onboarding-state-notice'
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

As above:

Suggested change
container.querySelector(
'.googlesitekit-publication-onboarding-state-notice'
)
getByText(
'Your publication requires further setup in Reader Revenue Manager'
)

Comment on lines 83 to 85
const { container, waitForRegistry } = render( <SettingsEdit />, {
registry,
} );
Copy link
Collaborator

Choose a reason for hiding this comment

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

You'll want to retrieve getByRole and getByText here to address the points below:

Suggested change
const { container, waitForRegistry } = render( <SettingsEdit />, {
registry,
} );
const { waitForRegistry, getByRole, getByText } = render(
<SettingsEdit />,
{
registry,
}
);

} );

if ( isDoingSubmitChanges || undefined === hasModuleAccess ) {
return <ProgressBar smallHeight={ 80 } desktopHeight={ 88 } medium />;
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be rendered without props to be consistent with the other SettingsEdit components:

Suggested change
return <ProgressBar smallHeight={ 80 } desktopHeight={ 88 } medium />;
return <ProgressBar />;

Copy link
Collaborator

@techanvil techanvil left a comment

Choose a reason for hiding this comment

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

Thanks @ankitrox, this LGTM.

Please note I made a couple of final tweaks which you'll see in the commit history, and also tidied up the QAB a bit.

@techanvil techanvil merged commit 516183b into develop Aug 2, 2024
24 of 26 checks passed
@techanvil techanvil deleted the enhancement/8841-settings-screen branch August 2, 2024 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants