Skip to content

Commit fd85ba9

Browse files
authored
feat: enable clearable text fields on search widget (#2976)
* starting to use clearable field: dashboardlist * now using clearable field: SearchWidget * working on search-source bar * updated raw flux editor : updated placeholder text and successfully tested the functions; via the 'functions' button in the flux script notebook 'create notebook' page * enabled in Alerts Page search * adding clearbutton to the FluxToolbarSearch * added clearing to all the filters in the querybuilder * removed dead code, added clearing to components in notebooks, and the user list
1 parent d9e86c1 commit fd85ba9

File tree

14 files changed

+72
-236
lines changed

14 files changed

+72
-236
lines changed

src/alerting/components/AlertsColumn.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ const AlertsColumnHeader: FC<OwnProps & StateProps> = ({
7272
/>
7373
)
7474

75+
// not using the SearchWidget here, just adding the onClear to the Input;
76+
// because using the SearchWidget instead changes how the 'children(searchTerm)'
77+
// function is called (with the vanilla Input, it is called on each keystroke,
78+
// with the searchWidget is it only called once at render time)
7579
return (
7680
<Panel
7781
backgroundColor={InfluxColors.Grey5}
@@ -102,6 +106,7 @@ const AlertsColumnHeader: FC<OwnProps & StateProps> = ({
102106
onChange={e => onChangeSearchTerm(e.target.value)}
103107
testID={`filter--input ${type}`}
104108
tabIndex={tabIndex}
109+
onClear={() => onChangeSearchTerm('')}
105110
/>
106111
</div>
107112
<div className="alerting-index--column-body">

src/annotations/components/controlBar/AnnotationsSearchBar.scss

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/annotations/components/controlBar/AnnotationsSearchBar.tsx

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/annotations/components/controlBar/AnnotationsSearchBarItem.tsx

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/flows/pipes/QueryBuilder/BucketSelector.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import BuilderCard from 'src/timeMachine/components/builderCard/BuilderCard'
88
import {BucketContext} from 'src/flows/context/bucket.scoped'
99
import {PipeContext} from 'src/flows/context/pipe'
1010

11+
// this is used by notebooks
1112
const BucketSelector: FC = () => {
1213
const {data, update} = useContext(PipeContext)
1314
const {loading, buckets} = useContext(BucketContext)
@@ -122,6 +123,7 @@ const BucketSelector: FC = () => {
122123
placeholder="Search for a bucket"
123124
className="tag-selector--search"
124125
onChange={e => setSearch(e.target.value)}
126+
onClear={() => setSearch('')}
125127
/>
126128
</BuilderCard.Menu>
127129
<List

src/flows/pipes/QueryBuilder/CardList.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ const Card: FC<Props> = ({idx}) => {
210210
onChange={evt => {
211211
valueSearch(evt.target.value)
212212
}}
213+
onClear={() => valueSearch('')}
213214
/>
214215
</BuilderCard.Menu>
215216
{_values}
@@ -252,6 +253,7 @@ const Card: FC<Props> = ({idx}) => {
252253
onChange={evt => {
253254
valueSearch(evt.target.value)
254255
}}
256+
onClear={() => valueSearch('')}
255257
/>
256258
</BuilderCard.Menu>
257259
{_values}

src/flows/pipes/RawFluxEditor/functions.tsx

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
import React, {FC, useState, useMemo, useCallback} from 'react'
22

3-
import {
4-
Input,
5-
InputType,
6-
IconFont,
7-
EmptyState,
8-
ComponentSize,
9-
} from '@influxdata/clockface'
3+
import {EmptyState, ComponentSize} from '@influxdata/clockface'
104
import {FLUX_FUNCTIONS} from 'src/shared/constants/fluxFunctions'
115
import {FluxToolbarFunction} from 'src/types/shared'
126
import Fn from './function'
7+
import SearchWidget from 'src/shared/components/search_widget/SearchWidget'
138

149
interface Props {
1510
onSelect: (fn: FluxToolbarFunction) => void
@@ -22,8 +17,8 @@ interface FilteredFn {
2217
const Functions: FC<Props> = ({onSelect}) => {
2318
const [search, setSearch] = useState('')
2419
const updateSearch = useCallback(
25-
e => {
26-
setSearch(e.target.value)
20+
text => {
21+
setSearch(text)
2722
},
2823
[search, setSearch]
2924
)
@@ -74,12 +69,10 @@ const Functions: FC<Props> = ({onSelect}) => {
7469
return (
7570
<div className="flux-toolbar">
7671
<div className="flux-toolbar--search">
77-
<Input
78-
type={InputType.Text}
79-
icon={IconFont.Search_New}
80-
placeholder="Filter Functions..."
81-
onChange={updateSearch}
82-
value={search}
72+
<SearchWidget
73+
placeholderText="Filter Functions..."
74+
onSearch={updateSearch}
75+
searchTerm={search}
8376
testID="flux-toolbar-search--input"
8477
/>
8578
</div>

src/me/components/DashboardsList.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ const DashboardList: FC<Props> = ({dashboards, org}) => {
3636
setSearchTerm(e.target.value)
3737
}
3838

39+
const clear = (): void => {
40+
setSearchTerm('')
41+
}
42+
3943
let dashboardsList = (
4044
<EmptyState size={ComponentSize.ExtraSmall}>
4145
<EmptyState.Text>You don't have any Dashboards</EmptyState.Text>
@@ -90,6 +94,7 @@ const DashboardList: FC<Props> = ({dashboards, org}) => {
9094
placeholder="Filter dashboards..."
9195
onChange={handleInputChange}
9296
id="filter-dashboards"
97+
onClear={clear}
9398
/>
9499
{dashboardsList}
95100
</>

src/shared/components/search_widget/SearchWidget.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, {Component, ChangeEvent} from 'react'
33
import {debounce} from 'lodash'
44

55
// Components
6-
import {Input} from '@influxdata/clockface'
6+
import {ComponentSize, Input} from '@influxdata/clockface'
77

88
// Types
99
import {IconFont} from '@influxdata/clockface'
@@ -17,6 +17,9 @@ interface Props {
1717
placeholderText: string
1818
searchTerm: string
1919
testID: string
20+
tabIndex?: number
21+
autoFocus?: boolean
22+
size?: ComponentSize
2023
}
2124

2225
interface State {
@@ -30,6 +33,9 @@ class SearchWidget extends Component<Props, State> {
3033
placeholderText: 'Search...',
3134
searchTerm: '',
3235
testID: 'search-widget',
36+
autoFocus: false,
37+
tabIndex: 0,
38+
size: ComponentSize.Small,
3339
}
3440

3541
public componentDidUpdate(prevProps: Props) {
@@ -50,7 +56,7 @@ class SearchWidget extends Component<Props, State> {
5056
}
5157

5258
public render() {
53-
const {placeholderText, testID} = this.props
59+
const {placeholderText, testID, tabIndex = 0, autoFocus, size} = this.props
5460
const {searchTerm} = this.state
5561

5662
return (
@@ -63,6 +69,10 @@ class SearchWidget extends Component<Props, State> {
6369
onBlur={this.handleBlur}
6470
testID={testID}
6571
className="search-widget-input"
72+
tabIndex={tabIndex}
73+
onClear={this.clear}
74+
autoFocus={autoFocus}
75+
size={size}
6676
/>
6777
</ErrorBoundary>
6878
)
@@ -79,6 +89,9 @@ class SearchWidget extends Component<Props, State> {
7989
private handleChange = (e: ChangeEvent<HTMLInputElement>): void => {
8090
this.setState({searchTerm: e.target.value}, this.handleSearch)
8191
}
92+
private clear = (): void => {
93+
this.setState({searchTerm: ''}, this.handleSearch)
94+
}
8295
}
8396

8497
export default SearchWidget

0 commit comments

Comments
 (0)