import React, { Component, ChangeEvent } from 'react'; import { Modal, ModalBody, ModalHeader, Input } from 'reactstrap'; import { Fuzzy, FuzzyResult } from '@nexucis/fuzzy'; const fuz = new Fuzzy({ pre: '', post: '', shouldSort: true }); interface MetricsExplorerProps { show: boolean; updateShow(show: boolean): void; metrics: string[]; insertAtCursor(value: string): void; } type MetricsExplorerState = { searchTerm: string; }; class MetricsExplorer extends Component { constructor(props: MetricsExplorerProps) { super(props); this.state = { searchTerm: '' }; } handleSearchTerm = (event: ChangeEvent): void => { this.setState({ searchTerm: event.target.value }); }; handleMetricClick = (query: string): void => { this.props.insertAtCursor(query); this.props.updateShow(false); this.setState({ searchTerm: '' }); }; toggle = (): void => { this.props.updateShow(!this.props.show); }; render(): JSX.Element { return ( Metrics Explorer {this.state.searchTerm.length > 0 && fuz .filter(this.state.searchTerm, this.props.metrics) .map((result: FuzzyResult) => (

))} {this.state.searchTerm.length === 0 && this.props.metrics.map((metric) => (

{metric}

))}
); } } export default MetricsExplorer;