Skip to content

feat: show alternatives banner on unavailable book pages#12910

Open
Sadashii wants to merge 7 commits into
internetarchive:masterfrom
Sadashii:feat/12743/recommend-available-alternatives
Open

feat: show alternatives banner on unavailable book pages#12910
Sadashii wants to merge 7 commits into
internetarchive:masterfrom
Sadashii:feat/12743/recommend-available-alternatives

Conversation

@Sadashii

@Sadashii Sadashii commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

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, or locate physical states.

Technical

  • Extracted availability state resolution logic to a new @public function get_lending_state in lending.py.
  • Registered the helper as a template global in code.py.
  • Added <ol-banner> inside the EditionNavBar macro, wrapped within a responsive div using .desktop-only / .mobile-only CSS utility classes to avoid layout conflicts.
  • Simplified view.html layout by delegating the banner rendering to the navbar component, and removed the unused data-workid carousel attribute.
  • Refactored get_pending_action_banner in mybooks.py and updated AGENTS.md to follow i18n best practices (combining localized segments into single formatted strings with placeholders).
  • Implemented unit tests covering all lending states in test_lending.py.
  • Added data-lending-state attribute to #contentBody and visibility/tracking hooks in lazy-carousel.js to instrument discovery of recommended books.

Analytics & Experiment Tracking

Added tracking for the discovery of the recommended books carousel under the category OpenRelatedBooks to 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

  1. Run python unit tests:
    uv run --with-requirements requirements_test.txt pytest openlibrary/tests/core/test_lending.py
  2. Run template compilation tests:
    uv run --with-requirements requirements_test.txt pytest openlibrary/tests/test_templates.py
  3. Verify pre-commit checks run successfully:
    pre-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.js

Screenshot

  1. Added banner clicking on which smooth-scrolls the user down to the carousel section, banner will show above the navbar on both mobile and desktop - style changes to the banner will be made via feat(components): add ol-toast and ol-banner web components #12868
image image
  1. Moved the carousel section inside the right-side segment for better looks and behaviour
image
  1. (Partially related) Switched the patron intent banner to use ol-banner
image

Stakeholders

@mekarpeles

Copilot AI review requested due to automatic review settings June 12, 2026 09:50
@github-actions github-actions Bot added the Priority: 2 Important, as time permits. [managed] label Jun 12, 2026
…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.
@Sadashii Sadashii force-pushed the feat/12743/recommend-available-alternatives branch from 7fe996d to d74ca35 Compare June 12, 2026 09:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_state to resolve user-facing lending/availability state (with new tests) and expose it to templates.
  • Update edition templates/macros to pass lending state into EditionNavBar and 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.

Comment thread openlibrary/core/lending.py Outdated
Comment thread openlibrary/core/lending.py
Comment thread openlibrary/tests/core/test_lending.py Outdated
Comment thread static/css/components/work.css
Comment thread openlibrary/i18n/messages.pot
Comment thread static/css/page-book.css
@Sadashii Sadashii force-pushed the feat/12743/recommend-available-alternatives branch 2 times, most recently from c6c6a3f to d74ca35 Compare June 12, 2026 09:56
@Sadashii

Copy link
Copy Markdown
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.

@github-actions github-actions Bot added the Needs: Response Issues which require feedback from lead label Jun 13, 2026

@lokesh lokesh left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead Priority: 2 Important, as time permits. [managed]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Book Page: Recommend Available Alternatives

4 participants