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

Add Restricted Course Content block #3849

Merged
merged 18 commits into from
Jan 21, 2021

Conversation

gikaragia
Copy link
Contributor

@gikaragia gikaragia commented Dec 14, 2020

Changes proposed in this Pull Request

  • This PR introduces a new blocks to the single course page, 'Restrict Content' (naming suggestions welcome 😄 ).
  • The block is similar to how the 'Group' block works but they show the content to enrolled, unenrolled or users which completed a course only.
  • I investigated to possibly add the blocks to the single lesson page too. Currently in the single lesson template we don't show the content at all when the user is not enrolled. For this reason we should probably wait until we drop the single lesson template to see if it fits to add these blocks.

Update:

  • It is possible to transform any selection of blocks to move it inside a wrapper 'Enrolled Content' or 'Unenrolled Content' block. This allows users easily to restrict the content after it is created. When transforming one of these blocks to the inverse one, a wrapper is not created and the block is switched instead.
    record

Second Update:

  • There is now a single block for all cases. The user can select between different options by using a dropdown. It also has a new option which restricts the content to users which completed a course.
    button
  • Since there wasn't an intuitive option to remove the restriction once the block is created, I also added an option to the drop down menu which removes the 'Restrict content' block. Basically it replaces the block whith its inner blocks
    remove
  • I have considered the suggestions in this comment but I decided against them for the following reasons:
    • The toolbar should follow gutenberg's minimalistic approach so any not absolutely necessary text should be avoided. The ideal way to do this would be to have the selected icon on the toolbar and the options on the dropdown should be a button with the icon and a few words, similar with the rest of the dropdown menus. Additionally this would require more time to implement.
    • I used text only for now to avoid the extra work of creating new icons.
    • Since the button can be considered as a title too, I think that we don't need any extra indicator to explain that the content will be hidden. We can revise this if users find the block confusing.

Testing instructions

  • In a course include the new block and add some content in them.
  • Try the 'Enrolled Users', 'Unenrolled Users' and 'Course Completed' options and observe that the content is displayed (or not) accordingly in the frontend.
  • Try selecting multiple blocks and transform them to a 'Restrict content' block.
  • Try removing the restriction from a block.

@gikaragia gikaragia requested a review from a team December 14, 2020 11:32
@@ -0,0 +1,67 @@
<?php
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Written this class as part of my investigation of adding the blocks to the lesson page. Happy to remove it since it is unused.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could remove this since it's being worked in the other PRs of the lesson blocks :)

@donnapep
Copy link
Collaborator

Dropping a quick note that this one should go through a design review before being merged. Making a note to do that this week.

@yscik
Copy link
Contributor

yscik commented Dec 14, 2020

Nice!

A few things that would be good to have in this:

  • Add block transform to wrap any block in Enrolled/Unenrolled. This way the user can group existing blocks into a restricted block. This probably also covers switching Enrolled to Unenrolled and vice-versa.
  • Full/wide alignment options do not work inside these blocks. Maybe they could be always full-width? Or have alignment options, but could be cleaner if they are just layout-agnostic, if it's possible.

@yscik
Copy link
Contributor

yscik commented Dec 14, 2020

Design-wise, I think the main thing here is a way to indicate in the editor when content is restricted. This is kind of a wider issue of making a parent block more visible, that also came up with the course outline block, and will hopefully be handled by Gutenberg at some point. Until then, we should roll our own solution, but it's worth a dedicated PR.

The core Gallery block already selects both the container an the inner block:

image

Jetpack's Repeat Visitor block has a note, but it's unclear where the block ends:

image

I also explored some options in Conditional Sections for Course Enrollment Blocks (p6rkRX-1Dd-p2):

Outline and labels:
image

Sections:
image

@alexsanford
Copy link
Contributor

Dropping a quick note that this one should go through a design review before being merged.

cc @pablohoneyhoney

@gikaragia
Copy link
Contributor Author

Nice!

A few things that would be good to have in this:

* Add block transform to wrap any block in Enrolled/Unenrolled. This way the user can group existing blocks into a restricted block. This probably also covers switching Enrolled to Unenrolled and vice-versa.

* Full/wide alignment options do not work inside these blocks. Maybe they could be always full-width? Or have alignment options, but could be cleaner if they are just layout-agnostic, if it's possible.

Great ideas! Added transforms and alignment options (following the group block).

Copy link
Contributor

@yscik yscik left a comment

Choose a reason for hiding this comment

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

Code is looking good, just a few notes:

type: 'block',
isMultiBlock: true,
blocks: [ '*' ],
__experimentalConvert: ( blocks ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a transform(attributes, innerBlocks) function as a stable API, any reason this one is used?

Copy link
Contributor Author

@gikaragia gikaragia Dec 15, 2020

Choose a reason for hiding this comment

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

Yes transform includes the attributes and inner blocks only but we need the plugin name which is provided by convert. It also supports better multiple selections. It seems to be the plan to deprecate transform in favor of convert so I thought that it is safe enough to use.

assets/blocks/restricted-content/enrolled/block.json Outdated Show resolved Hide resolved
includes/blocks/class-sensei-course-blocks.php Outdated Show resolved Hide resolved
Comment on lines 96 to 98
title: __( 'Unenrolled Content', 'sensei-lms' ),
description: __(
'Content inside this container block will be displayed to unenrolled users only.',
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we use unenrolled anywhere, something like ..users not enrolled might sound better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 94e3470. I don't like unenrolled too but couldn't find a better alternative. Hoping for a better recommendation by the design review cc @donnapep

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.

Cool! I think this feature will be very useful! Did you also think about the option to create a single block with multiple states as a setting (enrolled, unenrolled, course completed...)?

For the design meeting, maybe would be nice to think about the unenrolled icon too. The open padlock gives a sensation that it is unlocked for any user (although the title says clearly the block purpose).

cc @donnapep

assets/blocks/sensei-single-course-blocks.js.js Outdated Show resolved Hide resolved
@gikaragia
Copy link
Contributor Author

gikaragia commented Dec 16, 2020

Cool! I think this feature will be very useful! Did you also think about the option to create a single block with multiple states as a setting (enrolled, unenrolled, course completed...)?

Yep I considered it but thought that separate blocks are probably more easy to understand.

@donnapep donnapep added the [Status] Needs Design Requires design feedback label Dec 17, 2020
@pablohoneyhoney
Copy link

pablohoneyhoney commented Dec 18, 2020

While the use case makes sense, it'd be better to think of this as an implementation that shares paradigms to similar cases like Pay Wall in Dotcom.

@alexsanford worth connecting with @fditrapani and @artpi, and more recently @apeatling
Some context https://heytimmyneutron.wordpress.com/2020/03/04/premium-content-block-i3/
I haven't found related issues.

Additionally, it's more natural to think of the premium/extra content as the block to be added, rather than creating a paradox of rolled/unrolled. So the creator has the clarity that in order to add special content, they need to add the Premium (or whatever the right term is) block.

@alexsanford
Copy link
Contributor

shares paradigms to similar cases like Pay Wall in Dotcom.

Good point, the "Premium Content" block on dotcom seems like a good place from which to draw inspiration.

Additionally, it's more natural to think of the premium/extra content as the block to be added, rather than creating a paradox of rolled/unrolled.

I think both paradigms are needed. A concrete example that came up when building WP Courses was the need to have sales copy on the Course page that only displays for non-enrolled users.

Note that the Premium Content block has this capability; the "Visitor View" is a fully editable container. Perhaps it would make sense to do something similar, having a "Visitor View" and "Learner View"?

@yscik
Copy link
Contributor

yscik commented Dec 18, 2020

The content for Enrolled/unenrolled users is not necessarily connected — someone could just want to hide the outline to guest users, or add some extra content, like a sales copy, or a welcome message. I wouldn't push this in the direction where the content is toggled based on a state.

We can merge these into a single Restricted block, with a setting on who can see it:
image

I think the main challenge here is to indicate the visibility of these blocks when they are not selected, so the user can have a better overview of what's in the post. Even just a subtle icon would help:
image

@alexsanford alexsanford added [Status] Needs Design Review and removed [Status] Needs Design Requires design feedback labels Dec 18, 2020
@gikaragia gikaragia requested review from a team, renatho and yscik January 11, 2021 16:09
@gikaragia gikaragia mentioned this pull request Jan 12, 2021
renatho
renatho previously approved these changes Jan 15, 2021
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.

It works well, and from the code perspective, it looks good to me!
I added a few comments, but nothing critical.

Before merging, it worths it to wait for UX/product feedback.

I investigated to possibly add the blocks to the single lesson page too. Currently in the single lesson template we don't show the content at all when the user is not enrolled. For this reason we should probably wait until we drop the single lesson template to see if it fits to add these blocks.

Nice! When we can, I think it would be nice to use this block in the lessons too, and maybe in the quizzes.

assets/blocks/restricted-content/block.json Outdated Show resolved Hide resolved
@@ -0,0 +1,67 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could remove this since it's being worked in the other PRs of the lesson blocks :)

assets/blocks/restricted-content/settings.js Outdated Show resolved Hide resolved
assets/blocks/restricted-content/settings.js Show resolved Hide resolved
@yscik
Copy link
Contributor

yscik commented Jan 18, 2021

One minor thing, the toolbar button and dropdown should be left aligned, and have no extra spacing/fixed width. It's fine if the width changes when the user selects something else.
image

@gikaragia gikaragia changed the base branch from master to add/toolbar-dropdown January 20, 2021 08:40
@gikaragia
Copy link
Contributor Author

Otherwise, I think this is good to go for a first iteration. I didn't do any code review, do we still have any outstanding questions there? Are there any design or UX questions that we need more input on?

There were Peter's comments about the popover but these should be solved as with the latest rebase I switched to using the common one introduced in #3904.

Base automatically changed from add/toolbar-dropdown to feature/lessons-block January 21, 2021 13:37
Copy link
Contributor

@alexsanford alexsanford left a comment

Choose a reason for hiding this comment

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

Tested and works well, code LGTM! Note that I used the Github feature to merge the latest from feature/lessons-block into this branch.

@gikaragia gikaragia added this to the 3.8.0 milestone Jan 21, 2021
@gikaragia gikaragia merged commit 17a321d into feature/lessons-block Jan 21, 2021
@donnapep donnapep deleted the add/enrolled-content-block branch January 25, 2021 18:50
@donnapep donnapep changed the title Add restricted content blocks Add Restricted Course Content block Jan 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants