question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Implement Idea Hub datastore infrastructure for saving and dismissing an idea

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:10 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
johnPhillipscommented, Jun 15, 2021

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

1reaction
felixarntzcommented, Jun 14, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Datastore Overview | App Engine standard environment for Go ...
Datastore can execute a set of operations where either all succeed, or none occur. High availability of reads and writes. Datastore runs in...
Read more >
google/site-kit-wp 1.36.0 on GitHub - NewReleases.io
Implement Idea Hub datastore infrastructure for saving and dismissing an idea. See #3556. ... Implement a minimal settings panel for the Idea Hub...
Read more >
https://mundoviajar.com.br/wp-content/plugins/goog...
**Tag Manager:** Use Site Kit to easily set up Tag Manager- no code ... Implement Idea Hub datastore infrastructure for saving and dismissing...
Read more >
Tutorial: Storing device data in a DynamoDB table - AWS IoT ...
Here are some ideas to get you started. Change the device_id in the input message's topic and observe the effect on the data....
Read more >
Campus LAN and Wireless LAN Solution Design Guide - Cisco
Campus network design concepts include small networks that use a single LAN switch, up to very large networks with thousands of connections. The...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found