Repository navigation
Feat: add filter in chat and search page - #16707
Conversation
📝 WalkthroughWalkthroughOwner-based filtering is added to chat and search lists. Both ChangesOwner filtering for chats and searches
Estimated code review effort: 2 (Simple) | ~12 minutes Sequence Diagram(s)sequenceDiagram
participant ChatList
participant useFetchChatList
participant useHandleFilterSubmit
participant chatService
ChatList->>useFetchChatList: request chats
useFetchChatList->>useHandleFilterSubmit: get filterValue, handleFilterSubmit
useFetchChatList->>chatService: listChats(owner_ids, keywords, pagination)
chatService-->>useFetchChatList: chats data
useFetchChatList-->>ChatList: chats, filterValue, handleFilterSubmit
ChatList->>ChatList: buildOwnersFilter(chats)
ChatList->>ChatList: render ListFilterBar(filters=owners, value=filterValue, onChange=handleFilterSubmit)
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
web/src/hooks/use-chat-request.ts (1)
76-83: 📐 Maintainability & Code Quality | 🟠 Major | ⚡ Quick winRaw
queryKeyarray violates query key factory guideline.The
queryKeyis written as an inline array literal rather than via a query key factory returning anas consttuple.As per coding guidelines, "Never write raw `queryKey` arrays inline; use a query key factory object that returns `as const` tuples for every `useQuery` and `invalidateQueries` call."♻️ Suggested direction
+export const chatListQueryKeys = { + list: (params: { debouncedSearchString: string; filterValue: FilterValue } & Pagination) => + [ChatApiAction.FetchChatList, params] as const, +}; ... - queryKey: [ - ChatApiAction.FetchChatList, - { - debouncedSearchString, - filterValue, - ...pagination, - }, - ], + queryKey: chatListQueryKeys.list({ debouncedSearchString, filterValue, ...pagination }),🤖 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/hooks/use-chat-request.ts` around lines 76 - 83, The `useQuery` call in `use-chat-request` is using an inline raw `queryKey` array instead of the required query key factory pattern. Replace the literal array with a dedicated factory entry for `ChatApiAction.FetchChatList` that returns an `as const` tuple, and then use that factory result here (and keep the same shape for any related `invalidateQueries` usage) so the key is consistent and typed.Source: Coding guidelines
web/src/pages/next-searches/hooks.ts (1)
59-67: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winAlign
owner_idswith the request payload.filterValue.owneris astring[]here, and the serializer sends repeatedowner_idskeys, soSearchListParams.owner_idsshould bestring[]to avoid the type drifting from actual usage.🤖 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/next-searches/hooks.ts` around lines 59 - 67, The SearchListParams owner_ids type is out of sync with how the request is actually built, since filterValue.owner is a string[] and the serializer emits repeated owner_ids entries. Update SearchListParams in hooks.ts so owner_ids is typed as string[] and make sure any code using this interface matches the array-based request payload, especially where the search list params are assembled.
🧹 Nitpick comments (1)
web/src/pages/next-chats/index.tsx (1)
31-33: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueMemoize
ownersto avoid recomputation/new reference every render.
buildOwnersFilterand the wrapping array are recreated on every render, producing a new array reference passed toListFilterBar/FilterPopovereven whendata.chatshasn't changed content-wise.♻️ Suggested fix
- const owners = [ - buildOwnersFilter(data?.chats ?? [], undefined, tc('owner')), - ]; + const owners = useMemo( + () => [buildOwnersFilter(data?.chats ?? [], undefined, tc('owner'))], + [data?.chats, tc], + );🤖 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/next-chats/index.tsx` around lines 31 - 33, The owners filter is being rebuilt on every render in the next-chats page, creating a new array reference even when the chats data has not changed. Memoize the owners value in the index component using the existing data dependency so `buildOwnersFilter` and the wrapping array are only recomputed when `data.chats` or `tc('owner')` changes, keeping the reference stable for `ListFilterBar` and `FilterPopover`.
🤖 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/next-chats/index.tsx`:
- Around line 31-33: The owner filter options are being built from the already
filtered chat list, so the dropdown only shows the currently selected owner
after filtering. Update the `owners` computation in `index.tsx` to source data
from an unfiltered chat list instead of `data.chats`, while keeping
`buildOwnersFilter` as the helper used to derive the options.
In `@web/src/pages/next-searches/index.tsx`:
- Around line 29-34: The inline owners array passed to ListFilterBar is
recreated on every render, which causes FilterPopover to treat filters as
changed and reset its form. Memoize the owners value in next-searches index
using the existing list data and tc/buildOwnersFilter inputs so the reference
stays stable across pagination/search/refetch renders. Keep the change localized
around the owners definition before it is passed into ListFilterBar.
---
Outside diff comments:
In `@web/src/hooks/use-chat-request.ts`:
- Around line 76-83: The `useQuery` call in `use-chat-request` is using an
inline raw `queryKey` array instead of the required query key factory pattern.
Replace the literal array with a dedicated factory entry for
`ChatApiAction.FetchChatList` that returns an `as const` tuple, and then use
that factory result here (and keep the same shape for any related
`invalidateQueries` usage) so the key is consistent and typed.
In `@web/src/pages/next-searches/hooks.ts`:
- Around line 59-67: The SearchListParams owner_ids type is out of sync with how
the request is actually built, since filterValue.owner is a string[] and the
serializer emits repeated owner_ids entries. Update SearchListParams in hooks.ts
so owner_ids is typed as string[] and make sure any code using this interface
matches the array-based request payload, especially where the search list params
are assembled.
---
Nitpick comments:
In `@web/src/pages/next-chats/index.tsx`:
- Around line 31-33: The owners filter is being rebuilt on every render in the
next-chats page, creating a new array reference even when the chats data has not
changed. Memoize the owners value in the index component using the existing data
dependency so `buildOwnersFilter` and the wrapping array are only recomputed
when `data.chats` or `tc('owner')` changes, keeping the reference stable for
`ListFilterBar` and `FilterPopover`.
🪄 Autofix (Beta)
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
Run ID: 04496376-27f3-4b8b-aed9-c0f6948ef3bb
📒 Files selected for processing (4)
web/src/hooks/use-chat-request.tsweb/src/pages/next-chats/index.tsxweb/src/pages/next-searches/hooks.tsweb/src/pages/next-searches/index.tsx
| const owners = [ | ||
| buildOwnersFilter(data?.chats ?? [], undefined, tc('owner')), | ||
| ]; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== file list ==\n'
git ls-files 'web/src/pages/next-chats/index.tsx' 'web/src/hooks/use-chat-request.ts' 'web/src/**/buildOwnersFilter*' 'web/src/**/owners*filter*' || true
printf '\n== outline next-chats index ==\n'
ast-grep outline web/src/pages/next-chats/index.tsx --view expanded || true
printf '\n== outline use-chat-request ==\n'
ast-grep outline web/src/hooks/use-chat-request.ts --view expanded || true
printf '\n== search buildOwnersFilter usages ==\n'
rg -n "buildOwnersFilter|owner_ids: filterValue\.owner|owner filter|owners filter" web/src -S || trueRepository: infiniflow/ragflow
Length of output: 3251
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== next-chats index slice ==\n'
sed -n '1,120p' web/src/pages/next-chats/index.tsx | cat -n
printf '\n== use-chat-request slice ==\n'
sed -n '65,115p' web/src/hooks/use-chat-request.ts | cat -n
printf '\n== list-filter-util slice ==\n'
sed -n '1,120p' web/src/utils/list-filter-util.ts | cat -n
printf '\n== related next-searches slice for comparison ==\n'
sed -n '1,80p' web/src/pages/next-searches/index.tsx | cat -nRepository: infiniflow/ragflow
Length of output: 11162
Build owner filter options from an unfiltered source
owners is derived from data.chats, but useFetchChatList already filters that response with owner_ids: filterValue.owner. After selecting an owner, the dropdown will only include that owner, so switching to a different owner requires clearing the filter first. Pull the owner options from an unfiltered source instead.
🤖 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/next-chats/index.tsx` around lines 31 - 33, The owner filter
options are being built from the already filtered chat list, so the dropdown
only shows the currently selected owner after filtering. Update the `owners`
computation in `index.tsx` to source data from an unfiltered chat list instead
of `data.chats`, while keeping `buildOwnersFilter` as the helper used to derive
the options.
| filterValue, | ||
| handleFilterSubmit, | ||
| } = useFetchSearchList(); | ||
|
|
||
| const owners = [ | ||
| buildOwnersFilter(list?.data?.search_apps ?? [], undefined, tc('owner')), | ||
| ]; |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== index.tsx outline ==\n'
ast-grep outline web/src/pages/next-searches/index.tsx --view expanded || true
printf '\n== list filter related files ==\n'
fd -a "ListFilterBar.*" web/src || true
fd -a "FilterPopover.*" web/src || true
fd -a "CheckboxFormMultiple.*" web/src || true
fd -a "useFetchSearchList.*" web/src || trueRepository: infiniflow/ragflow
Length of output: 295
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== locate relevant files ==\n'
fd -a "ListFilterBar.*" web/src || true
fd -a "FilterPopover.*" web/src || true
fd -a "CheckboxFormMultiple.*" web/src || true
fd -a "next-searches" web/src/pages || true
printf '\n== outline next-searches index ==\n'
ast-grep outline web/src/pages/next-searches/index.tsx --view expanded || trueRepository: infiniflow/ragflow
Length of output: 349
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== search component symbols ==\n'
rg -n "ListFilterBar|FilterPopover|CheckboxFormMultiple|useFetchSearchList|buildOwnersFilter" web/src || true
printf '\n== search page source ==\n'
cat -n web/src/pages/next-searches/index.tsx | sed -n '1,220p'Repository: infiniflow/ragflow
Length of output: 12183
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== list-filter-bar outline ==\n'
ast-grep outline web/src/components/list-filter-bar/index.tsx --view expanded || true
printf '\n== filter-popover outline ==\n'
ast-grep outline web/src/components/list-filter-bar/filter-popover.tsx --view expanded || true
printf '\n== list-filter-bar source ==\n'
cat -n web/src/components/list-filter-bar/index.tsx | sed -n '1,260p'
printf '\n== filter-popover source (1/2) ==\n'
cat -n web/src/components/list-filter-bar/filter-popover.tsx | sed -n '1,240p'
printf '\n== filter-popover source (2/2) ==\n'
cat -n web/src/components/list-filter-bar/filter-popover.tsx | sed -n '241,420p'Repository: infiniflow/ragflow
Length of output: 18196
🏁 Script executed:
#!/bin/bash
set -euo pipefail
printf '\n== buildOwnersFilter ==\n'
cat -n web/src/utils/list-filter-util.ts | sed -n '1,180p'
printf '\n== useFetchSearchList ==\n'
cat -n web/src/pages/next-searches/hooks.ts | sed -n '1,180p'
printf '\n== any memoization in next-searches page ==\n'
rg -n "useMemo\\(|owners|filters=" web/src/pages/next-searches web/src/pages/next-chats web/src/pages/datasets/use-select-owners.ts web/src/pages/agents/hooks/use-select-filters.ts || trueRepository: infiniflow/ragflow
Length of output: 8861
Memoize owners before passing it to ListFilterBar
FilterPopover resets its form whenever filters changes, and this inline array creates a new reference on every render. That can clear unsaved selections while the popover is open during pagination/search/refetch updates. web/src/pages/next-searches/index.tsx:32-34
🤖 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/next-searches/index.tsx` around lines 29 - 34, The inline
owners array passed to ListFilterBar is recreated on every render, which causes
FilterPopover to treat filters as changed and reset its form. Memoize the owners
value in next-searches index using the existing list data and
tc/buildOwnersFilter inputs so the reference stays stable across
pagination/search/refetch renders. Keep the change localized around the owners
definition before it is passed into ListFilterBar.
Summary
Feat: add filter in chat and search page