Implement `<PublicationSelect>` component
Feature Description
A <PublicationSelect> component should be added for the Reader Revenue Manager module that presents the user with a list of available publications and allows them to select one of them. The selected publication should be stored in the data store within the publicationID module setting, with its onboarding state stored within the publicationOnboardingState module setting.
Screenshot for reference
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- A
PublicationSelectcomponent should be added for the Reader Revenue Manager module that presents the user with a dropdown of all available publications, according to the Figma designs. - Its label should be "Publication".
- Upon selecting a publication from the dropdown, data store values of three module settings should be updated:
publicationID: Should contain the publication ID of the selected publication.publicationOnboardingState: Should contain the onboarding state of the selected publication.publicationOnboardingStateLastSyncedAtMs: Should contain the current time, in the form of the number of milliseconds elapsed since the epoch.
Implementation Brief
- [ ] The
analytics-4ProperySelectcomponent can be used as a reference point here. - [ ] Create a new component in
assets/js/module/reader-revenue-manager/components/common/PublicationSelect.js. It should accept the following props.- [ ]
isDisabled- Flag whether Publication select should be in disabled/enable state. - [ ]
classNames- Class names forSelectcomponent fromgooglesitekit-components. - [ ]
onChange- Function to call when value in dropdown changes. - [ ]
hasModuleAccess- Flag to tell if the user has current module access.
- [ ]
- [ ] Use the
getPublicationsselector implemented in #8794 to get the list of publications.getPublicationsselector will only be called whenhasModuleAccessis notfalseandisDisabledis not falsy.hasModuleAccess !== false && ! isDisabled- [ ] Add a new function
isValidPublicationIDinassets/js/modules/analytics-4/utils/validation.jswhich should check if publication ID is valid. A publication ID should be string of only alphabets and digits. This should be similar toisValidMeasurementIDfunction here. - [ ] Add the
onPublicationChangeusinguseCallbackwhich would be passed toonEnhancedChangeprop ofSelectcomponent fromgooglesitekit-components. - [ ]
onPublicationChangeshould set thepublicationID,publicationOnboardingStateusing set method from thecreate-settings-storei.e.setPublicationIDandsetPublicationOnboardingState. These values should be received fromgetPublicationsselector. - [ ] Also set
publicationOnboardingStateLastSyncedAtMsusing same method, it should contain the current time, in the form of the number of milliseconds elapsed since the epoch. - [ ] Pass the label as
PublicationtoSelectcomponent. - [ ] Render a
Selectcomponent with no publications (other than if one is already selected) ifhasModuleAccessis explicitlyfalse, similar to the AnalyticsPropertySelectcomponent. - [ ] We should display a loading
ProgressBarcomponent if the publications are loading. Take the reference ofPropertySelectcomponent here which does the same.- [ ] We can use the
isResolvingselector to check if the resolver forgetPublicationsis still running.
- [ ] We can use the
- [ ] Add a new function
Test Coverage
- [ ] Add tests for the component with different props and combinations.
QA Brief
Changelog entry
Thank you for the IB, @ankitrox ! Please take a look at my comments below:
- Update the
getPublicationsselector to also retrieveonboardingStatein publication object. This should already be received fromGET:publicationsendpoint.
Let's remove this requirement as this property should already be a part of the getPublications selector. See this comment.
I think it might be beneficial to use the Analytics PropertySelect component as a starting point. See points below:
- Let's mention the usage of the
isDisabledandhasModuleAccessprops. ThegetPublicationsselector should only be called ifhasModuleAccessisn't explicitlyfalse, andisDisabledisn't falsy, similar to the AnalyticsPropertySelectcomponent. - Let's add validation for the publication ID, i.e.
isValidPublicationIDfunction. This should be similar to the AnalyticsisValidMeasurementIDfunction which checks that the value is a string which only contains alphabets and numbers. - Let's mention that we want to render a
Selectcomponent with no publications (other than if one is already selected) ifhasModuleAccessis explicitlyfalse, similar to the AnalyticsPropertySelectcomponent. - Let's mention that we want to display a loading progress bar when the publications are being resolved, again, similar to the Analytics
PropertySelectcomponent.
For Storybook stories, I don't think it'll be very valuable to add a Storybook story for this component alone. This will likely be included in the Storybook stories for the module setup and settings screens, so an individual story may seem redundant.
Let me know what you think and if you have any questions, thank you!
Thanks @nfmohit for reviewing the IB.
I have updated the IB as per the suggested points. Re-assigning to you for review.
Thanks again!
Thank you for the updates, @ankitrox ! I've made a few changes to the IB to reduce the back and forth, namely:
- I've mentioned using Analytics
PropertySelectas a reference point. - I've removed the proposal to update the
getPublicationsselector for onboarding state, as that should be no longer required. - I made the criteria for
isValidPublicationIDa little more specific and mentioned that it should only accept alphabets and digits (no symbols). - I've mentioned that we can use the
isResolvingselector forgetPublicationsto determine the loading state, instead of proposing to create a new selector. Working on a new selector unless necessary also includes adding test coverage for it, thus requiring more time and effort.
Please let me know if you have any questions. IB LGTM 👍 ✅
QA Update ⚠️
Few items to raise: ITEM 1: Copy The text description is currently 'This is just added as a placeholder component to assist with testing.' Based on figma, it should be 'Select your preferred publication to connect with Site Kit'. Is this going to be tackled under a different issue?
Figma:
ITEM 2: Publication ID Missing and dropdown size The dropdown should have included the Publication ID as well. Currently, it doesn't. Moreover, the size of the dropdown should be 300px wide, not 200px.
Figma size is 300px:
ITEM 3: Value for publicationOnboardingStateLastSyncedAtMs The "publicationOnboardingStateLastSyncedAtMs" is always 0 regardless of the publication selected. It's also 0 after some time that I've selected the publication at the dropdown. Are we expecting any values besides 0?
ITEM 4: Spacing From the icon to the description text, it's supposed to be around 45px. Currently, it's just 14px.
Implementation:
ITEM 1: Copy
As you can see from the discussion on previous PR, we just added the component along with the message so that it is convenience to test. We will test it thoroughly in #8800
ITEM 2: Publication ID Missing and dropdown size
Sorry for not including this. It looks like this was missed during our previous round. I have created a new PR #9073 to address the issue. Also, addressed the width issue in same PR, although I believe that we could have kept the width as is to maintain consistency along with other select components. We can check if there is any feedback in CR for the same.
ITEM 3: Value for publicationOnboardingStateLastSyncedAtMs
This is will be handled in #8796 here . The reason, it can't be seen in action as of now is because we are yet to integrate everything in setup screen. We can test this in #8800
ITEM 4: Spacing
As per the discussion mentioned previously, we can test all the styling things in #8800
Back to you for another pass, @kelvinballoo.
Please note that with regard to Item 2, the dropdown size is derived from content. As per this https://github.com/google/site-kit-wp/pull/9073#discussion_r1691287607 (which you may have already seen):
... the
Selectdropdown takes its width from its content, and this should be understood to be reflected in the Figma design rather than a fixed minimum width.
QA update ✅
Noted on Item 1, 3 and 4. Tested item 2 and the dropdown is now reflecting the Publication ID accordingly, similar to the Publisher Central.
Also tested the following:
-
New dropdown's label is "Publication".
-
Running
googlesitekit.data.select('modules/reader-revenue-manager').getSettings();will give 0 if nothing is selected at the dropdown. -
If there a publication is selected, the details related to that publication will appear when running the script.
Moving ticket to Approval.
Moving this back to execution to fix the RRM SetupMain story that developed an error as a result of its first PR.
Thanks @techanvil , merged 👍