Implement Idea Hub datastore infrastructure for saving and dismissing an idea
After #3518 and the REST data points being connected to the Idea Hub API, the datastore functionality for saving and dismissing an idea need to be implemented.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- The
modules/idea-hubJS store should receive the following actions:updateIdeaState( ideaState )which calls thePOST:update-idea-stateREST data point, passing theideaStateas argument. The expected response from this data point is an object with propertiesname(idea name),saved(boolean) anddismissed(boolean).saveIdea( ideaName ), which callsupdateIdeaStatewith an object{ name: ideaName, saved: true, dismissed: false }.unsaveIdea( ideaName ), which callsupdateIdeaStatewith an object{ name: ideaName, saved: false, dismissed: false }.dismissIdea( ideaName ), which callsupdateIdeaStatewith an object{ name: ideaName, saved: false, dismissed: true }.- The latter three actions should be the ones intended for primary usage, while
updateIdeaStateis more of a lower-level action typically not called from outside the store.
This is technically blocked by #3518, but can be implemented without waiting since the interface is clearly defined and JS tests can rely on mocked responses anyway.
Implementation Brief
Create the store partial
- Add a new file,
assets/js/modules/idea-hub/datastore/idea-state.js - Create a new store called
fetchPostUpdateIdeaStateStoreby usingcreateFetchStorewith the following parameters:
baseName: 'updateIdeaState'
controlCallback: () => {
return API.set( 'modules', 'idea-hub', 'update-idea-state' );
},
- Create a
baseInitialStateconstant and assign an empty object
Create the actions
- Add a
baseActionsconstant and assign an object containing the following actions (they will need to be generator functions):
updateIdeaState(ideaState)
- receives the following
ideaStateobject as a parameter. It should throw, viainvariant, if the object is missing or incorrectly shaped:{ name: string, saved: bool, dismissed: bool } - It should call
fetchPostUpdateIdeaStateStore.actions.updateIdeaState, passing theideaStateobject. - If there is an error, it should return it
- If there is no error, it should return the response, i.e.
{ error: false, response }
saveIdea( ideaName )
- calls
updateIdeaStatewith an object{ name: ideaName, saved: true, dismissed: false }. - returns the error if there is one, or the response as above.
unsaveIdea( ideaName )
- calls
updateIdeaStatewith an object{ name: ideaName, saved: false, dismissed: false }. - returns the error if there is one, or the response as above.
dismissIdea( ideaName )
- calls
updateIdeaStatewith an object{ name: ideaName, saved: false, dismissed: true }. - returns the error if there is one, or the response as above.
Incorporate into the Idea Hub store
- Use
Data.combineStoresto assign thebaseInitialStateandbaseActionswe just created to the newfetchPostUpdateIdeaStateStore. Assign this new store partial to a constant and export it as the default. - Make sure to export the
initialState,actionsand other store properties separately in addition to exporting the new store partial. See the other Idea Hub store partials for examples. - Import the new
ideaStatestore partial inassets/js/module s/idea-hub/datastore/index.jsand add it to thecombineStorescall with the others.
Tests and peripherals
- Add test coverage for the new store partial
- Ensure that the code is documented throughout as appropriate
Test Coverage
- Test coverage will need to be added for the new store as with the other Idea Hub stores.
Visual Regression Changes
- None anticipated.
QA Brief
The endpoint that these actions use will not be in place until #3518 is merged, and they are also not used by anything in the codebase until #3519 and #3520 are merged (those issues implement the UI).
Therefore there isn't much to QA here, apart from looking through the code and verifying that the ACs have been met.
You could also use the console to dispatch the actions, e.g. googlesitekit.data.dispatch('modules/idea-hub').saveIdea("ideas/17450692223393508734"). You should be able to call the actions and receive a promise, but remember that until #3518 is merged you will get an API error when the endpoint is called.
Changelog entry
- Implement Idea Hub datastore infrastructure for saving and dismissing an idea
@felixarntz I was just looking through the Idea Hub design document to remind myself how it's all supposed to work and I noticed mention was made of a restoreIdea action that would 'un-dismiss' an idea.
Is that still a requirement, and if so, should it be part of this issue?
@johnPhillips Good question - the restoreIdea was a previous name idea for what is now unsaveIdea. So you can ignore that part, it's included in the ACs as unsaveIdea.
@johnPhillips IB mostly lgtm, just one question: Why do we need the isUpdatingIdeaState selector? Particularly I'm wondering since it just returns through the value from the other automatically created selector.
@felixarntz This is my first IB dealing with our data store architecture in real depth and I'm still learning the ropes a bit. I was just trying to follow other examples in the code base. I'll remove that from the IB if it isn't needed 👍
@johnPhillips Sure, no worries - great to have you dive into this! IB ✅
@felixarntz How should we go about QA for this? I think this issue has a couple of dependencies so it's not currently possible to test these actions using the browser console, for example.
I've added unit test coverage for this - would labelling it QA:eng and having someone inspect the code and tests be sufficient?
@johnPhillips Since it is blocked by #3518, we should probably wait until merge and QA until that dependency is done first. Since this is a user-facing enhancement, I think this should eventually get regular QA rather than engineering only. cc @aaemnnosttv
@johnPhillips could you please add QA brief?
@eugene-manuilov See the comment above: I think the idea is to wait until https://github.com/google/site-kit-wp/issues/3518 is merged so that we can QA this properly.
@felixarntz can I clarify something:
Since this is a user-facing enhancement, I think this should eventually get regular QA rather than engineering only.
This issue was just building out the actions, so I am not sure how it could get a regular QA? I guess we would need https://github.com/google/site-kit-wp/issues/3519 and https://github.com/google/site-kit-wp/issues/3520 to be merged as well, as they are the UI facing consumers of this.
Otherwise I think we could QA:eng this and test it from the console etc. once https://github.com/google/site-kit-wp/issues/3518 is merged?
Let me know what you think and I'll update the QAB accordingly 👍
As mentioned by @johnPhillips, these API endpoints don't yet exist, but when the Idea Hub feature flag is enabled and they're called, it all works as-expected, with method:POST datapoint:update-idea-state type:modules identifier:idea-hub being the call made with the example action called in the Settings page in Site Kit.
So looks good, QA ✅