openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Convert FullTextSuggestions partial to Jinja

Open RayBB opened this issue 2 months ago • 7 comments

This is a good first issue. Comment that you'd like to work on it — don't wait to be assigned — then open a PR referencing this issue. Anyone may open a PR, but please don't open one if another PR is already open for this issue.

Part of #13566. See the epic for the full pattern, playbook, and test steps.

Convert 3 files: openlibrary/macros/FulltextSearchSuggestion.html (34 lines), openlibrary/macros/FulltextSearchSuggestionItem.html (90 lines), openlibrary/macros/FulltextSuggestionSnippet.html (26 lines). Bridge (do not convert) LoadingIndicator (shared). Use the Jinja icon global where the old code calls macros.icon. Render from FullTextSuggestionsPartial. Keep the has_error return flag exact.

Test GET /partials/FulltextSearchSuggestion.json while logged in. Keep the parsed DOM identical. No new tests.

RayBB avatar Sep 06 '26 06:09 RayBB

Context

  • Target files confirmed present: openlibrary/macros/FulltextSearchSuggestion.html (34 lines), FulltextSearchSuggestionItem.html (90 lines), FulltextSuggestionSnippet.html (26 lines) — line counts match the epic breakdown exactly.
  • Handler lives in openlibrary/plugins/openlibrary/partials.py#L423-L439 (FullTextSuggestionsPartialResult, FullTextSuggestionsPartial.generate_async), routed from openlibrary/fastapi/partials.py#L108-L123 (GET /partials/FulltextSearchSuggestion.json). has_error is set from "error" in data — the flag to preserve exactly.
  • Directly reusable pattern: the just-merged #13563 (MyBooksDropperListsPartial) shows the shape to follow — a .jinja template rendered via get_jinja_env().get_template(...).render(...), with json_encode passed in as a render kwarg rather than added as a global. See dropper_lists.html.jinja and the handler at partials.py#L74-L94.
  • LoadingIndicator bridge target confirmed at openlibrary/macros/LoadingIndicator.html; the icon Jinja global is already registered (env.globals["icon"]) in openlibrary/core/jinja.py#L113.
  • FulltextSearchSuggestionItem.html branches on 4 shapes of doc (infogami_work, infogami_edition, solr_work, solr_edition) via a $code block mixing hasattr/.get() — this is the "2 data shapes need care in Jinja" case the epic playbook calls out. It also calls macros.BookByline, which is not part of this task's file list.
  • No open or closed PR yet references this file set, and no duplicate open issue exists for this task.

Issue Assessment

Action items

  • [x] Which macro handles the shared author-byline rendering, and is it in scope? (Answer: openlibrary/macros/BookByline.html, called from FulltextSearchSuggestionItem.html — it is not listed in this task's file set, so it should be bridged with render_templetor_template, the same treatment as LoadingIndicator.)
  • [x] Does a Jinja icon global already exist for the macros.icon calls? (Answer: yes, registered in openlibrary/core/jinja.py#L113, same helper used by prior conversions.)

Stakeholders

🔔 Stakeholders @cdrini — tagged per Theme: Search/frontend-performance ownership; this partial renders Search Inside suggestions on search result pages.

Full triage checklist
  • [x] Triage — correct labels applied or removed
  • [x] Problem / opportunity — problem is clear, audience identified, actionable
  • [x] Scope — issue is well-scoped; does not try to do too many things
  • [x] Justification — reasoning and impact stated; sufficient for leads to prioritize
  • [x] Success & testing criteria — defines what "done" looks like, verifiable by a contributor
  • [x] Proposal & breakdown — concrete plan present; checklist actionable for a contributor
  • [ ] If bug: environment & repro steps — n/a, not a bug report
  • [x] Risks, concerns, open questions — identified and surfaced
  • [x] Richy context — relevant code, commits, PRs reviewed; no duplicate found
  • [x] References — screenshots, designs, docs, and links present where needed

[!NOTE] This comment was automatically generated by Richy, Open Library's issue enrichment assistant, on behalf of @mekarpeles. This is NOT a sign-off. This issue needs lead review before work begins.

openlibrary-bot avatar Sep 06 '26 07:09 openlibrary-bot

Hi! I'd like to work on this issue. I can take the FullTextSuggestions partial migration to Jinja, preserve the existing DOM output, and verify the endpoint behavior as described. I'll open a PR referencing this issue

rishabhkumaryadav avatar Sep 06 '26 07:09 rishabhkumaryadav

If someone would like to work on this please be sure to take into account the feedback given here. Also please try to follow the practices closely that we have in other partials now.

https://github.com/internetarchive/openlibrary/pull/13575#pullrequestreview-5127812060

RayBB avatar Sep 12 '26 00:09 RayBB

Hi, I am going through the requirements and would like to work on this issue. Can you please assign this to me?

Yashhuc avatar Sep 12 '26 13:09 Yashhuc

Please read the issue. Especially the first line

RayBB avatar Sep 12 '26 17:09 RayBB

Hi @RayBB , I’d like to work on this issue.

My proposed approach is:

Review the conversion pattern and testing playbook documented in #13566. Convert FulltextSearchSuggestion.html, FulltextSearchSuggestionItem.html, and FulltextSuggestionSnippet.html from the existing template syntax to Jinja. Keep LoadingIndicator as an unconverted bridge and use the Jinja icon global where the existing templates call macros.icon. Preserve the exact has_error return behavior and continue rendering through FullTextSuggestionsPartial. Compare the parsed DOM before and after the migration using GET /partials/FulltextSearchSuggestion.json while logged in. Run the relevant formatting, linting, and existing test suites documented by the project.

I’ll keep the PR limited to the three files specified in this issue and avoid unrelated formatting or refactoring.

I noticed that #13575 is already open for this issue, so I won’t open a competing PR. If the current contributor is no longer working on it and you would like someone to take it over, I’d be happy to help address the requested changes. Otherwise, I’m also happy to pick up another unclaimed subtask from #13566 .

Srijan229 avatar Sep 12 '26 23:09 Srijan229

Give it a shot!

RayBB avatar Sep 12 '26 23:09 RayBB