Skip to content

Commit c62d804

Browse files
authored
fix(AIM): Fix operator search field to keep cursor location (#4922)
1 parent 3a114cb commit c62d804

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

cypress/e2e/cloud/operatorRO.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe('Operator Page', () => {
8787
cy.getByTestID('orgTab').click()
8888
cy.getByTestID('operator-resource--searchbar').type('678', {
8989
force: true,
90-
delay: 50,
90+
delay: 300,
9191
})
9292

9393
cy.getByTestID('table-body').within(() => {

src/operator/ResourcesSearchbar.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Libraries
2-
import React, {ChangeEvent, FC, useContext} from 'react'
2+
import React, {ChangeEvent, FC, useContext, useState, useRef} from 'react'
33
import {Input, IconFont} from '@influxdata/clockface'
44
import {OperatorContext} from 'src/operator/context/operator'
55
import {debounce} from 'lodash'
@@ -8,12 +8,14 @@ import {debounce} from 'lodash'
88
import {OperatorRoutes} from 'src/operator/constants'
99

1010
const ResourcesSearchbar: FC = () => {
11-
const {pathname, searchTerm, setSearchTerm} = useContext(OperatorContext)
11+
const {pathname, setSearchTerm} = useContext(OperatorContext)
12+
const [searchText, setSearchText] = useState('')
1213

13-
const debounceFunc = debounce(setSearchTerm, 50)
14+
const debounceFunc = useRef(debounce(setSearchTerm, 300))
1415

1516
const changeSearchTerm = (event: ChangeEvent<HTMLInputElement>) => {
16-
debounceFunc(event.target.value)
17+
setSearchText(event.target.value)
18+
debounceFunc.current(event.target.value)
1719
}
1820

1921
const isOrgsTab = pathname.includes(OperatorRoutes.organizations)
@@ -27,7 +29,7 @@ const ResourcesSearchbar: FC = () => {
2729
isOrgsTab === 'organizations' ? 'id' : 'email'
2830
} ...`}
2931
inputStyle={{width: '500px'}}
30-
value={searchTerm}
32+
value={searchText}
3133
onChange={changeSearchTerm}
3234
testID="operator-resource--searchbar"
3335
/>

0 commit comments

Comments
 (0)