From b9bc8e7c330afc09c7926c83ddf0ee4f21764371 Mon Sep 17 00:00:00 2001 From: Augustin Husson Date: Wed, 12 Jan 2022 16:20:22 +0100 Subject: [PATCH 1/2] create a component to handle the search bar with debounce Signed-off-by: Augustin Husson --- web/ui/react-app/src/components/SearchBar.tsx | 31 +++++++++++++++++++ .../src/pages/serviceDiscovery/Services.tsx | 12 ++----- .../src/pages/targets/ScrapePoolList.tsx | 12 ++----- 3 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 web/ui/react-app/src/components/SearchBar.tsx diff --git a/web/ui/react-app/src/components/SearchBar.tsx b/web/ui/react-app/src/components/SearchBar.tsx new file mode 100644 index 000000000..761b29068 --- /dev/null +++ b/web/ui/react-app/src/components/SearchBar.tsx @@ -0,0 +1,31 @@ +import React, { ChangeEvent, FC } from 'react'; +import { Input, InputGroup, InputGroupAddon, InputGroupText } from 'reactstrap'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { faSearch } from '@fortawesome/free-solid-svg-icons'; + +export interface SearchBarProps { + handleChange: (e: ChangeEvent) => void; + placeholder: string; +} + +const SearchBar: FC = ({ handleChange, placeholder }) => { + let filterTimeout: NodeJS.Timeout; + + const handleSearchChange = (e: ChangeEvent) => { + clearTimeout(filterTimeout); + filterTimeout = setTimeout(() => { + handleChange(e); + }, 300); + }; + + return ( + + + {} + + + + ); +}; + +export default SearchBar; diff --git a/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx b/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx index ed90b7e3e..9f407ac32 100644 --- a/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx +++ b/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx @@ -8,9 +8,8 @@ import { mapObjEntries } from '../../utils'; import { usePathPrefix } from '../../contexts/PathPrefixContext'; import { API_PATH } from '../../constants/constants'; import { KVSearch } from '@nexucis/kvsearch'; -import { Container, Input, InputGroup, InputGroupAddon, InputGroupText } from 'reactstrap'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faSearch } from '@fortawesome/free-solid-svg-icons'; +import { Container } from 'reactstrap'; +import SearchBar from '../../components/SearchBar'; interface ServiceMap { activeTargets: Target[]; @@ -117,12 +116,7 @@ export const ServiceDiscoveryContent: FC = ({ activeTargets, dropped <>

Service Discovery

- - - {} - - - +
    {mapObjEntries(targetList, ([k, v]) => ( diff --git a/web/ui/react-app/src/pages/targets/ScrapePoolList.tsx b/web/ui/react-app/src/pages/targets/ScrapePoolList.tsx index f3f42da75..16640dc14 100644 --- a/web/ui/react-app/src/pages/targets/ScrapePoolList.tsx +++ b/web/ui/react-app/src/pages/targets/ScrapePoolList.tsx @@ -5,14 +5,13 @@ import { API_PATH } from '../../constants/constants'; import { groupTargets, ScrapePool, ScrapePools, Target } from './target'; import { withStatusIndicator } from '../../components/withStatusIndicator'; import { ChangeEvent, FC, useEffect, useState } from 'react'; -import { Col, Collapse, Input, InputGroup, InputGroupAddon, InputGroupText, Row } from 'reactstrap'; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faSearch } from '@fortawesome/free-solid-svg-icons'; +import { Col, Collapse, Row } from 'reactstrap'; import { ScrapePoolContent } from './ScrapePoolContent'; import Filter, { Expanded, FilterData } from './Filter'; import { useLocalStorage } from '../../hooks/useLocalStorage'; import styles from './ScrapePoolPanel.module.css'; import { ToggleMoreLess } from '../../components/ToggleMoreLess'; +import SearchBar from '../../components/SearchBar'; interface ScrapePoolListProps { activeTargets: Target[]; @@ -98,12 +97,7 @@ const ScrapePoolListContent: FC = ({ activeTargets }) => { - - - {} - - - + {Object.keys(poolList) From 74f497ac18305a41fbc1f79b280f27a82abe4abc Mon Sep 17 00:00:00 2001 From: Augustin Husson Date: Wed, 19 Jan 2022 14:01:39 +0100 Subject: [PATCH 2/2] Update web/ui/react-app/src/pages/serviceDiscovery/Services.tsx Co-authored-by: Julius Volz Signed-off-by: Augustin Husson --- web/ui/react-app/src/pages/serviceDiscovery/Services.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx b/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx index 9f407ac32..66fe93061 100644 --- a/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx +++ b/web/ui/react-app/src/pages/serviceDiscovery/Services.tsx @@ -116,7 +116,7 @@ export const ServiceDiscoveryContent: FC = ({ activeTargets, dropped <>

    Service Discovery

    - +
      {mapObjEntries(targetList, ([k, v]) => (