active search - #37
Conversation
- Move empty state HTML for the contact table to a reusable fragment. - Implement HTMX for dynamic search updates on keyup with delay. - Update `ContactController` to return HTML fragment for HTMX requests. - Improve empty state design consistency across templates.
📝 WalkthroughWalkthroughImplemented live search functionality using HTMX. Modified ContactController to detect HTMX search requests via trigger ID and conditionally return either a partial template fragment or full page. Updated templates to support debounced live search with HTMX attributes and simplified empty state handling across views. Changes
Sequence DiagramsequenceDiagram
actor User
participant Browser
participant Controller
participant Service
participant Template
User->>Browser: Types in search input
Browser->>Browser: Debounce trigger (200ms delay)<br/>after keyup + changed
Browser->>Controller: HTMX GET /contacts<br/>(hx-trigger: "nav-search")
Controller->>Service: contactService.list(q, pageable)
Service-->>Controller: Page<Contact>
Controller->>Template: Render fragment<br/>(contacts, search vars)
Template->>Template: Check if contacts.isEmpty()
alt Contacts Found
Template-->>Browser: HTML rows (th:each loop)
else No Contacts Found
Template-->>Browser: Empty state row
end
Browser->>Browser: HTMX swaps tbody content
Browser->>User: Updated results displayed
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/resources/templates/contacts/index.html (1)
31-32: Pagination text may display confusingly for empty results.When
contactPage.contentis empty, the pagination text will render as "1–0 of 0", which could confuse users. Consider hiding or adjusting the pagination controls when there are no results.💡 Potential fix to hide pagination when empty
- <div class="flex items-center gap-1"> + <div class="flex items-center gap-1" th:if="${!contactPage.content.isEmpty()}"> <span class="px-1 text-xs text-base-content/50" th:text="${contactPage.number * contactPage.size + 1} + '–' + ${contactPage.isLast() ? contactPage.totalElements : (contactPage.number + 1) * contactPage.size} + ' of ' + ${`#numbers.formatInteger`(contactPage.totalElements, 0, 'COMMA')}"></span>🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/resources/templates/contacts/index.html` around lines 31 - 32, The pagination line using contactPage currently renders "1–0 of 0" for empty results; wrap or replace the span that computes the range (the element with th:text using contactPage.number, contactPage.size, contactPage.isLast(), and contactPage.totalElements) with a Thymeleaf conditional so it is only shown when contactPage.content is not empty (e.g., th:if="${not contactPage.content.isEmpty()}" or th:if="${contactPage.totalElements > 0}"), or alternatively render a clearer message like "0 of 0" when contactPage.totalElements == 0 by using a ternary expression on contactPage.totalElements to avoid displaying "1–0".
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/main/resources/templates/contacts/index.html`:
- Around line 31-32: The pagination line using contactPage currently renders
"1–0 of 0" for empty results; wrap or replace the span that computes the range
(the element with th:text using contactPage.number, contactPage.size,
contactPage.isLast(), and contactPage.totalElements) with a Thymeleaf
conditional so it is only shown when contactPage.content is not empty (e.g.,
th:if="${not contactPage.content.isEmpty()}" or
th:if="${contactPage.totalElements > 0}"), or alternatively render a clearer
message like "0 of 0" when contactPage.totalElements == 0 by using a ternary
expression on contactPage.totalElements to avoid displaying "1–0".
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 6af92ec4-17e0-4916-a65f-a57539b9bbe6
📒 Files selected for processing (4)
src/main/java/codes/yam/contacts/ContactController.javasrc/main/resources/templates/contacts/index.htmlsrc/main/resources/templates/fragments/contact-list-rows.htmlsrc/main/resources/templates/layout.html
ContactControllerto return HTML fragment for HTMX requests.Closes #34
Summary by CodeRabbit