| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { useContext, WPElement } from '@wordpress/element'; |
| 5 |
|
| 6 |
/** |
| 7 |
* Internal dependencies. |
| 8 |
*/ |
| 9 |
import { State, Dispatch } from '../../context'; |
| 10 |
|
| 11 |
/** |
| 12 |
* Synonym Inspector |
| 13 |
* |
| 14 |
* @returns {WPElement} SolrEditor Component |
| 15 |
*/ |
| 16 |
const SolrEditor = () => { |
| 17 |
const state = useContext(State); |
| 18 |
const dispatch = useContext(Dispatch); |
| 19 |
const { alternatives, isSolrEditable, isSolrVisible, sets, solr } = state; |
| 20 |
const { |
| 21 |
synonymsTextareaInputName, |
| 22 |
solrInputHeading, |
| 23 |
solrAlternativesErrorMessage, |
| 24 |
solrSetsErrorMessage, |
| 25 |
} = window.epSynonyms.i18n; |
| 26 |
|
| 27 |
return ( |
| 28 |
<div className={`synonym-solr-editor metabox-holder ${!isSolrVisible ? 'hidden' : ''}`}> |
| 29 |
<div className="postbox"> |
| 30 |
<h2 className="hndle"> |
| 31 |
<span>{solrInputHeading}</span> |
| 32 |
</h2> |
| 33 |
<div className="inside"> |
| 34 |
<textarea |
| 35 |
className="large-text" |
| 36 |
id="ep-synonym-input" |
| 37 |
name={synonymsTextareaInputName} |
| 38 |
rows="20" |
| 39 |
value={solr} |
| 40 |
readOnly={!isSolrEditable} |
| 41 |
onChange={(event) => |
| 42 |
dispatch({ type: 'UPDATE_SOLR', data: event.target.value }) |
| 43 |
} |
| 44 |
/> |
| 45 |
<div |
| 46 |
role="region" |
| 47 |
aria-live="assertive" |
| 48 |
className="synonym-solr-editor__validation" |
| 49 |
> |
| 50 |
{alternatives.some((alternative) => !alternative.valid) && ( |
| 51 |
<p>{solrAlternativesErrorMessage}</p> |
| 52 |
)} |
| 53 |
{sets.some((set) => !set.valid) && <p>{solrSetsErrorMessage}</p>} |
| 54 |
</div> |
| 55 |
</div> |
| 56 |
</div> |
| 57 |
</div> |
| 58 |
); |
| 59 |
}; |
| 60 |
|
| 61 |
export default SolrEditor; |
| 62 |
|