@@ -38,12 +38,18 @@ export const ProjectHomePage = () => {
38
38
const [ open , setOpen ] = useState ( false ) ;
39
39
const [ name , setName ] = useState ( '' ) ;
40
40
const [ saving , setSaving ] = useState ( false ) ;
41
+ const [ inputValue , setInputValue ] = useState ( '' ) ;
42
+ const [ searchKeyword , setSearchKeyword ] = useState ( '' ) ;
41
43
42
44
const nameRef = useRef ( null ) ;
43
45
const connectionRef = useRef ( null ) ;
44
46
const configRef = useRef ( null ) ;
47
+ const debounceRef = useRef < NodeJS . Timeout | null > ( null ) ;
45
48
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
+ ) ;
47
53
48
54
const navigate = useNavigate ( ) ;
49
55
@@ -98,12 +104,35 @@ export const ProjectHomePage = () => {
98
104
if ( success ) {
99
105
handleHideDialog ( ) ;
100
106
setVersion ( ( v ) => v + 1 ) ;
107
+ setPage ( 1 ) ;
108
+ setSearchKeyword ( '' ) ;
109
+ setInputValue ( '' ) ;
101
110
}
102
111
} ;
103
112
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
+
104
127
return (
105
128
< 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
+ />
107
136
< Button type = "primary" icon = { < PlusOutlined /> } onClick = { handleShowDialog } >
108
137
New Project
109
138
</ Button >
0 commit comments