Skip to content

Commit 15eba06

Browse files
Search functionality in the projects page for efficient usage (#8437)
1 parent ca8b887 commit 15eba06

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

config-ui/src/routes/project/home/index.tsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,18 @@ export const ProjectHomePage = () => {
3838
const [open, setOpen] = useState(false);
3939
const [name, setName] = useState('');
4040
const [saving, setSaving] = useState(false);
41+
const [inputValue, setInputValue] = useState('');
42+
const [searchKeyword, setSearchKeyword] = useState('');
4143

4244
const nameRef = useRef(null);
4345
const connectionRef = useRef(null);
4446
const configRef = useRef(null);
47+
const debounceRef = useRef<NodeJS.Timeout | null>(null);
4548

46-
const { ready, data } = useRefreshData(() => API.project.list({ page, pageSize }), [version, page, pageSize]);
49+
const { ready, data } = useRefreshData(
50+
() => API.project.list({ page, pageSize, ...(searchKeyword.trim() && { keyword: searchKeyword.trim() }) }),
51+
[version, page, pageSize, searchKeyword]
52+
);
4753

4854
const navigate = useNavigate();
4955

@@ -98,12 +104,35 @@ export const ProjectHomePage = () => {
98104
if (success) {
99105
handleHideDialog();
100106
setVersion((v) => v + 1);
107+
setPage(1);
108+
setSearchKeyword('');
109+
setInputValue('');
101110
}
102111
};
103112

113+
const handleSearch = (value: string) => {
114+
setInputValue(value);
115+
116+
if (debounceRef.current) {
117+
clearTimeout(debounceRef.current);
118+
}
119+
120+
debounceRef.current = setTimeout(() => {
121+
setSearchKeyword(value.trim());
122+
setPage(1);
123+
setVersion((v) => v + 1);
124+
}, 500);
125+
};
126+
104127
return (
105128
<PageHeader breadcrumbs={[{ name: 'Projects', path: PATHS.PROJECTS() }]}>
106-
<Flex style={{ marginBottom: 16 }} justify="flex-end">
129+
<Flex style={{ marginBottom: 16, width: '100%' }} justify="flex-end" align="center">
130+
<Input
131+
placeholder="Search project ..."
132+
style={{ width: 300, marginRight: 12 }}
133+
value={inputValue}
134+
onChange={(e) => handleSearch(e.target.value)}
135+
/>
107136
<Button type="primary" icon={<PlusOutlined />} onClick={handleShowDialog}>
108137
New Project
109138
</Button>

0 commit comments

Comments
 (0)