From 56360d9136812f4a5570d3bcffe42e60f38663d0 Mon Sep 17 00:00:00 2001 From: veetmoradiya3628 Date: Tue, 13 May 2025 00:05:55 +0530 Subject: [PATCH] Search functionality in the projects page for efficient usage --- config-ui/src/routes/project/home/index.tsx | 33 +++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/config-ui/src/routes/project/home/index.tsx b/config-ui/src/routes/project/home/index.tsx index 0c52c186023..8980edaba1b 100644 --- a/config-ui/src/routes/project/home/index.tsx +++ b/config-ui/src/routes/project/home/index.tsx @@ -38,12 +38,18 @@ export const ProjectHomePage = () => { const [open, setOpen] = useState(false); const [name, setName] = useState(''); const [saving, setSaving] = useState(false); + const [inputValue, setInputValue] = useState(''); + const [searchKeyword, setSearchKeyword] = useState(''); const nameRef = useRef(null); const connectionRef = useRef(null); const configRef = useRef(null); + const debounceRef = useRef(null); - const { ready, data } = useRefreshData(() => API.project.list({ page, pageSize }), [version, page, pageSize]); + const { ready, data } = useRefreshData( + () => API.project.list({ page, pageSize, ...(searchKeyword.trim() && { keyword: searchKeyword.trim() }) }), + [version, page, pageSize, searchKeyword] + ); const navigate = useNavigate(); @@ -98,12 +104,35 @@ export const ProjectHomePage = () => { if (success) { handleHideDialog(); setVersion((v) => v + 1); + setPage(1); + setSearchKeyword(''); + setInputValue(''); } }; + const handleSearch = (value: string) => { + setInputValue(value); + + if (debounceRef.current) { + clearTimeout(debounceRef.current); + } + + debounceRef.current = setTimeout(() => { + setSearchKeyword(value.trim()); + setPage(1); + setVersion((v) => v + 1); + }, 500); + }; + return ( - + + handleSearch(e.target.value)} + />