Implement Idea Hub datastore infrastructure for saving and dismissing an idea
See original GitHub issueAfter #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-hub
JS store should receive the following actions:updateIdeaState( ideaState )
which calls thePOST:update-idea-state
REST data point, passing theideaState
as argument. The expected response from this data point is an object with propertiesname
(idea name),saved
(boolean) anddismissed
(boolean).saveIdea( ideaName )
, which callsupdateIdeaState
with an object{ name: ideaName, saved: true, dismissed: false }
.unsaveIdea( ideaName )
, which callsupdateIdeaState
with an object{ name: ideaName, saved: false, dismissed: false }
.dismissIdea( ideaName )
, which callsupdateIdeaState
with an object{ name: ideaName, saved: false, dismissed: true }
.- The latter three actions should be the ones intended for primary usage, while
updateIdeaState
is 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
fetchPostUpdateIdeaStateStore
by usingcreateFetchStore
with the following parameters:
baseName: 'updateIdeaState'
controlCallback: () => {
return API.set( 'modules', 'idea-hub', 'update-idea-state' );
},
- Create a
baseInitialState
constant and assign an empty object
Create the actions
- Add a
baseActions
constant and assign an object containing the following actions (they will need to be generator functions):
updateIdeaState(ideaState)
- receives the following
ideaState
object 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 theideaState
object. - 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
updateIdeaState
with an object{ name: ideaName, saved: true, dismissed: false }
. - returns the error if there is one, or the response as above.
unsaveIdea( ideaName )
- calls
updateIdeaState
with an object{ name: ideaName, saved: false, dismissed: false }
. - returns the error if there is one, or the response as above.
dismissIdea( ideaName )
- calls
updateIdeaState
with 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.combineStores
to assign thebaseInitialState
andbaseActions
we 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
,actions
and other store properties separately in addition to exporting the new store partial. See the other Idea Hub store partials for examples. - Import the new
ideaState
store partial inassets/js/module s/idea-hub/datastore/index.js
and add it to thecombineStores
call 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
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (8 by maintainers)
@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 Good question - the
restoreIdea
was a previous name idea for what is nowunsaveIdea
. So you can ignore that part, it’s included in the ACs asunsaveIdea
.