Repository navigation
Feat: Search for timeline nodes. - #17996
Conversation
📝 WalkthroughWalkthroughSearch state now lives in ChangesRepresentation search and rendering
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant ExpandableSearchInput
participant Representation
participant useGraphEntitySearch
participant DocumentGraphFetch
ExpandableSearchInput->>Representation: change search keyword
Representation->>useGraphEntitySearch: handleSearchKeywordChange
useGraphEntitySearch->>DocumentGraphFetch: fetch with debounced keyword
DocumentGraphFetch-->>useGraphEntitySearch: return graph results
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts`:
- Around line 17-23: Update the keyword selection around useDebounce and
useFetchDocumentStructureGraph to use raw searchKeyword for choosing the active
source, so clearing free-text immediately falls back to graphKeywords instead of
the stale debounced value. When searchKeyword becomes non-empty, clear
graphKeywords, and revise the nearby keyword-source comment to describe these
transitions accurately.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 822c1625-8650-474b-9ec5-fa61daca25e3
📒 Files selected for processing (6)
web/src/components/structure-graph/adapters.tsweb/src/components/structure-graph/representation-renderer.tsxweb/src/pages/chunk/representation/hooks/use-graph-entity-search.tsweb/src/pages/chunk/representation/hooks/use-selected-template.tsweb/src/pages/chunk/representation/index.tsxweb/src/pages/dataset/compilation/utils/skill-tree.ts
💤 Files with no reviewable changes (1)
- web/src/components/structure-graph/adapters.ts
| // Non-graph kinds search server-side with the same ?keywords= query the | ||
| // graph-kind Enter search uses; the two inputs never show at once, and the | ||
| // handlers below keep at most one of the two keyword sources non-empty. | ||
| const debouncedSearchKeyword = useDebounce(searchKeyword, { wait: 500 }); | ||
| const { data, loading } = useFetchDocumentStructureGraph( | ||
| debouncedSearchKeyword || graphKeywords, | ||
| ); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🌐 Web query:
Confirm the return-value timing of [email protected] useDebounce(value, { wait: 500 }) when value changes from a non-empty string to an empty string.
💡 Result:
In [email protected], when the input value of useDebounce(value, { wait: 500 }) changes from a non-empty string to an empty string, the returned value will update to the empty string exactly 500 milliseconds after the change occurred [1][2]. This behavior occurs because useDebounce leverages useDebounceFn internally [1][2]. When the input value changes, the useEffect hook triggers the debounced function (run), which is configured with a 500ms delay [1][2]. The state holding the returned debounced value is only updated inside the debounced callback, meaning it waits for the specified wait period to elapse without further changes to the value before finalizing the update [1][3]. If the input remains an empty string for the duration of the wait, the update will execute at the end of that 500ms interval [4][3].
Citations:
- 1: https://github.com/alibaba/hooks/blob/master/packages/hooks/src/useDebounce/index.ts
- 2: https://segmentfault.com/a/1190000042869140
- 3: https://juejin.cn/post/7157709622596337695
- 4: https://www.bytezonex.com/archives/Ncc0RBOE.html
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== file outline"
ast-grep outline web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts || true
echo "=== relevant source"
cat -n web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts | sed -n '1,150p'
echo "=== package ahooks version"
if [ -f web/package.json ]; then
node -e 'const p=require("./web/package.json"); console.log(p.dependencies?.ahooks ?? p.devDependencies?.ahooks ?? "not found in web/package.json")'
fi
if [ -f package.json ]; then
node -e 'const p=require("./package.json"); console.log(p.dependencies?.ahooks ?? p.devDependencies?.ahooks ?? "not found in package.json")'
fi
echo "=== useFetchDocumentStructureGraph usages"
rg -n "useFetchDocumentStructureGraph|keepPreviousData" web/src -S | head -n 120Repository: infiniflow/ragflow
Length of output: 6461
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "=== use-document-request relevant function"
cat -n web/src/hooks/use-document-request.ts | sed -n '730,776p'
echo "=== component consumers using returned searchKeyword / graphSelectValue"
rg -n "searchKeyword|graphSelectValue|handleSearchKeywordChange|handleNoMatchEnter|handleSelectEntity|handleTemplateChange|handleNodeClick" web/src/pages/chunk/representation -SRepository: infiniflow/ragflow
Length of output: 4734
Switch the active keyword source when free-text search is cleared.
useDebounce(searchKeyword, { wait: 500 }) keeps the previous non-empty term for up to 500 ms. If that source is cleared at lines 60, 81, or 106 while graphKeywords is set, debouncedSearchKeyword || graphKeywords still sends the stale free-text term and preserves the prior cached result via keepPreviousData. Select the active source from raw searchKeyword; clear graphKeywords when searchKeyword starts non-empty; and update the keyword-source comment at lines 17-19 to match the actual state transitions.
🤖 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 `@web/src/pages/chunk/representation/hooks/use-graph-entity-search.ts` around
lines 17 - 23, Update the keyword selection around useDebounce and
useFetchDocumentStructureGraph to use raw searchKeyword for choosing the active
source, so clearing free-text immediately falls back to graphKeywords instead of
the stale debounced value. When searchKeyword becomes non-empty, clear
graphKeywords, and revise the nearby keyword-source comment to describe these
transitions accurately.
Source: Coding guidelines
wangq8
left a comment
There was a problem hiding this comment.
Good refactor — moving tree search from client-side to server-side is the right approach for scalability. Architecture review:
What works well:
- Removing the client-side
filterTreeDataByKeywordand relying onuseFetchDocumentStructureGraphwith keyword parameters unifies the search path. Clean separation. - The 500ms debounce via
useDebounceprevents hammering the API during fast typing. - The
useSelectedTemplatefallback fix (checking ifselectedTemplateIdis still in the current templates array before using it, falling back totemplates[0]) is important — without it, search results that don't include the previously selected template would render a blank representation. - Moving
searchKeywordstate and its handler intouseGraphEntitySearchkeeps the hook as the single source of truth for all search-related state. Good cohesion. - Mutual exclusivity between
graphKeywords(entity dropdown) andsearchKeyword(ExpandableSearchInput) is handled properly through the callbacks — at most one is non-empty at a time.
Minor observations (non-blocking):
- In
use-graph-entity-search.ts,handleSearchKeywordChangeonly setssearchKeywordbut doesn't explicitly cleargraphKeywords. The safety relies on callers (the dropdown handlers) clearingsearchKeyword. This is fine for the current UX where the two inputs never show simultaneously, but a future refactor that adds both inputs at once could hit a subtle conflict. Consider adding a comment noting this assumption, or clearinggraphKeywordsinhandleSearchKeywordChangefor defense-in-depth. - The comment cleanup in
skill-tree.tsis a nice touch — stale references to deleted code are worse than removed code.
LGTM overall. 👍
Summary
Feat: Search for timeline nodes.