Idea hub, loading indicator to show "Creating new draft"
Feature Description
This is in reference to the comment on this issue: https://github.com/google/site-kit-wp/issues/3357#issuecomment-841365269
Objective: To show a loading indicator when the user clicks the "Start a draft" button on the idea hub widget.
Proposed solution:
- User clicks on the "Start a draft" button
- An overlay appears on this idea row - (Grey area in the screenshot below)
- Overlay shows a standard loading spinner or an illustration with these copies:
"Creating draft post for you", then the copy changes to "Draft post created",
- As a nice to have, the number on the "Drafts" tab does a subtle animation to show that it increased.

Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- When creating an Idea Hub draft post via the widget, the current state of the progress should be indicated:
- While the API request is happening, it should say "Creating draft" (in italic) instead of the three icons on the right - essentially the text should display in the same spot where it for ideas with a draft post has the "View draft" link.
- Once the API request is completed, the idea should not immediately disappear from the current tab; instead the text above should change to "Draft created" for 2 seconds. After those 2 seconds, the whole idea item should disappear (since anyway its new place now is in the "Drafts" tab).
Implementation Brief
- Using
assets/js/modules/idea-hub/datastore/draft-ideas.js,- Add a new action which removes an idea from the list of
newIdeasandsavedIdeasstate variables. - Update
reducerCallbackto remove the code wherenewIdeasandsavedIdeasare updated.
- Add a new action which removes an idea from the list of
- Using
assets/js/modules/idea-hub/datastore/constants.js,- Add 3 constants,
ACTIVITY_IS_PROCESSING,ACTIVITY_CREATING_DRAFT,ACTIVITY_DRAFT_CREATED, each having the same values.
- Add 3 constants,
- Using
assets/js/modules/idea-hub/datastore/idea-state.js,- Add
activitiesto the initial state with an empty object as default value. - Add the
setActivityaction which has 2 parameters:key: string which will be the idea namevalue: string which will store the current activity of the idea, i.e whether a draft is being created or has been created.
- The
setActivitywill add thekeyandvalueto theactivitiesobject. - Add the
removeActivityaction which as a single parameter:key: string, which is the idea name.
removeActivitywill remove the item with the specified key from theactivitiesobject.- Add the
getActivityselector which will return the activity of an idea based on thekeyfrom theactivitiesobject. - The above implementation should be inspired by the
core/uidata store.
- Add
- Using
assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/Idea.js,- Update the
handleCreatefunction to dispatch thesetActivityaction, with the idea name askeyand the value set toACTIVITY_CREATING_DRAFT. This should be done beforecreateIdeaDraftPostis called. - After
createIdeaDraftPosthas been called,- call
setActivitywith the value set toACTIVITY_DRAFT_CREATEDand idea name askey. - After another 2 seconds, dispatch the
removeActivityaction and then the newly created action created as per the first bullets point of the IB should be called, to remove the idea from the list.
- call
- Get the activity of the idea via the
getActivityselector passing the idea name askey. Based on the value returned by the selector,- Update the conditions to display the buttons in the
googlesitekit-idea-hub__idea--actionscontainer ifgetActivityisACTIVITY_CREATING_DRAFT. If it's the case, then the buttons are not rendered and the text as per the AC should be rendered, in italic and right aligned, similar to the "View Draft" text. - A small spinner should be prepended to the text when a draft is being created. The
CircularProgresscomponent, imported from@material-ui/corecan be used. The size of theCircularProgressshould be10, with a margin right of8pxfrom the text. - Update the conditions to display the buttons in the
googlesitekit-idea-hub__idea--actionscontainer ifgetActivityisACTIVITY_DRAFT_CREATED. If it's the case, then the buttons are not rendered and the text as per the AC should be rendered when a draft has been created, in italic and right aligned, similar to the "View Draft" text. - Remove the
isProcessingstate variable and instead use thegetActivitystate variable and set the value toACTIVITY_IS_PROCESSINGwhereisProcessingwas originall set totrue. Where it was set tofalse, useremoveActivity. - Update the
disabledlogic for buttons to check for whengetActivityisACTIVITY_IS_PROCESSING.
- Update the conditions to display the buttons in the
- Update the
Test Coverage
- Tests to be added for the new actions and selectors.
Visual Regression Changes
- N/A
QA Brief
- See screenshot in AC. Click on button to start a draft for a few ideas
- Verify that animation happens as per AC
Changelog entry
- Add loading indicator to the Idea Hub widget when a new draft is being created
@Pratheep-lab Revisiting this, I wanted to suggest another idea: Instead of overlaying the entire idea row, it might be smoother to only alter the area on the right where the user is interacting with anyway. I'm thinking something like:
- Replace the three icons with the text on what's currently happening.
- This would have similar appearance to what we already use for "View draft" (which is just a text button) and it would be less disruptive of the entire row - for example the user would still be able to see the idea name.
- The labels in that case could be much shorter, but they wouldn't lose meaning: We could rely on "Creating draft" and "Draft created", which would be also similar to the existing "View draft" button label later.
What do you think?
@felixarntz SGTM, as long as there is enough space to display the copy "Creating draft" and then "Draft created" even on smaller screens.
"Creating draft" copy should be shown immediately on click and then after 300 ms, "Draft created" copy should be shown.
@felixarntz @Pratheep-lab showing just static copy Creating draft isn't enough because it might confuse users. The expected behavior and the common pattern that is understood by all users is to show a progress bar or a spinner that will convince users that something is still being done and they need to wait a bit more. What do you think if we replace the text with a small progress bar?
- Using assets/js/modules/idea-hub/datastore/draft-ideas.js,
- Remove the reducerCallback which does the same thing as the new action above.
We can't remove the reducerCallback completely because it still needs to add the new draft to the draftPostIdeas array.
- Get the values of the following keys from the core/ui data store via the getValue selector
The core/ui datastore is not intended for keeping a state of different processes. It is intended to store UI-related information like which tab is selected in a widget. For the purpose of this task, let's add the appropriate actions and selectors to the idea-hub datastore to control the state of the draft post creation process.
Thanks, @asvinb. Please, check my comments regarding your IB ^.
@eugene-manuilov I agree, we did discuss a solution of both the loading spinner and the copy to be shown. I would recommend having both - a small loading spinner and the copy. CC: @felixarntz
@eugene-manuilov I've updated the IB to not use the core/ui data store. However I think it would be overkilled to add actions and selectors to the idea hub datastore for the state of each idea. I think we can simplify this by adding a state variable which we can use for any activity happening with the idea. I also suggested we remove the existing isProcessing state variable and just use the activity one. Thus we can easily add more activity states in the future. Let me know what you think.
@felixarntz Let me know your thoughts about the circular progress since it's not mentioned in the AC.
@asvinb the problem with the internal state is that it will be lost if I switch tabs during a draft post creation. We need to make sure the progress status persists for the idea.
@eugene-manuilov Good point, however we are not re-rendering the tabs when switching tabs. Instead the tabs were intentionally hidden via aria-hidden attributes so that we can keep the state of each tab.
however we are not re-rendering the tabs when switching tabs. Instead the tabs were intentionally hidden via
aria-hiddenattributes so that we can keep the state of each tab.
Each tab returns NULL if it is not active:
https://github.com/google/site-kit-wp/blob/e2564bf10f06d36b04c36ece7f66e2edbaf78f3f/assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/SavedIdeas.js#L70-L72 https://github.com/google/site-kit-wp/blob/e2564bf10f06d36b04c36ece7f66e2edbaf78f3f/assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/NewIdeas.js#L71-L73 https://github.com/google/site-kit-wp/blob/e2564bf10f06d36b04c36ece7f66e2edbaf78f3f/assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/DraftIdeas.js#L69-L71
It means that we do re-render ideas.
@eugene-manuilov Great point - let's do it as @Pratheep-lab has advised and show both the loading spinner and the copy in that state.
however we are not re-rendering the tabs when switching tabs. Instead the tabs were intentionally hidden via
aria-hiddenattributes so that we can keep the state of each tab.Each tab returns
NULLif it is not active:https://github.com/google/site-kit-wp/blob/e2564bf10f06d36b04c36ece7f66e2edbaf78f3f/assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/SavedIdeas.js#L70-L72
https://github.com/google/site-kit-wp/blob/e2564bf10f06d36b04c36ece7f66e2edbaf78f3f/assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/NewIdeas.js#L71-L73
https://github.com/google/site-kit-wp/blob/e2564bf10f06d36b04c36ece7f66e2edbaf78f3f/assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/DraftIdeas.js#L69-L71
It means that we do re-render ideas.
I completely missed that @eugene-manuilov . IB updated. Can you check?
@asvinb IB almost looks good to me. I have the last ask for you: let's make the activities be an object instead of an array. In this case, idea names will be keys and current activities their values.
Thanks @eugene-manuilov . Updated. I've also increased the estimate to 19 since there'll be some more QA time because of the UI changes.
IB :heavy_check_mark:
@asvinb @eugene-manuilov Thanks for the descriptive IB.
It all made sense except the last instructions
Remove the isProcessing state variable and instead use the getActivity state variable and set the value to ACTIVITY_IS_PROCESSING where isProcessing was originall set to true. Where it was set to false, use removeActivity.
Update the disabled logic for buttons to check for when getActivity is ACTIVITY_IS_PROCESSING.
The activity will already be set to IDEA_HUB_ACTIVITY_CREATING_DRAFT then IDEA_HUB_ACTIVITY_DRAFT_CREATED, and then cleared
The buttons are also hidden when one of these activities is happening.
I don't see why we need another activity type or to disable the buttons
I've created a PR for this task where you can see it working https://github.com/google/site-kit-wp/pull/3676/
https://user-images.githubusercontent.com/8496063/124963385-073dd480-e020-11eb-8d7d-d6101b141c5f.mp4
This may not be a concern when on the network but we risk showing the loading text for less than one second.
It all made sense except the last instructions
Remove the isProcessing state variable and instead use the getActivity state variable and set the value to ACTIVITY_IS_PROCESSING where isProcessing was originall set to true. Where it was set to false, use removeActivity. Update the disabled logic for buttons to check for when getActivity is ACTIVITY_IS_PROCESSING.The activity will already be set to
IDEA_HUB_ACTIVITY_CREATING_DRAFTthenIDEA_HUB_ACTIVITY_DRAFT_CREATED, and then clearedThe buttons are also hidden when one of these activities is happening.
I don't see why we need another activity type or to disable the buttons
@danielgent, yes, you are right. We don't need the ACTIVITY_IS_PROCESSING activity for the new draft callback. However, we need it for other callbacks. See my comment here: https://github.com/google/site-kit-wp/pull/3676#discussion_r666457989
QA Update: ⚠️
@danielgent In the AC it doesn't mention the loading icon which appears to the right hand side of the Creating draft text. The icon does shift the text a little further over to the left so doesn't align with the Draft created text when that appears.. Not sure if this icon should be there?
https://user-images.githubusercontent.com/73545194/125090645-dc12be00-e0cf-11eb-9efc-68f8e8ef3995.mp4
@danielgent could you please create a follow-up PR to adjust styles for the loading text to display it without line breaks?