Debounce global search IO-530
This commit is contained in:
@@ -1,12 +1,13 @@
|
|||||||
import { useLazyQuery } from "@apollo/react-hooks";
|
import { useLazyQuery } from "@apollo/react-hooks";
|
||||||
import { AutoComplete, Input } from "antd";
|
import { AutoComplete, Input } from "antd";
|
||||||
|
import _ from "lodash";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import { logImEXEvent } from "../../firebase/firebase.utils";
|
|
||||||
import { GLOBAL_SEARCH_QUERY } from "../../graphql/search.queries";
|
import { GLOBAL_SEARCH_QUERY } from "../../graphql/search.queries";
|
||||||
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
import CurrencyFormatter from "../../utils/CurrencyFormatter";
|
||||||
import AlertComponent from "../alert/alert.component";
|
import AlertComponent from "../alert/alert.component";
|
||||||
|
|
||||||
export default function GlobalSearch() {
|
export default function GlobalSearch() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
@@ -14,27 +15,18 @@ export default function GlobalSearch() {
|
|||||||
GLOBAL_SEARCH_QUERY
|
GLOBAL_SEARCH_QUERY
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleSearch = (searchTerm) => {
|
const executeSearch = (v) => {
|
||||||
logImEXEvent("global_search", { term: searchTerm });
|
callSearch(v);
|
||||||
|
};
|
||||||
|
const debouncedExecuteSearch = _.debounce(executeSearch, 500);
|
||||||
|
|
||||||
if (searchTerm.length > 0)
|
const handleSearch = (value) => {
|
||||||
callSearch({ variables: { search: searchTerm } });
|
if (value && value !== "")
|
||||||
|
debouncedExecuteSearch({ variables: { search: value } });
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderTitle = (title) => {
|
const renderTitle = (title) => {
|
||||||
return (
|
return <span>{title}</span>;
|
||||||
<span>
|
|
||||||
{title}
|
|
||||||
<a
|
|
||||||
style={{ float: "right" }}
|
|
||||||
href="https://www.google.com/search?q=antd"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
>
|
|
||||||
more
|
|
||||||
</a>
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const options = data
|
const options = data
|
||||||
@@ -155,8 +147,9 @@ export default function GlobalSearch() {
|
|||||||
dropdownMatchSelectWidth={false}
|
dropdownMatchSelectWidth={false}
|
||||||
style={{ width: 200 }}
|
style={{ width: 200 }}
|
||||||
options={options}
|
options={options}
|
||||||
|
onSearch={handleSearch}
|
||||||
>
|
>
|
||||||
<Input.Search loading={loading} onSearch={handleSearch} />
|
<Input.Search loading={loading} />
|
||||||
</AutoComplete>
|
</AutoComplete>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Dropdown, Button, Table } from "antd";
|
import { Dropdown, Button, Table, Space } from "antd";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
import ScoreboardRemoveButton from "../scoreboard-remove-button/scorebard-remove-button.component";
|
import ScoreboardRemoveButton from "../scoreboard-remove-button/scorebard-remove-button.component";
|
||||||
@@ -42,10 +42,10 @@ export default function ScoreboardJobsList({ scoreBoardlist }) {
|
|||||||
dataIndex: "actions",
|
dataIndex: "actions",
|
||||||
key: "actions",
|
key: "actions",
|
||||||
render: (text, record) => (
|
render: (text, record) => (
|
||||||
<div>
|
<Space>
|
||||||
<ScoreboardEntryEdit entry={record} style={{ zIndex: 15 }} />
|
<ScoreboardEntryEdit entry={record} style={{ zIndex: 15 }} />
|
||||||
<ScoreboardRemoveButton scoreboardId={record.id} />
|
<ScoreboardRemoveButton scoreboardId={record.id} />
|
||||||
</div>
|
</Space>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user