fix(ui): search agentflows across all pages#6133
fix(ui): search agentflows across all pages#6133haimingZZ wants to merge 2 commits intoFlowiseAI:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new search functionality for agentflows. The backend getAllChatflows service now accepts a search parameter and filters chatflows by name, category, or ID. The frontend Agentflows component has been updated to include a search input with a debounce mechanism, and client-side filtering has been removed in favor of server-side filtering. Feedback includes a potential PostgreSQL runtime error when searching by id due to uuid type incompatibility with LIKE and LOWER, suggesting an explicit cast to TEXT. Additionally, there's a concern about a stale closure in the useEffect debounce logic, where agentflowVersion might not be current if the version is changed during the debounce period.
| new Brackets((qb) => { | ||
| qb.where('LOWER(chat_flow.name) LIKE :search', { search: searchTerm }) | ||
| .orWhere("LOWER(COALESCE(chat_flow.category, '')) LIKE :search", { search: searchTerm }) | ||
| .orWhere('LOWER(chat_flow.id) LIKE :search', { search: searchTerm }) |
There was a problem hiding this comment.
Searching on the id field using LIKE will cause a runtime error when using a PostgreSQL database. In PostgreSQL, the id column is of type uuid, and the LIKE operator (as well as the LOWER function) is not compatible with the uuid type without an explicit cast to text.
To support cross-database compatibility (SQLite, MySQL, and PostgreSQL), you should cast the ID to a string before applying the search filter.
| .orWhere('LOWER(chat_flow.id) LIKE :search', { search: searchTerm }) | |
| .orWhere('CAST(chat_flow.id AS TEXT) LIKE :search', { search: searchTerm }) |
| const timeoutId = setTimeout(() => { | ||
| setSearchQuery(normalizedSearch) | ||
| setCurrentPage(1) | ||
| refresh(1, pageLimit, agentflowVersion, normalizedSearch) | ||
| }, 300) |
There was a problem hiding this comment.
The refresh call inside this setTimeout closure captures the value of agentflowVersion from the render cycle when the effect was triggered. If a user types a search term and then quickly switches the Agentflow version (V1/V2) before the 300ms debounce period ends, the search request will be sent for the old version instead of the currently selected one.
To fix this, you should include agentflowVersion in the useEffect dependency array so the debounce is reset and uses the latest version, or use a React Ref to track the current version without triggering re-effects.
References
- While repository rules allow omitting dependencies for initial content loading to avoid infinite loops, dynamic interactions like search debouncing must include all relevant dependencies to avoid stale closures and ensure data consistency.
|
Follow-up update: I addressed both review points in the latest commit.
Commit: |
Summary
Testing
pnpm install --frozen-lockfilerunCloses #5868