Skip to content

Commit 8fdb579

Browse files
committed
Merge branch 'enh/refresh-search-list-result-after-modification'
2 parents 62e4318 + f827145 commit 8fdb579

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

src/components/EditorSidePanel/TablesTab/SearchBar.jsx

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
1-
import { useState } from "react";
2-
import { useSelect, useTables } from "../../../hooks";
1+
import { useMemo, useState } from "react";
2+
import { useSelect } from "../../../hooks";
33
import { AutoComplete } from "@douyinfe/semi-ui";
44
import { IconSearch } from "@douyinfe/semi-icons";
55
import { ObjectType } from "../../../data/constants";
66

7-
export default function SearchBar() {
8-
const { tables } = useTables();
7+
export default function SearchBar({ tables }) {
98
const { setSelectedElement } = useSelect();
109
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],
1313
);
1414

15-
const handleStringSearch = (value) => {
16-
setFilteredResult(
17-
tables.map((t) => t.name).filter((i) => i.includes(value)),
18-
);
19-
};
20-
2115
return (
2216
<AutoComplete
23-
data={filteredResult}
17+
data={filteredTable}
2418
value={searchText}
2519
showClear
2620
prefix={<IconSearch />}
2721
placeholder="Search..."
28-
onSearch={(v) => handleStringSearch(v)}
2922
emptyContent={<div className="p-3 popover-theme">No tables found</div>}
3023
onChange={(v) => setSearchText(v)}
3124
onSelect={(v) => {

src/components/EditorSidePanel/TablesTab/TablesTab.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default function TablesTab() {
1414
<>
1515
<Row gutter={6}>
1616
<Col span={16}>
17-
<SearchBar />
17+
<SearchBar tables={tables} />
1818
</Col>
1919
<Col span={8}>
2020
<Button icon={<IconPlus />} block onClick={() => addTable(true)}>

0 commit comments

Comments
 (0)