site-kit-wp icon indicating copy to clipboard operation
site-kit-wp copied to clipboard

Implement Idea Hub datastore infrastructure for saving and dismissing an idea

Open felixarntz opened this issue 5 years ago • 10 comments

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-hub JS store should receive the following actions:
    • updateIdeaState( ideaState ) which calls the POST:update-idea-state REST data point, passing the ideaState as argument. The expected response from this data point is an object with properties name (idea name), saved (boolean) and dismissed (boolean).
    • saveIdea( ideaName ), which calls updateIdeaState with an object { name: ideaName, saved: true, dismissed: false }.
    • unsaveIdea( ideaName ), which calls updateIdeaState with an object { name: ideaName, saved: false, dismissed: false }.
    • dismissIdea( ideaName ), which calls updateIdeaState 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 using createFetchStore 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, via invariant, if the object is missing or incorrectly shaped:
    { name: string, saved: bool, dismissed: bool }
    
  • It should call fetchPostUpdateIdeaStateStore.actions.updateIdeaState, passing the ideaState 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 the baseInitialState and baseActions we just created to the new fetchPostUpdateIdeaStateStore. 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 in assets/js/module s/idea-hub/datastore/index.js and add it to the combineStores 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

felixarntz avatar Jun 10 '21 23:06 felixarntz

@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 avatar Jun 14 '21 15:06 johnPhillips

@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.

felixarntz avatar Jun 14 '21 17:06 felixarntz

@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 avatar Jun 14 '21 17:06 felixarntz

@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 avatar Jun 15 '21 13:06 johnPhillips

@johnPhillips Sure, no worries - great to have you dive into this! IB ✅

felixarntz avatar Jun 15 '21 18:06 felixarntz

@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 avatar Jun 18 '21 11:06 johnPhillips

@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

felixarntz avatar Jun 18 '21 16:06 felixarntz

@johnPhillips could you please add QA brief?

eugene-manuilov avatar Jun 23 '21 16:06 eugene-manuilov

@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 👍

johnPhillips avatar Jun 24 '21 09:06 johnPhillips

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 ✅

tofumatt avatar Jun 30 '21 22:06 tofumatt