11import React , { useState , useEffect } from "react" ;
22import { Layout } from "@elastic/react-search-ui-views" ;
33import { ErrorBoundary , Facet , PagingInfo , ResultsPerPage , Paging , useSearch , SearchBox } from "@elastic/react-search-ui" ;
4- import { Box , Button , TextField , InputAdornment } from "@mui/material" ;
4+ import { Box , Button , TextField , InputAdornment , Tooltip } from "@mui/material" ;
55import CalendarMonthIcon from '@mui/icons-material/CalendarMonth' ;
6+ import ClearRoundedIcon from '@mui/icons-material/ClearRounded' ;
67import DatePicker from "react-datepicker" ;
78import "react-datepicker/dist/react-datepicker.css" ;
89import './CaputLogSearchLayout.css' ;
10+ import CustomSearchBoxView from "./CustomSearchBoxView" ;
911import moment from "moment" ;
1012import PropTypes from "prop-types" ;
1113
@@ -15,17 +17,19 @@ const propTypes = {
1517 field : PropTypes . string . isRequired ,
1618 label : PropTypes . string . isRequired ,
1719 } ) ) ,
20+ initialSearchTerm : PropTypes . string ,
1821 children : PropTypes . func . isRequired ,
1922}
2023
2124function CaputLogSearchLayout ( {
2225 showSearchBox = false ,
2326 facetFields = [ ] ,
27+ initialSearchTerm = "" ,
2428 children
2529} ) {
2630 const [ startDate , setStartDate ] = useState ( null ) ;
2731 const [ endDate , setEndDate ] = useState ( null ) ;
28- const { wasSearched, setFilter, removeFilter, results, setSort } = useSearch ( ) ;
32+ const { wasSearched, setFilter, removeFilter, results, setSort, setSearchTerm } = useSearch ( ) ;
2933
3034 // Set initial sort to @timestamp desc on mount
3135 useEffect ( ( ) => {
@@ -49,9 +53,10 @@ function CaputLogSearchLayout({
4953 }
5054 } ;
5155
52- const clearDateFilters = ( ) => {
56+ const clearAllFilters = ( ) => {
5357 setStartDate ( null ) ;
5458 setEndDate ( null ) ;
59+ setSearchTerm ( initialSearchTerm ) ;
5560 removeFilter ( "@timestamp" ) ;
5661 } ;
5762
@@ -67,7 +72,10 @@ function CaputLogSearchLayout({
6772 flexDirection : "column" ,
6873 } } >
6974 { showSearchBox && (
70- < SearchBox inputProps = { { placeholder : "Search by PV Name, User, or Client" } } />
75+ < SearchBox
76+ inputProps = { { placeholder : "Search by PV Name, User, or Client" } }
77+ view = { CustomSearchBoxView }
78+ />
7179 ) }
7280 < Box sx = { { display : 'flex' , flexDirection : 'row' , gap : 1 , width : '100%' } } >
7381 < Box sx = { { flex : 1 } } >
@@ -98,9 +106,17 @@ function CaputLogSearchLayout({
98106 }
99107 />
100108 </ Box >
101- < Button variant = "contained" onClick = { clearDateFilters } >
102- Clear
103- </ Button >
109+ < Tooltip arrow title = "Clear All Filters" >
110+ < Button
111+ variant = "contained"
112+ disableElevation
113+ color = "secondary"
114+ onClick = { clearAllFilters }
115+ sx = { { minWidth : 56 , height : 40 } }
116+ >
117+ CLEAR < ClearRoundedIcon sx = { { color : 'black' } } fontSize = "medium" />
118+ </ Button >
119+ </ Tooltip >
104120 </ Box >
105121 </ Box >
106122 }
0 commit comments