Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refresh search list after modification #53

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 7 additions & 14 deletions src/components/EditorSidePanel/TablesTab/SearchBar.jsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,23 @@
import { useState } from "react";
import { useSelect, useTables } from "../../../hooks";
import { useEffect, useMemo, useState } from "react";

Check failure on line 1 in src/components/EditorSidePanel/TablesTab/SearchBar.jsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'useEffect' is defined but never used

Check failure on line 1 in src/components/EditorSidePanel/TablesTab/SearchBar.jsx

View workflow job for this annotation

GitHub Actions / build (20.x)

'useEffect' is defined but never used
import { useSelect } from "../../../hooks";
import { AutoComplete } from "@douyinfe/semi-ui";
import { IconSearch } from "@douyinfe/semi-icons";

export default function SearchBar() {
const { tables } = useTables();
export default function SearchBar({ tables }) {
const { setSelectedElement } = useSelect();
const [searchText, setSearchText] = useState("");
const [filteredResult, setFilteredResult] = useState(
tables.map((t) => t.name)
const filteredTable = useMemo(
() => tables.map((t) => t.name).filter((i) => i.includes(searchText)),
[tables, searchText],
);

const handleStringSearch = (value) => {
setFilteredResult(
tables.map((t) => t.name).filter((i) => i.includes(value))
);
};

return (
<AutoComplete
data={filteredResult}
data={filteredTable}
value={searchText}
showClear
prefix={<IconSearch />}
placeholder="Search..."
onSearch={(v) => handleStringSearch(v)}
emptyContent={<div className="p-3 popover-theme">No tables found</div>}
onChange={(v) => setSearchText(v)}
onSelect={(v) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/EditorSidePanel/TablesTab/TablesTab.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function TablesTab() {
<>
<Row gutter={6}>
<Col span={16}>
<SearchBar />
<SearchBar tables={tables} />
</Col>
<Col span={8}>
<Button icon={<IconPlus />} block onClick={() => addTable(true)}>
Expand Down
Loading