Skip to content

added find-in-message search to the message details viewer - #4572

Open
viktor-tanov wants to merge 1 commit into
provectus:masterfrom
viktor-tanov:feature/find_in_message
Open

added find-in-message search to the message details viewer#4572
viktor-tanov wants to merge 1 commit into
provectus:masterfrom
viktor-tanov:feature/find_in_message

Conversation

@viktor-tanov

@viktor-tanov viktor-tanov commented Aug 6, 2026

Copy link
Copy Markdown

Expanded message rows render their key, value and headers in a read-only Ace viewer with no way to search the document. Ctrl-F/Command-F fell through to the browser's find, which cannot see the rows Ace virtualises out of the DOM, so large payloads were effectively unsearchable.

Ace's built-in find command is replaced with one that opens an in-panel find bar, backed by a useEditorSearch hook that drives Ace's own search API. Matches are counted and highlighted, Enter/Shift+Enter step through them and Esc closes the bar. Scans are debounced and require two characters, since a single character matches nearly everywhere in a multi-megabyte message. Switching tabs resets the search, because each tab is a different document.

EditorViewer gains an optional onLoad passthrough so callers can reach the underlying Ace instance; it is not invoked for the plain-text fallback, and the panel handler leaves the browser's find in place in that case.

  • Breaking change? (if so, please describe the impact and migration path for existing application instances)

What changes did you make? (Give an overview)

Is there anything you'd like reviewers to focus on?

How Has This Been Tested? (put an "x" (case-sensitive!) next to an item)

  • No need to
  • Manually (please, describe, if necessary)
  • Unit checks
  • Integration checks
  • Covered by existing automation

Checklist (put an "x" (case-sensitive!) next to all the items, otherwise the build will fail)

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (e.g. ENVIRONMENT VARIABLES)
  • My changes generate no new warnings (e.g. Sonar is happy)
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

Check out Contributing and Code of Conduct

Summary by CodeRabbit

  • New Features

    • Added search to expanded message content with Ctrl/Cmd+F support.
    • Search results are highlighted with match counts and current-match navigation.
    • Added next, previous, and close controls, plus keyboard shortcuts.
    • Search styling adapts to light and dark themes.
  • Bug Fixes

    • Restored focus to the message panel when closing search.
    • Search resets when switching message tabs.
Expanded message rows render their key, value and headers in a read-only
Ace viewer with no way to search the document. Ctrl-F/Command-F fell
through to the browser's find, which cannot see the rows Ace virtualises
out of the DOM, so large payloads were effectively unsearchable.

Ace's built-in find command is replaced with one that opens an in-panel
find bar, backed by a useEditorSearch hook that drives Ace's own search
API. Matches are counted and highlighted, Enter/Shift+Enter step through
them and Esc closes the bar. Scans are debounced and require two
characters, since a single character matches nearly everywhere in a
multi-megabyte message. Switching tabs resets the search, because each
tab is a different document.

EditorViewer gains an optional onLoad passthrough so callers can reach
the underlying Ace instance; it is not invoked for the plain-text
fallback, and the panel handler leaves the browser's find in place in
that case.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@viktor-tanov
viktor-tanov requested a review from a team as a code owner August 6, 2026 22:18
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Message content now supports Ace-backed search with debounced matching, navigation, keyboard shortcuts, focus restoration, themed highlights, and a conditional find bar. EditorViewer exposes the loaded Ace instance. Tests cover the hook, controls, and integration behavior.

Changes

Message content search

Layer / File(s) Summary
Ace search hook
kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/useEditorSearch.ts, kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/__tests__/useEditorSearch.spec.ts
Adds debounced Ace searching, match highlighting, cyclic navigation, reset behavior, and unmount cleanup.
Message content integration
kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageContent.tsx, kafka-ui-react-app/src/components/common/EditorViewer/EditorViewer.tsx, kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageContent.styled.ts, kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/__tests__/MessageContent.spec.tsx
Connects the search hook to the message panel and Ace editor. Adds Ctrl-F/Command-F, Escape handling, tab reset, focus restoration, and toolbar layout.
Search controls and theme rendering
kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageSearch.tsx, kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageSearch.styled.ts, kafka-ui-react-app/src/theme/theme.ts, kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/__tests__/MessageSearch.spec.tsx
Adds the find bar with term input, result status, navigation, close actions, SVG icons, and light/dark theme colors.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant MessageContent
  participant MessageSearch
  participant EditorViewer
  participant useEditorSearch
  participant AceEditor
  User->>MessageContent: Press Ctrl-F or Command-F
  MessageContent->>MessageSearch: Open find bar
  MessageSearch->>MessageContent: Submit search term
  MessageContent->>EditorViewer: Register Ace search command
  EditorViewer-->>MessageContent: Provide Ace editor instance
  MessageContent->>useEditorSearch: Update search term
  useEditorSearch->>AceEditor: Search and highlight matches
  AceEditor-->>useEditorSearch: Return match ranges
  useEditorSearch-->>MessageSearch: Display match status
Loading

Suggested reviewers: cdiazmu

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding find-in-message search to the message details viewer.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/useEditorSearch.ts (2)

127-140: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Flush a pending scan before stepping.

matchCount stays 0 until the debounce elapses. If the user presses Enter within 300 ms of the last keystroke, step returns early and the keystroke does nothing. Flush the pending scan first so the first Enter navigates.

♻️ Proposed refactor
   const step = React.useCallback(
     (direction: 1 | -1) => {
-      if (!editor || matchCount === 0) return;
+      if (!editor) return;
+      // Enter can arrive inside the debounce window; run the scan now so the
+      // keystroke is not swallowed.
+      runSearch.flush();
+      if (matchCount === 0) return;
       if (direction === 1) {

matchCount is still read from the previous render in the same tick, so a follow-up state read is required for the very first Enter. An alternative is to keep the flush in MessageSearch's Enter handler.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/useEditorSearch.ts`
around lines 127 - 140, Update the step callback to flush any pending debounced
search scan before checking matchCount or navigating, ensuring the first Enter
within the debounce window is handled. Because the flushed scan may not update
matchCount until a later render, add the necessary follow-up state handling or
move the flush into MessageSearch’s Enter handler while preserving next/previous
navigation and current-match updates.

45-54: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Pass a shallow clone of FIND_OPTIONS into editor.find.

Ace 1.7.1 writes options.needle and may write options.start onto the object passed to Editor.find, while the module-level constant is shared across viewer instances. A shallow clone at the call site keeps the shared options constant unchanged between searches.

♻️ Proposed refactor
-    const found = editor.find(needle, FIND_OPTIONS);
+    const found = editor.find(needle, { ...FIND_OPTIONS });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/useEditorSearch.ts`
around lines 45 - 54, Update the `editor.find` call in `useEditorSearch` to pass
a shallow clone of `FIND_OPTIONS` rather than the shared constant directly,
allowing Ace to add `needle` or `start` without mutating module-level search
options.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/useEditorSearch.ts`:
- Around line 127-140: Update the step callback to flush any pending debounced
search scan before checking matchCount or navigating, ensuring the first Enter
within the debounce window is handled. Because the flushed scan may not update
matchCount until a later render, add the necessary follow-up state handling or
move the flush into MessageSearch’s Enter handler while preserving next/previous
navigation and current-match updates.
- Around line 45-54: Update the `editor.find` call in `useEditorSearch` to pass
a shallow clone of `FIND_OPTIONS` rather than the shared constant directly,
allowing Ace to add `needle` or `start` without mutating module-level search
options.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: b4e42671-5b28-474c-bbdc-d8360442c687

📥 Commits

Reviewing files that changed from the base of the PR and between 83b5a60 and 94855b4.

📒 Files selected for processing (10)
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageContent.styled.ts
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageContent.tsx
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageSearch.styled.ts
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageSearch.tsx
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/__tests__/MessageContent.spec.tsx
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/__tests__/MessageSearch.spec.tsx
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/__tests__/useEditorSearch.spec.ts
  • kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/useEditorSearch.ts
  • kafka-ui-react-app/src/components/common/EditorViewer/EditorViewer.tsx
  • kafka-ui-react-app/src/theme/theme.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant