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

Idea hub, loading indicator to show "Creating new draft"

Open Pratheep-lab opened this issue 5 years ago • 24 comments

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:

  1. User clicks on the "Start a draft" button
  2. An overlay appears on this idea row - (Grey area in the screenshot below)
  3. 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",

  1. As a nice to have, the number on the "Drafts" tab does a subtle animation to show that it increased.

image


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 newIdeas and savedIdeas state variables.
    • Update reducerCallback to remove the code where newIdeas and savedIdeas are updated.
  • 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.
  • Using assets/js/modules/idea-hub/datastore/idea-state.js,
    • Add activities to the initial state with an empty object as default value.
    • Add the setActivity action which has 2 parameters:
      • key: string which will be the idea name
      • value: string which will store the current activity of the idea, i.e whether a draft is being created or has been created.
    • The setActivity will add the key and value to the activities object.
    • Add the removeActivity action which as a single parameter:
      • key: string, which is the idea name.
    • removeActivity will remove the item with the specified key from the activities object.
    • Add the getActivity selector which will return the activity of an idea based on the key from the activities object.
    • The above implementation should be inspired by the core/ui data store.
  • Using assets/js/modules/idea-hub/components/dashboard/DashboardIdeasWidget/Idea.js,
    • Update the handleCreate function to dispatch the setActivity action, with the idea name as key and the value set to ACTIVITY_CREATING_DRAFT. This should be done before createIdeaDraftPost is called.
    • After createIdeaDraftPost has been called,
      • call setActivity with the value set to ACTIVITY_DRAFT_CREATED and idea name as key.
      • After another 2 seconds, dispatch the removeActivity action 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.
    • Get the activity of the idea via the getActivity selector passing the idea name as key. Based on the value returned by the selector,
      • Update the conditions to display the buttons in the googlesitekit-idea-hub__idea--actions container if getActivity is ACTIVITY_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 CircularProgress component, imported from @material-ui/core can be used. The size of the CircularProgress should be 10, with a margin right of 8px from the text.
      • Update the conditions to display the buttons in the googlesitekit-idea-hub__idea--actions container if getActivity is ACTIVITY_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 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.

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 avatar May 20 '21 12:05 Pratheep-lab

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

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

Pratheep-lab avatar Jun 11 '21 15:06 Pratheep-lab

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

eugene-manuilov avatar Jun 30 '21 12:06 eugene-manuilov

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

eugene-manuilov avatar Jun 30 '21 12:06 eugene-manuilov

Thanks, @asvinb. Please, check my comments regarding your IB ^.

eugene-manuilov avatar Jun 30 '21 12:06 eugene-manuilov

@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

Pratheep-lab avatar Jun 30 '21 14:06 Pratheep-lab

@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 avatar Jul 01 '21 11:07 asvinb

@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 avatar Jul 01 '21 12:07 eugene-manuilov

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

asvinb avatar Jul 01 '21 13:07 asvinb

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.

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 avatar Jul 01 '21 14:07 eugene-manuilov

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

felixarntz avatar Jul 01 '21 21:07 felixarntz

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.

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.

I completely missed that @eugene-manuilov . IB updated. Can you check?

asvinb avatar Jul 05 '21 13:07 asvinb

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

eugene-manuilov avatar Jul 05 '21 18:07 eugene-manuilov

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.

asvinb avatar Jul 06 '21 07:07 asvinb

IB :heavy_check_mark:

eugene-manuilov avatar Jul 06 '21 09:07 eugene-manuilov

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

danielgent avatar Jul 08 '21 17:07 danielgent

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.

danielgent avatar Jul 08 '21 17:07 danielgent

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

@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

eugene-manuilov avatar Jul 08 '21 19:07 eugene-manuilov

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

wpdarren avatar Jul 09 '21 14:07 wpdarren

@danielgent could you please create a follow-up PR to adjust styles for the loading text to display it without line breaks?

eugene-manuilov avatar Jul 09 '21 14:07 eugene-manuilov