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

feat: redirect to unit page if the hit or its parent is a unit #957

Conversation

rpenido
Copy link
Contributor

@rpenido rpenido commented Apr 19, 2024

Description

This PR adds the feature to redirect from a search result to a Unit, in case the hit parent is a Unit, or the hit is a unit itself.

More Information:

Closes:

Depends on:

Testing Instructions

  1. Go to the Course Authoring MFE, e.g. http://apps.local.edly.io:2001/course-authoring/home
  2. Optionally, browse to a specific course.
  3. Click on the search icon in the header
  4. Search for a Unit and/or a component inside a unit and click on it
  5. You should be redirected to the unit page and the selected component should be highlighted (if any).

Private ref: FAL-3709

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Apr 19, 2024
@openedx-webhooks
Copy link

openedx-webhooks commented Apr 19, 2024

Thanks for the pull request, @rpenido! Please note that it may take us up to several weeks or months to complete a review and merge your PR.

Feel free to add as much of the following information to the ticket as you can:

  • supporting documentation
  • Open edX discussion forum threads
  • timeline information ("this must be merged by XX date", and why that is)
  • partner information ("this is a course on edx.org")
  • any other information that can help Product understand the context for the PR

All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here.

Please let us know once your PR is ready for our review and all tests are green.

@rpenido rpenido force-pushed the rpenido/fal-3709-allow-redirect-to-the-unit-page-from-search-results branch 5 times, most recently from 33b131e to 9798dc3 Compare April 22, 2024 14:58
Copy link

codecov bot commented Apr 23, 2024

Codecov Report

Attention: Patch coverage is 97.95918% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 92.09%. Comparing base (5686dee) to head (0493375).
Report is 3 commits behind head on master.

Files Patch % Lines
src/course-unit/hooks.jsx 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #957      +/-   ##
==========================================
+ Coverage   92.02%   92.09%   +0.06%     
==========================================
  Files         686      685       -1     
  Lines       11955    12090     +135     
  Branches     2598     2637      +39     
==========================================
+ Hits        11002    11134     +132     
- Misses        917      920       +3     
  Partials       36       36              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rpenido rpenido force-pushed the rpenido/fal-3709-allow-redirect-to-the-unit-page-from-search-results branch 5 times, most recently from fc5df69 to 0d38d98 Compare April 24, 2024 12:39
@rpenido rpenido force-pushed the rpenido/fal-3709-allow-redirect-to-the-unit-page-from-search-results branch from 0d38d98 to 9901d9b Compare April 24, 2024 12:48
@rpenido rpenido force-pushed the rpenido/fal-3709-allow-redirect-to-the-unit-page-from-search-results branch from 64c630e to 949b3c6 Compare April 24, 2024 14:36
@ChrisChV
Copy link
Contributor

@rpenido

You should be redirected to the unit page and the selected component should be highlighted (if any).

When I search for a component it does not redirect me to the unit page:

https://www.loom.com/share/1c5633da07804908980a158e3dfc0289?sid=638b4634-5b63-461c-9206-5548d5ccf2e3

@rpenido
Copy link
Contributor Author

rpenido commented Apr 24, 2024

@rpenido

You should be redirected to the unit page and the selected component should be highlighted (if any).

When I search for a component it does not redirect me to the unit page:

https://www.loom.com/share/1c5633da07804908980a158e3dfc0289?sid=638b4634-5b63-461c-9206-5548d5ccf2e3

Hi @ChrisChV! Thank you for your input!
It seems that your breadcrumbs are broken. Could you check if you are using openedx/edx-platform#34535 and please run tutor dev run cms ./manage.py cms reindex_studio --experimental again?

@rpenido rpenido force-pushed the rpenido/fal-3709-allow-redirect-to-the-unit-page-from-search-results branch 2 times, most recently from 0e4d37f to 1954667 Compare April 24, 2024 18:01
@rpenido rpenido force-pushed the rpenido/fal-3709-allow-redirect-to-the-unit-page-from-search-results branch from 1954667 to 78dc0c4 Compare April 24, 2024 18:04
Copy link
Contributor

@ChrisChV ChrisChV left a comment

Choose a reason for hiding this comment

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

@rpenido Thanks! It works 👍

  • I tested this: I followed the testing instructions
  • I read through the code and considered the security, stability and performance implications of the changes.
  • I tested that the UI can be used with a keyboard only (tab order, keyboard controls).
  • Includes tests for bugfixes and/or features added.

@rpenido rpenido marked this pull request as ready for review April 25, 2024 19:23
@rpenido rpenido requested a review from a team as a code owner April 25, 2024 19:23
@rpenido rpenido requested a review from xitij2000 April 25, 2024 19:23
Copy link
Contributor

@xitij2000 xitij2000 left a comment

Choose a reason for hiding this comment

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

I think this is looking good.

I just have one minor nit about reusing styles. The other point is entirely optional since I don't see anything wrong with the current implementation.

Comment on lines 13 to 21
@keyframes glow {
0% {
box-shadow: 0 0 5px 5px $primary-500;
}

100% {
box-shadow: unset;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This exact same animation already exists in CourseOutline.scss, can you boost it to a more common location and reuse the code instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the suggestion @xitij2000! I moved it here: 0493375

Comment on lines +71 to +74
if (courseXBlockElementRef.current && (shouldScroll || isScrolledToElement)) {
scrollToElement(courseXBlockElementRef.current);
}
}, []);
}, [isScrolledToElement]);
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI, there is another way to do this without using react state at all.

  • Give the element a unique ID e.g. xblock-id-abcde
  • Set the url hash to the above ID, i.e. "...some/url/page#xblock-id-abcde"
  • Use the ":target" pseudo-class to apply the glow style.

If the URL fragment matches an ID the browser should automatically scroll to it, and it applies the :target pseudo-class ref.

This means by using this mechanism you can avoid any code for scrolling, and applying a class. Also changing this value doesn't cause the page to refresh since it's client-side only.

The only disadvantage is that this is never passed to the server. What that means is that the server can't perform any action based on this value. Here since there is no server this is a moot point, but worth mentioning anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Awesome @xitij2000! Thank you for this.

Using targets here would be a better approach, but I think refactoring it (we already had some scrolling function feature) will put us out of schedule/scope.

But I think it is worth refactoring it next time we hit this feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Certainly, that makes sense, and keeping this part of the JavaScript code also opens up other possibilities. No need for a refactoring already.

@rpenido
Copy link
Contributor Author

rpenido commented Apr 29, 2024

Hi @xitij2000 ! Could you do another pass and merge if everything is fine?

@rpenido rpenido requested a review from xitij2000 April 29, 2024 13:05
@xitij2000 xitij2000 merged commit e24fb78 into openedx:master Apr 29, 2024
6 checks passed
@openedx-webhooks
Copy link

@rpenido 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future.

@xitij2000 xitij2000 deleted the rpenido/fal-3709-allow-redirect-to-the-unit-page-from-search-results branch April 29, 2024 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants