File tree 2 files changed +8
-15
lines changed
src/components/EditorSidePanel/TablesTab 2 files changed +8
-15
lines changed Original file line number Diff line number Diff line change 1
- import { useState } from "react" ;
2
- import { useSelect , useTables } from "../../../hooks" ;
1
+ import { useMemo , useState } from "react" ;
2
+ import { useSelect } from "../../../hooks" ;
3
3
import { AutoComplete } from "@douyinfe/semi-ui" ;
4
4
import { IconSearch } from "@douyinfe/semi-icons" ;
5
5
import { ObjectType } from "../../../data/constants" ;
6
6
7
- export default function SearchBar ( ) {
8
- const { tables } = useTables ( ) ;
7
+ export default function SearchBar ( { tables } ) {
9
8
const { setSelectedElement } = useSelect ( ) ;
10
9
const [ searchText , setSearchText ] = useState ( "" ) ;
11
- const [ filteredResult , setFilteredResult ] = useState (
12
- tables . map ( ( t ) => t . name ) ,
10
+ const filteredTable = useMemo (
11
+ ( ) => tables . map ( ( t ) => t . name ) . filter ( ( i ) => i . includes ( searchText ) ) ,
12
+ [ tables , searchText ] ,
13
13
) ;
14
14
15
- const handleStringSearch = ( value ) => {
16
- setFilteredResult (
17
- tables . map ( ( t ) => t . name ) . filter ( ( i ) => i . includes ( value ) ) ,
18
- ) ;
19
- } ;
20
-
21
15
return (
22
16
< AutoComplete
23
- data = { filteredResult }
17
+ data = { filteredTable }
24
18
value = { searchText }
25
19
showClear
26
20
prefix = { < IconSearch /> }
27
21
placeholder = "Search..."
28
- onSearch = { ( v ) => handleStringSearch ( v ) }
29
22
emptyContent = { < div className = "p-3 popover-theme" > No tables found</ div > }
30
23
onChange = { ( v ) => setSearchText ( v ) }
31
24
onSelect = { ( v ) => {
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export default function TablesTab() {
14
14
< >
15
15
< Row gutter = { 6 } >
16
16
< Col span = { 16 } >
17
- < SearchBar />
17
+ < SearchBar tables = { tables } />
18
18
</ Col >
19
19
< Col span = { 8 } >
20
20
< Button icon = { < IconPlus /> } block onClick = { ( ) => addTable ( true ) } >
You can’t perform that action at this time.
0 commit comments