Skip to content

Conversation

@gumaerc
Copy link
Contributor

@gumaerc gumaerc commented Sep 9, 2024

What are the relevant tickets?

Closes https://github.com/mitodl/hq/issues/5297

Description (What does it do?)

This PR adds "add to list" buttons to the learning resource drawer. When you bring up the drawer, if you are a learning path editor you will see both the add to learning path and user list buttons. If you are a normal user, you will only see the add to userlist button, just like how it works on cards.

Screenshots (if appropriate):

image
image

How can this be tested?

  • Spin up mit-learn on this branch
  • Make sure you have some data populated into your database and have generated a search index
  • Log in as a superuser
  • Visit the search page at http://localhost:8062/search
  • Click on any search result to display the learning resource drawer
  • In the drawer, you should see both the add to learning path and add to user list buttons
  • Test out both buttons, adding the resource to both a learning path and user list
  • Log out of your superuser and log in as a normal user
  • Repeat the process, but ensure that only the "add to user list" bookmark button shows up

@gumaerc gumaerc added the Needs Review An open Pull Request that is ready for review label Sep 9, 2024
})

const section = screen
.getByRole("heading", { name: "Info" })!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.getByRole("heading", { name: "Info" })!
.getByRole("heading", { name: "Info" })

getBy will always be non-null.

Suggestion: I would just skip the non-null assertions all together and call invariant(section) if you need to refine the type. The error message will be better if it did happen to be null. Also, imo, we should add a linting rule forbidding the non-null assertions.

Info
</Typography>
<ListButtonContainer>
{user?.is_authenticated && user?.is_learning_path_editor && (
Copy link
Contributor

Choose a reason for hiding this comment

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

mentioning: Just user?.is_learning_path_editor should be fine

{user?.is_authenticated && (
<CardActionButton
filled={inUserList}
aria-label="Add to User List"
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably best dealt with in a separate PR for all the cards at once, but we did have accessibility feedback that this label text is confusing, suggesting "Bookmark Resource(course?video?)" instead, or "Save..."

// user info is still loading
return null
}
if (user.is_authenticated) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: drop the conditional above and

Suggested change
if (user.is_authenticated) {
if (user?.is_authenticated) {

const expectedButtons =
expectAddToLearningPathButton && expectAddToUserListButton ? 2 : 1
expect(buttons).toHaveLength(expectedButtons)
if (expectAddToLearningPathButton) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion: I like to do

expect(
  !!within(section).queryByRole("button", {name: "Add to Learning Path" })
).toBe(expectAddToLearningPathButton)

because:

  • no conditional => we're sure the assertion is always running
  • currently this asserts presence in the truthy case. With the queryBy version, it also asserts absence in the falsy case. (I guess you do that right now with the button count).

@gumaerc gumaerc merged commit b64bcb8 into main Sep 10, 2024
@odlbot odlbot mentioned this pull request Sep 12, 2024
17 tasks
@rhysyngsun rhysyngsun deleted the cg/learning-resource-drawer-bookmark branch February 7, 2025 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review An open Pull Request that is ready for review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants