|
|
|
|
@ -37,34 +37,34 @@ class ExpressionInput extends Component<ExpressionInputProps, ExpressionInputSta |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
|
componentDidMount(): void { |
|
|
|
|
this.setHeight(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
setHeight = () => { |
|
|
|
|
setHeight = (): void => { |
|
|
|
|
const { offsetHeight, clientHeight, scrollHeight } = this.exprInputRef.current!; |
|
|
|
|
const offset = offsetHeight - clientHeight; // Needed in order for the height to be more accurate.
|
|
|
|
|
this.setState({ height: scrollHeight + offset }); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
handleInput = () => { |
|
|
|
|
handleInput = (): void => { |
|
|
|
|
this.setValue(this.exprInputRef.current!.value); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
setValue = (value: string) => { |
|
|
|
|
setValue = (value: string): void => { |
|
|
|
|
const { onExpressionChange } = this.props; |
|
|
|
|
onExpressionChange(value); |
|
|
|
|
this.setState({ height: 'auto' }, this.setHeight); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps: ExpressionInputProps) { |
|
|
|
|
componentDidUpdate(prevProps: ExpressionInputProps): void { |
|
|
|
|
const { value } = this.props; |
|
|
|
|
if (value !== prevProps.value) { |
|
|
|
|
this.setValue(value); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
handleKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => { |
|
|
|
|
handleKeyPress = (event: React.KeyboardEvent<HTMLInputElement>): void => { |
|
|
|
|
const { executeQuery } = this.props; |
|
|
|
|
if (event.key === 'Enter' && !event.shiftKey) { |
|
|
|
|
executeQuery(); |
|
|
|
|
@ -72,7 +72,7 @@ class ExpressionInput extends Component<ExpressionInputProps, ExpressionInputSta |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
getSearchMatches = (input: string, expressions: string[]) => { |
|
|
|
|
getSearchMatches = (input: string, expressions: string[]): FuzzyResult[] => { |
|
|
|
|
return fuz.filter(input.replace(/ /g, ''), expressions); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
@ -84,9 +84,9 @@ class ExpressionInput extends Component<ExpressionInputProps, ExpressionInputSta |
|
|
|
|
}; |
|
|
|
|
let index = 0; |
|
|
|
|
const sections = |
|
|
|
|
inputValue!.length && this.props.enableAutocomplete |
|
|
|
|
inputValue?.length && this.props.enableAutocomplete |
|
|
|
|
? Object.entries(autocompleteSections).reduce((acc, [title, items]) => { |
|
|
|
|
const matches = this.getSearchMatches(inputValue!, items); |
|
|
|
|
const matches = this.getSearchMatches(inputValue, items); |
|
|
|
|
return !matches.length |
|
|
|
|
? acc |
|
|
|
|
: [ |
|
|
|
|
@ -131,19 +131,19 @@ class ExpressionInput extends Component<ExpressionInputProps, ExpressionInputSta |
|
|
|
|
); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
openMetricsExplorer = () => { |
|
|
|
|
openMetricsExplorer = (): void => { |
|
|
|
|
this.setState({ |
|
|
|
|
showMetricsExplorer: true, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
updateShowMetricsExplorer = (show: boolean) => { |
|
|
|
|
updateShowMetricsExplorer = (show: boolean): void => { |
|
|
|
|
this.setState({ |
|
|
|
|
showMetricsExplorer: show, |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
insertAtCursor = (value: string) => { |
|
|
|
|
insertAtCursor = (value: string): void => { |
|
|
|
|
if (!this.exprInputRef.current) return; |
|
|
|
|
|
|
|
|
|
const startPosition = this.exprInputRef.current.selectionStart; |
|
|
|
|
|