Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show notice in Course Editor to focus on Course Outline block or Insert one if block does not exist for first time users #7364

Closed

Conversation

Imran92
Copy link
Contributor

@Imran92 Imran92 commented Dec 6, 2023

Resolves #7331

Proposed Changes

New users often don't know where they can add lessons, or sometimes, they don't know about the need of Course Outline block. So here, we've added a notice in the Course Editor that is shown to only those users who have not created any course yet.

Clicking on the link on that notice will focus (and scroll to, if necessary) on the Course Outline block if there is already one added in the editor.

If the Course Outline block is not there in the editor, it'll create one for the user. If at least one of the lessons in the Course Outline block is published, this notice will disappear.

To not bother the existing users, we've taken some measures. If the user has authored any course, this notice isn't shown to them. Once the user dismisses the notice, it's not shown to them anymore.

One thing to be noted is, that the dismissed flag is stored in localStorage. So the user may see it in a different browser or device. But it may not be very likely because once the user is in the Course editor, and playing around with it, there's a high probability that they'll have authored at least a course. So I didn't want to add another user meta for it as it may turn out to be not very useful.

I'll add some more tests for testing all the edge cases either in this PR, or a new one. I'm temporarily moving on to another issue.

Testing Instructions

  1. Create a new User who can create course
  2. Create a new Course
  3. Check that you see the desired notice on top
  4. Click on the offline outline (Start with blank) or generate lessons with AI (Generate with AI)
  5. Click on the add some lessons link on the notice
  6. Make sure it takes the focus to the Course Outline block
  7. Now delete all content from the editor
  8. Now insert a pattern from Block Inserter (+ button on Top Toolbar of GB) -> Patterns -> Sensei LMS -> (Select any long pattern)
  9. Now click on the 'add some lessons' link in the notice again
  10. Make sure it scrolls you to the Course Outline block
  11. Now remove everything again, or at least the Course Outline block
  12. Click on the aforementioned link
  13. Make sure it adds a Course Outline block in the editor
  14. Now click on a lesson, from its toolbar, click 'Edit Lesson', and in the lesson editor, publish the lesson. Remember you are publishing only the lesson, not the course
  15. Go back to the Course editor
  16. Make sure the notice isn't there anymore
  17. Create another similar user
  18. Create a course. This time in the editor, dismiss the notice
  19. Refresh the window, make sure the notice isn't appearing anymore
  20. Now log in with an user who has authored at least one course
  21. Make sure you don't see the notice for the user
Screen.Recording.2023-12-06.at.11.51.46.PM.mov

Pre-Merge Checklist

  • PR title and description contain sufficient detail and accurately describe the changes
  • Acceptance criteria is met
  • Decisions are publicly documented
  • Adheres to coding standards (PHP, JavaScript, CSS, HTML)
  • All strings are translatable (without concatenation, handles plurals)
  • Follows our naming conventions (P6rkRX-4oA-p2)
  • Hooks (p6rkRX-1uS-p2) and functions are documented
  • New UIs are responsive and use a mobile-first approach
  • New UIs match the designs
  • Different user privileges (admin, teacher, subscriber) are tested as appropriate
  • Code is tested on the minimum supported PHP and WordPress versions
  • User interface changes have been tested on the latest versions of Chrome, Firefox and Safari
  • "Needs Documentation" label is added if this change requires updates to documentation
  • Known issues are created as new GitHub issues

@Imran92 Imran92 added this to the 4.19.3 milestone Dec 6, 2023
@Imran92 Imran92 requested a review from a team December 6, 2023 18:32
@Imran92 Imran92 self-assigned this Dec 6, 2023
Copy link

github-actions bot commented Dec 6, 2023

WordPress Dependencies Report

The github-action-wordpress-dependencies-report action has detected some script changes between the commit ad3aeee and trunk. Please review and confirm the following are correct before merging.

Script Handle Added Dependencies Removed Dependencies Total Size Size Diff
js/admin/first-course-creation-notice.js lodash, wp-blocks, wp-data, wp-dom-ready, wp-i18n, wp-polyfill 1.99 kB +1.99 kB ( +100% 🔼 )
admin/editor-wizard/index.js 12.4 kB +4 B ( +0.04% 🔼 )

This comment was automatically generated by the github-action-wordpress-dependencies-report action.

Copy link

codecov bot commented Dec 6, 2023

Codecov Report

Attention: Patch coverage is 34.11765% with 56 lines in your changes missing coverage. Please review.

Project coverage is 50.93%. Comparing base (1d0f103) to head (ad3aeee).
Report is 992 commits behind head on trunk.

Files with missing lines Patch % Lines
includes/class-sensei-course.php 0.00% 38 Missing ⚠️
assets/js/admin/first-course-creation-notice.js 63.04% 10 Missing and 7 partials ⚠️
assets/admin/editor-wizard/steps/patterns-step.js 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##              trunk    #7364      +/-   ##
============================================
- Coverage     50.96%   50.93%   -0.04%     
- Complexity    11159    11161       +2     
============================================
  Files           614      614              
  Lines         47085    47163      +78     
  Branches        405      413       +8     
============================================
+ Hits          23996    24021      +25     
- Misses        22762    22808      +46     
- Partials        327      334       +7     
Files with missing lines Coverage Δ
assets/admin/editor-wizard/steps/patterns-step.js 21.73% <0.00%> (ø)
assets/js/admin/first-course-creation-notice.js 63.04% <63.04%> (ø)
includes/class-sensei-course.php 38.35% <0.00%> (-0.75%) ⬇️

... and 8 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d38577f...ad3aeee. Read the comment docs.

@donnapep
Copy link
Collaborator

donnapep commented Dec 7, 2023

Hey @Imran92! Did a super quick test.

  1. It looks like the notice is displayed as soon as I go into the editor. It should only be displayed as per this criteria:

Notice is triggered when a user creates their first course and after selecting a course layout.

  1. Also, I'm reconsidering this criteria:

Notice is no longer displayed as soon as the course contains at least one published lesson

I'm thinking perhaps we should change it to:

Notice is no longer displayed as soon as the course contains at least one lesson, regardless of status

If I saw that notice that asked me to add some lessons, and I did that, I'd be confused as to why the notice was still there. Then, I think we could catch the issue with draft lessons by tweaking this frontend notice and adding a CTA (though as part of a separate issue and PR):

Screenshot 2023-12-07 at 4 08 11 PM

  1. I think this criteria hasn't been met, but perhaps it would also benefit from some tweaking:

Notice is not displayed for subsequent courses the user may create.

I created 2 courses and didn't add lessons to either of them, but I saw the notice in both. After I published a lesson in the first course, I still saw the notice in the second course. I'm happy to go with whichever of these is easiest to implement:

  • Implement the criteria as described; that is, tie the notice to the first course the user creates and only to the first course the user creates.
  • Leave the notice on both, but don't show it on any course after lessons have been added to either of them.

Please let me know your thoughts on all of this. 🙇🏻‍♀️

@Imran92
Copy link
Contributor Author

Imran92 commented Dec 12, 2023

Thanks for checking it @donnapep !

  1. It looks like the notice is displayed as soon as I go into the editor. It should only be displayed as per this criteria:

I've updated it here ddb29ea, now the notice will only be shown after a pattern is selected

If I saw that notice that asked me to add some lessons, and I did that, I'd be confused as to why the notice was still there

Agreed, I'm updating it here 4bc987c to show the notice only when there are no lessons in it.

Notice is not displayed for subsequent courses the user may create.

Oh, it was only considering if you've published a course. I've updated the logic here f424669 to consider any Course of any status. Showing it the first time sounds better as it helps with having less notice cluttering on the top.

I think we could catch the issue with draft lessons by tweaking this frontend notice and adding a CTA (though as part of a separate issue and PR):

Absolutely agree with this one. After seeing the deep dive, I think any improvement here that helps with publishing the course and lessons properly is worth doing.

@donnapep
Copy link
Collaborator

donnapep commented Dec 14, 2023

@Imran92 It's better, but still isn't quite working as expected for me. The notice is now showing after a course layout is selected, but if I save the course without adding any lessons, and then come back in later, the notice isn't there anymore.

Also, looks like some tests are broken.

@donnapep donnapep removed this from the 4.19.3 milestone Dec 14, 2023
@Imran92 Imran92 added this to the 4.20.1 milestone Dec 15, 2023
@Imran92 Imran92 closed this Dec 15, 2023
@Imran92 Imran92 reopened this Dec 15, 2023
@Imran92
Copy link
Contributor Author

Imran92 commented Dec 15, 2023

Thanks for taking a look @donnapep !

I've updated the logic here e84c62a to load the notice scripts only when the user has at least a lesson created under a course.

Here, I've gone with the following approach, as it required less checking with db query

Leave the notice on both, but don't show it on any course after lessons have been added to either of them.

I've left some edge case behaviors, but wanted to surface them here to get your opinion on them -

  • User has created lessons without associating with any courses: If the user has created any lesson that are not associated with any course, then we still show the notice on Courses
  • User has deleted the course after creating: If the user deletes only the Course after creating a Course with lessons, we're not doing any special handling for that.
  • User has deleted the lessons after creating: If the user creates a Course with lessons, but then deletes the lessons, we don't keep a track of that
  • User saves Course without adding any lesson, but then closes and reopens: As per our need, when the user creates a new Course, we show the notice only after the user has selected a pattern. But if the user decides to save the Course without any lesson then closes the window, and opens the same course again to edit it, we show the notice right away. Because we don't show the pattern picker modal again. And if the user has already selected a pattern the last time, it's not straightforward to detect if a pattern was used (we can keep a meta, or flag in storage, but I wasn't sure the extra work to cover this edge case was necessary). So as there no modal to block the viewport, and if the user is eligible of seeing the notice, we show the user the notice right away when they open a saved course for editing later.

Thanks!

@donnapep
Copy link
Collaborator

donnapep commented Dec 15, 2023

@Imran92 Thanks! The logic looks good. I had a bit of confusion when testing. At one point, the notice stopped showing for new users. 😱 After stepping through code, I realized it was because I had previously dismissed the notice, which I see is tracked in local storage. Is this how WordPress typically handles client-side notices? I know for server-side it's usually an option in the wp_options table. But if so, I think it would be helpful to mention it in the PR description as I think it could fool others too. 🙂

An FYI that I haven't done a code review; I've only tested the behavior & logic. Given our discussion about not really needing this for when a user selects a pattern from the block inserter, if there is any feedback from a code review that requires reworking the patterns code, please just remove that logic. It's not part of the flow that new users are most likely going to move through, and so is not the flow we're most interested in capturing. No sense in spending any more time there. 🙂 I'm also hoping this notice will be temporary until we're able to secure a design resource to help us with this. Thx!

Copy link
Contributor

@renatho renatho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, it looks good.

But I'd like to propose something. IMO, this is a very small helper which doesn't worth such complexity to maintain. My suggestion would be:

  • Don't worry about persisting the dismiss, since it would simplify the code, and it's a helper to "jump" to the Course Outline for new courses.
  • Since we won't display the notice when having draft lessons, create the notice as soon as the wizard is closed (skipping earlier or choosing a pattern), and remove the notice when:
    • Clicking on "add some lessons".
    • When clicking on the "X".
    • When clicking on the course outline actions "Start with blank" or "Generate with AI".

With that, we don't need to:

  • Monitor the dispatch.
  • Subscribe the store.
  • Have any backend logic.
  • Have new JS assets (we can have a file imported in the course-edit.js).
  • Worry about persistency.
  • Worry if the post is new or not.

WDYT? cc @donnapep

assets/js/admin/first-course-creation-notice.js Outdated Show resolved Hide resolved
const { insertBlock } = dispatch( 'core/block-editor' );

courseOutlineBlock = createBlock( 'sensei-lms/course-outline' );
await insertBlock( courseOutlineBlock );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test it, but I think the selection happens by default given the documentation (updateSelection defaults to true).

If confirmed, I think it doesn't need to be an async function, and we can add the following selection in an else. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, I've updated the code here a633f08

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Imran92!
With this, I think the function doesn't need to be async anymore, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! Removed here 3d47a01, thanks @renatho

let noticeRemoved = false;

const notice = __(
'Nice! Now you can <a href="javascript:;" onclick="window?.handleCourseOutlineBlockIncomplete();">add some lessons</a> to your course.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My suggestion wouldn't match the design, but it would match the default behavior of the Gutenberg notices.

Should we tweak it to use a separate button, being the actions from the Gutenberg notice instead? cc @donnapep

So we wouldn't need to put the function in the window, we wouldn't need to add the onclick and href="javascript:;" as HTML attributes, it would get more organized in terms of code, and the users would the same behavior of other notices.

If we decide to not change it, we need to extract the HTML and logic from the translation string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're good with the design change, we can go for it 👍 Our current design of showing it as a URL looks better to me. But as showing it as button is simpler, as that's the default behavior. I think the main benefit of this will be not having to use the __unstableHTML property.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with changing it to use a button if it helps simplify things. In that case, we could change the message to:

Nice! Now you can add some content to your course. Add Lessons

where Add Lessons is a button that jumps to / adds the Course Outline block.

Let's see what that looks like. 🙂

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated comment here 🙂

@Imran92
Copy link
Contributor Author

Imran92 commented Jan 1, 2024

Thanks for checking @donnapep!

Is this how WordPress typically handles client-side notices? I know for server-side it's usually an option in the wp_options table. But if so, I think it would be helpful to mention it in the PR description as I think it could fool others too. 🙂

Yap you are right, if it's a global notice to be shown once, it's saved in wp_options, and for per-user notices, the flag is saved in wp_usermeta. I didn't find a convention for handing this in the frontend. I've shared my thoughts in the PR description for it-
One thing to be noted is, that the dismissed flag is stored in localStorage. So the user may see it in a different browser or device. But it may not be very likely because once the user is in the Course editor, and playing around with it, there's a high probability that they'll have authored at least a course. So I didn't want to add another user meta for it as it may turn out to be not very useful.
But if we think it's necessary to save it as meta and it can have other usage too or can be important data, we can add it.

It's not part of the flow that new users are most likely going to move through, and so is not the flow we're most interested in capturing

Thanks! I've removed it here ee75e87 .

@Imran92
Copy link
Contributor Author

Imran92 commented Jan 1, 2024

Thanks @renatho for your nice suggestion and the new approach you suggested, I'm good with having a version with a bit of a smaller set of requirements for it. My only concern is I'm not sure users who are familiar with the Sensei environment (from the perspective of our current set of requirements, they are users who have created any lesson that belongs to any course) would like to see a notice on top. And also, even though we have an extra asset, it's loaded only for the specific case of the first Course. A little benefit that I like about this is we load less code if all subsequent usages. But I'm okay to load it as part of course-edit.js too, no problem!

Thanks again! <3

Otherwise php above 8 throws an error in testing. So we manually set the _new_post to true for new post. If we do it in backed, it causes the new course modal to appear for existing courses
@donnapep
Copy link
Collaborator

donnapep commented Jan 8, 2024

Thanks @renatho for your nice suggestion and the new approach you suggested, I'm good with having a version with a bit of a smaller set of requirements for it. My only concern is I'm not sure users who are familiar with the Sensei environment (from the perspective of our current set of requirements, they are users who have created any lesson that belongs to any course) would like to see a notice on top.

After thinking about this for a bit, if Renatho's suggestions #7364 (review) significantly simplify the logic, I'm open to displaying this notice for existing users too. I would want to tweak the messaging though:

There are no lessons in your course. Add some now"

where "Add some now" is a button that jumps to / adds the Course Outline block.

@donnapep donnapep removed this from the 4.20.1 milestone Jan 15, 2024
@m1r0 m1r0 added this to the 4.20.2 milestone Jan 17, 2024
@donnapep
Copy link
Collaborator

donnapep commented Feb 5, 2024

We're pausing this work until we get through some of the other onboarding improvements.

@donnapep donnapep removed this from the 4.20.2 milestone Feb 5, 2024
@Imran92
Copy link
Contributor Author

Imran92 commented Oct 29, 2024

Maybe we can close this as we have the Course tour now?

@donnapep donnapep closed this Nov 11, 2024
@donnapep donnapep deleted the add/notice-to-create-course-outline-block-first-time branch November 11, 2024 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add notice in editor to direct next steps after selecting course layout
4 participants