Skip to content

Commit b4940c7

Browse files
committed
search bar incorporated
1 parent 25b99ce commit b4940c7

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

src/components/ClusterNodes/ClusterSelectionList.tsx

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useHistory, useLocation } from 'react-router-dom'
33
import { ReactComponent as Search } from '../../assets/icons/ic-search.svg'
44
import { ReactComponent as Clear } from '../../assets/icons/ic-error.svg'
55
import { handleUTCTime } from '../common'
6-
import { Progressing } from '@devtron-labs/devtron-fe-common-lib'
6+
import { CustomInput, Progressing, SearchBar } from '@devtron-labs/devtron-fe-common-lib'
77
import { ClusterDetail } from './types'
88
import { ReactComponent as Error } from '../../assets/icons/ic-error-exclamation.svg'
99
import { ReactComponent as Success } from '../../assets/icons/appstatus/healthy.svg'
@@ -73,37 +73,36 @@ export default function ClusterSelectionList({
7373
setSearchText('')
7474
}
7575

76-
const handleFilterKeyPress = (event): void => {
77-
const theKeyCode = event.key
78-
if (theKeyCode === 'Enter') {
79-
handleFilterChanges(event.target.value)
76+
const handleFilterKeyPress = (value): void => {
77+
handleFilterChanges(value)
8078
setSearchApplied(true)
81-
} else if (theKeyCode === 'Backspace' && searchText.length === 1) {
82-
clearSearch()
83-
}
79+
}
80+
81+
const handleSearchChange = (value): void => {
82+
setSearchText(value)
83+
}
84+
85+
const handleOnBlur = (event): void => {
86+
event.stopPropagation()
87+
let _searchText = event.target.value
88+
_searchText = _searchText?.trim()
89+
handleFilterChanges(_searchText)
90+
setSearchText(_searchText)
8491
}
8592

8693
const renderSearch = (): JSX.Element => {
8794
return (
88-
<div className="search dc__position-rel margin-right-0 en-2 bw-1 br-4 h-32">
89-
<Search className="search__icon icon-dim-18" />
90-
<input
91-
type="text"
92-
placeholder="Search clusters"
93-
value={searchText}
94-
className="search__input"
95-
onChange={(event) => {
96-
setSearchText(event.target.value)
97-
}}
98-
onKeyDown={handleFilterKeyPress}
99-
disabled={clusterListLoader}
100-
/>
101-
{searchApplied && (
102-
<button className="search__clear-button" type="button" onClick={clearSearch}>
103-
<Clear className="icon-dim-18 icon-n4 dc__vertical-align-middle" />
104-
</button>
105-
)}
106-
</div>
95+
<SearchBar
96+
initialSearchText={searchText}
97+
handleSearchChange={handleSearchChange}
98+
handleEnter={handleFilterKeyPress}
99+
containerClassName="w-250-imp"
100+
inputProps={{
101+
placeholder: 'Search clusters',
102+
autoFocus: true,
103+
}}
104+
handleOnBlur={handleOnBlur}
105+
/>
107106
)
108107
}
109108

0 commit comments

Comments
 (0)