-
-
Notifications
You must be signed in to change notification settings - Fork 24k
fix: implement server-side search for chatflows and agentflows #5963
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useEffect, useState } from 'react' | ||
| import { useEffect, useState, useCallback, useRef } from 'react' | ||
| import { useNavigate } from 'react-router-dom' | ||
| import { useSelector } from 'react-redux' | ||
|
|
||
|
|
@@ -28,6 +28,9 @@ import useApi from '@/hooks/useApi' | |
| import { baseURL, AGENTFLOW_ICONS } from '@/store/constant' | ||
| import { useError } from '@/store/context/ErrorContext' | ||
|
|
||
| // utils | ||
| import { debounce } from 'lodash' | ||
|
|
||
| // icons | ||
| import { IconPlus, IconLayoutGrid, IconList, IconX, IconAlertTriangle } from '@tabler/icons-react' | ||
|
|
||
|
|
@@ -54,17 +57,22 @@ const Agentflows = () => { | |
| const [pageLimit, setPageLimit] = useState(DEFAULT_ITEMS_PER_PAGE) | ||
| const [total, setTotal] = useState(0) | ||
|
|
||
| const searchRef = useRef('') | ||
|
|
||
| const onChange = (page, pageLimit) => { | ||
| setCurrentPage(page) | ||
| setPageLimit(pageLimit) | ||
| refresh(page, pageLimit, agentflowVersion) | ||
| refresh(page, pageLimit, agentflowVersion, searchRef.current) | ||
| } | ||
|
|
||
| const refresh = (page, limit, nextView) => { | ||
| const refresh = (page, limit, nextView, searchVal) => { | ||
| const params = { | ||
| page: page || currentPage, | ||
| limit: limit || pageLimit | ||
| } | ||
| if (searchVal) { | ||
| params.search = searchVal | ||
| } | ||
| getAllAgentflows.request(nextView === 'v2' ? 'AGENTFLOW' : 'MULTIAGENT', params) | ||
| } | ||
|
|
||
|
|
@@ -78,19 +86,22 @@ const Agentflows = () => { | |
| if (nextView === null) return | ||
| localStorage.setItem('agentFlowVersion', nextView) | ||
| setAgentflowVersion(nextView) | ||
| refresh(1, pageLimit, nextView) | ||
| refresh(1, pageLimit, nextView, searchRef.current) | ||
| } | ||
|
|
||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| const debouncedSearch = useCallback( | ||
| debounce((value, version) => { | ||
| setCurrentPage(1) | ||
| refresh(1, pageLimit, version, value) | ||
| }, 300), | ||
| [pageLimit] | ||
| ) | ||
|
Comment on lines
+92
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To fix this, you should make |
||
|
|
||
| const onSearchChange = (event) => { | ||
| setSearch(event.target.value) | ||
| } | ||
|
|
||
| function filterFlows(data) { | ||
| return ( | ||
| data.name.toLowerCase().indexOf(search.toLowerCase()) > -1 || | ||
| (data.category && data.category.toLowerCase().indexOf(search.toLowerCase()) > -1) || | ||
| data.id.toLowerCase().indexOf(search.toLowerCase()) > -1 | ||
| ) | ||
| searchRef.current = event.target.value | ||
| debouncedSearch(event.target.value, agentflowVersion) | ||
| } | ||
|
|
||
| const addNew = () => { | ||
|
|
@@ -304,7 +315,7 @@ const Agentflows = () => { | |
| <> | ||
| {!view || view === 'card' ? ( | ||
| <Box display='grid' gridTemplateColumns='repeat(3, 1fr)' gap={gridSpacing}> | ||
| {getAllAgentflows.data?.data.filter(filterFlows).map((data, index) => ( | ||
| {getAllAgentflows.data?.data?.map((data, index) => ( | ||
| <ItemCard | ||
| key={index} | ||
| onClick={() => goToCanvas(data)} | ||
|
|
@@ -322,7 +333,6 @@ const Agentflows = () => { | |
| images={images} | ||
| icons={icons} | ||
| isLoading={isLoading} | ||
| filterFunction={filterFlows} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this A quick fix is to pass a no-op filter: However, since filtering is now done on the server, the client-side filtering in |
||
| updateFlowsApi={getAllAgentflows} | ||
| setError={setError} | ||
| currentPage={currentPage} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { useEffect, useState } from 'react' | ||
| import { useEffect, useState, useCallback, useRef } from 'react' | ||
| import { useNavigate } from 'react-router-dom' | ||
|
|
||
| // material-ui | ||
|
|
@@ -27,6 +27,9 @@ import useApi from '@/hooks/useApi' | |
| import { baseURL } from '@/store/constant' | ||
| import { useError } from '@/store/context/ErrorContext' | ||
|
|
||
| // utils | ||
| import { debounce } from 'lodash' | ||
|
|
||
| // icons | ||
| import { IconPlus, IconLayoutGrid, IconList } from '@tabler/icons-react' | ||
|
|
||
|
|
@@ -48,18 +51,22 @@ const Chatflows = () => { | |
| const [currentPage, setCurrentPage] = useState(1) | ||
| const [pageLimit, setPageLimit] = useState(DEFAULT_ITEMS_PER_PAGE) | ||
| const [total, setTotal] = useState(0) | ||
| const searchRef = useRef('') | ||
|
|
||
| const onChange = (page, pageLimit) => { | ||
| setCurrentPage(page) | ||
| setPageLimit(pageLimit) | ||
| applyFilters(page, pageLimit) | ||
| applyFilters(page, pageLimit, searchRef.current) | ||
| } | ||
|
|
||
| const applyFilters = (page, limit) => { | ||
| const applyFilters = (page, limit, searchVal) => { | ||
| const params = { | ||
| page: page || currentPage, | ||
| limit: limit || pageLimit | ||
| } | ||
| if (searchVal) { | ||
| params.search = searchVal | ||
| } | ||
| getAllChatflowsApi.request(params) | ||
| } | ||
|
|
||
|
|
@@ -69,16 +76,19 @@ const Chatflows = () => { | |
| setView(nextView) | ||
| } | ||
|
|
||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| const debouncedSearch = useCallback( | ||
| debounce((value) => { | ||
| setCurrentPage(1) | ||
| applyFilters(1, pageLimit, value) | ||
| }, 300), | ||
| [pageLimit] | ||
| ) | ||
|
Comment on lines
+79
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The To fix this, you should make |
||
|
|
||
| const onSearchChange = (event) => { | ||
| setSearch(event.target.value) | ||
| } | ||
|
|
||
| function filterFlows(data) { | ||
| return ( | ||
| data?.name.toLowerCase().indexOf(search.toLowerCase()) > -1 || | ||
| (data.category && data.category.toLowerCase().indexOf(search.toLowerCase()) > -1) || | ||
| data?.id.toLowerCase().indexOf(search.toLowerCase()) > -1 | ||
| ) | ||
| searchRef.current = event.target.value | ||
| debouncedSearch(event.target.value) | ||
| } | ||
|
|
||
| const addNew = () => { | ||
|
|
@@ -196,7 +206,7 @@ const Chatflows = () => { | |
| <> | ||
| {!view || view === 'card' ? ( | ||
| <Box display='grid' gridTemplateColumns='repeat(3, 1fr)' gap={gridSpacing}> | ||
| {getAllChatflowsApi.data?.data?.filter(filterFlows).map((data, index) => ( | ||
| {getAllChatflowsApi.data?.data?.map((data, index) => ( | ||
| <ItemCard key={index} onClick={() => goToCanvas(data)} data={data} images={images[data.id]} /> | ||
| ))} | ||
| </Box> | ||
|
|
@@ -205,7 +215,6 @@ const Chatflows = () => { | |
| data={getAllChatflowsApi.data?.data} | ||
| images={images} | ||
| isLoading={isLoading} | ||
| filterFunction={filterFlows} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this A quick fix is to pass a no-op filter: However, since filtering is now done on the server, the client-side filtering in |
||
| updateFlowsApi={getAllChatflowsApi} | ||
| setError={setError} | ||
| currentPage={currentPage} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous client-side search was case-insensitive. This
LIKEimplementation might be case-sensitive depending on the database's collation. To ensure consistent, case-insensitive search behavior across different databases, it's better to useLOWER()on both the column and the search term.