feat: show alternatives banner on unavailable book pages#12910
Open
Sadashii wants to merge 7 commits into
Open
feat: show alternatives banner on unavailable book pages#12910Sadashii wants to merge 7 commits into
Sadashii wants to merge 7 commits into
Conversation
…hive#12743) Recommend alternative books via a warning banner when a book edition is unavailable (preview_only, checked out, waitlist, or locate physical states). To avoid code duplication and keep template markup clean, the availability state resolution is extracted to Python, and the responsive banner logic is encapsulated inside the EditionNavBar component. - Add `get_lending_state` helper to lending.py and register it as template global. - Update EditionNavBar.html to conditionally render the banner wrapped in responsive divs, avoiding display-override conflicts. - Delegate banner logic in view.html to EditionNavBar and clean up unused data-workid carousel attribute. - Refactor get_pending_action_banner in mybooks.py and update AGENTS.md to follow i18n best practices (unified strings with format placeholders). - Add unit tests for get_lending_state to test_lending.py.
7fe996d to
d74ca35
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR improves in-page navigation and availability messaging on edition pages by enabling smooth scrolling, adjusting anchor offsets, and surfacing lending-state-driven banners/sections.
Changes:
- Add
get_lending_stateto resolve user-facing lending/availability state (with new tests) and expose it to templates. - Update edition templates/macros to pass lending state into
EditionNavBarand reposition the Related Books carousel as a tab section target. - Improve scrolling UX (smooth scroll + updated
scroll-padding-top) and adjust carousel layout CSS; update pending-action banner rendering & i18n strings.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| static/css/page-book.css | Adjusts scroll padding offsets for anchor navigation across breakpoints. |
| static/css/components/work.css | Tweaks carousel container margin for related books layout. |
| static/css/base/common.css | Enables smooth scrolling with reduced-motion fallback. |
| openlibrary/core/lending.py | Adds get_lending_state helper for templates and other call sites. |
| openlibrary/tests/core/test_lending.py | Adds test coverage for get_lending_state. |
| openlibrary/plugins/openlibrary/code.py | Exposes get_lending_state as a template global. |
| openlibrary/templates/type/edition/view.html | Computes lending state once and wires it into EditionNavBar; relocates Related Books section. |
| openlibrary/macros/EditionNavBar.html | Adds conditional availability banner linking to related books. |
| openlibrary/templates/account/view.html | Switches pending-action banner to <ol-banner> output. |
| openlibrary/plugins/upstream/mybooks.py | Refactors translated pending-action message to use placeholders around an HTML link. |
| openlibrary/i18n/messages.pot | Updates extracted strings and source references for i18n. |
| AGENTS.md | Documents i18n guidance for link placeholders inside a single translatable string. |
c6c6a3f to
d74ca35
Compare
for more information, see https://pre-commit.ci
…get_lending_state
…end-available-alternatives
…com:Sadashii/openlibrary into feat/12743/recommend-available-alternatives
Collaborator
Author
|
Note to self, a follow up PR on ol banner has to be merged first with some additions to be made here, do not merge this before that. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #12743
This PR adds a warning banner recommending available alternative books on the Book Edition page when a book is in
preview_only,checkedout,waitlist, orlocatephysical states.Technical
@publicfunctionget_lending_stateinlending.py.code.py.<ol-banner>inside theEditionNavBarmacro, wrapped within a responsivedivusing.desktop-only/.mobile-onlyCSS utility classes to avoid layout conflicts.view.htmllayout by delegating the banner rendering to the navbar component, and removed the unuseddata-workidcarousel attribute.get_pending_action_bannerinmybooks.pyand updatedAGENTS.mdto follow i18n best practices (combining localized segments into single formatted strings with placeholders).test_lending.py.data-lending-stateattribute to#contentBodyand visibility/tracking hooks inlazy-carousel.jsto instrument discovery of recommended books.Analytics & Experiment Tracking
Added tracking for the discovery of the recommended books carousel under the category
OpenRelatedBooksto compare natural discovery vs banner-driven discovery:OpenRelatedBooks|BannerClick: Tracked when a user clicks the link on the warning banner to jump to the recommendations.OpenRelatedBooks|FromBanner: Tracked when the related books carousel lazy-loads/is discovered after the user clicked the banner link (URL hash is#related-work-carousel).OpenRelatedBooks|ScrolledDownAvailable: Tracked when the related books carousel lazy-loads/is discovered by scrolling down normally when the book is available.OpenRelatedBooks|ScrolledDownUnavailable: Tracked when the related books carousel lazy-loads/is discovered by scrolling down normally when the book is unavailable (in one of the 4 warning states).Testing
uv run --with-requirements requirements_test.txt pytest openlibrary/tests/core/test_lending.pyuv run --with-requirements requirements_test.txt pytest openlibrary/tests/test_templates.pypre-commit run --files openlibrary/core/lending.py openlibrary/plugins/openlibrary/code.py openlibrary/templates/type/edition/view.html openlibrary/tests/core/test_lending.py openlibrary/macros/EditionNavBar.html openlibrary/plugins/openlibrary/js/lazy-carousel.jsScreenshot
Stakeholders
@mekarpeles