11import React from 'react' ;
2- import Autosuggest from 'react-autosuggest' ;
2+ import Autosuggest , { InputProps } from 'react-autosuggest' ;
33import { StandardEditorContext , StandardEditorProps } from '@grafana/data' ;
44import './TypeaheadTextfield.css' ;
55import { PanelSettings } from '../../types' ;
6-
76interface Props extends StandardEditorProps < string , PanelSettings > {
87 item : any ;
98 value : string ;
109 onChange : ( value ?: string ) => void ;
1110 context : StandardEditorContext < any > ;
1211}
13-
1412interface State {
1513 item : any ;
1614 value : string ;
1715 onChange : ( value ?: string ) => void ;
1816 context : StandardEditorContext < any > ;
1917 suggestions : string [ ] ;
2018}
21-
2219export class TypeaheadTextField extends React . PureComponent < Props , State > {
2320 constructor ( props : Props | Readonly < Props > ) {
2421 super ( props ) ;
25-
2622 var { value } = props ;
2723 if ( value === undefined ) {
2824 value = props . item . defaultValue ;
@@ -33,11 +29,9 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
3329 suggestions : [ ] ,
3430 } ;
3531 }
36-
3732 renderSuggestion ( suggestion : string ) {
3833 return < div > { suggestion } </ div > ;
3934 }
40-
4135 getColumnNames ( ) {
4236 var { data } = this . props . context ;
4337 var series ;
@@ -56,17 +50,15 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
5650 }
5751 return columnNames ;
5852 }
59-
60- onChange = ( event : React . FormEvent < HTMLInputElement > , { newValue } : { newValue : string } ) => {
53+ onChange = ( event : React . FormEvent < HTMLElement > , { newValue } : { newValue : string } ) => {
6154 //TODO make this type nicer!
6255 const { path } = this . props . item ;
63- const { value } = event . currentTarget ;
56+ const { value } = event . currentTarget as HTMLInputElement ;
6457 this . setState ( {
6558 value : value ,
6659 } ) ;
6760 this . props . onChange . call ( path , newValue ) ;
6861 } ;
69-
7062 getSuggestions = ( value : string ) => {
7163 var inputValue = '' ;
7264 if ( value !== undefined ) {
@@ -75,44 +67,36 @@ export class TypeaheadTextField extends React.PureComponent<Props, State> {
7567 if ( value !== undefined && value !== null && value !== '' ) {
7668 inputValue = value . trim ( ) . toLowerCase ( ) ;
7769 }
78-
7970 const inputLength = inputValue . length ;
8071 if ( inputLength === 0 || inputValue === undefined ) {
8172 return [ ] ;
8273 }
83- return this . getColumnNames ( ) . filter ( columnName => columnName . toLowerCase ( ) . startsWith ( inputValue ) ) ;
74+ return this . getColumnNames ( ) . filter ( ( columnName ) => columnName . toLowerCase ( ) . startsWith ( inputValue ) ) ;
8475 } ;
85-
8676 onSuggestionsFetchRequested = ( value : any ) => {
8777 this . setState ( {
8878 suggestions : this . getSuggestions ( value ) ,
8979 } ) ;
9080 } ;
91-
9281 getSuggestionValue = ( suggestion : string ) => {
9382 return suggestion ;
9483 } ;
95-
9684 onSuggestionsClearRequested = ( ) => {
9785 this . setState ( {
9886 suggestions : [ ] ,
9987 } ) ;
10088 } ;
101-
10289 render ( ) {
10390 var { value } = this . props ;
10491 if ( value === undefined ) {
10592 value = this . props . item . defaultValue ;
10693 }
107-
10894 const suggestions = this . getSuggestions ( value ) ;
109-
110- const inputProps = {
95+ const inputProps : InputProps < string > = {
11196 placeholder : 'Enter column name...' ,
11297 value,
11398 onChange : this . onChange ,
11499 } ;
115-
116100 return (
117101 < Autosuggest
118102 suggestions = { suggestions }
0 commit comments