import { encodeRuleName } from 'Engine/rules.js'
import Fuse from 'fuse.js'
import PropTypes from 'prop-types'
import { pick } from 'ramda'
import React from 'react'
import Highlighter from 'react-highlight-words'
import { withI18n } from 'react-i18next'
import { Link, Redirect } from 'react-router-dom'
import Select from 'react-select'
import 'react-select/dist/react-select.css'
import { capitalise0 } from '../utils'
class SearchBar extends React.Component {
static contextTypes = {
i18n: PropTypes.object.isRequired
}
componentDidMount() {
this.inputElement.focus()
}
UNSAFE_componentWillMount() {
let { rules } = this.props
var options = {
keys: [
{
name: 'name',
weight: 0.3
},
{
name: 'title',
weight: 0.3
},
{
name: 'espace',
weight: 0.2
},
{
name: 'description',
weight: 0.2
}
]
}
this.fuse = new Fuse(
rules.map(pick(['title', 'espace', 'description', 'name', 'dottedName'])),
options
)
}
state = {
selectedOption: null,
inputValue: null
}
handleChange = selectedOption => {
this.setState({ selectedOption })
}
renderOption = ({ title, dottedName }) => (
)
filterOptions = (options, filter) => this.fuse.search(filter)
render() {
let { rules } = this.props,
{ i18n } = this.context,
{ selectedOption } = this.state
if (selectedOption != null) {
this.props.finally && this.props.finally()
return (
)
}
return (
<>