refactor Output component to display multiple results

This commit is contained in:
Sorrel Bri 2020-02-21 20:21:06 -08:00
parent 745fd3b899
commit 6f55f0ac39
3 changed files with 30 additions and 4 deletions

View file

@ -102,7 +102,7 @@ const PhonoChangeApplier = () => {
<Features phones={phones} features={features} dispatch={dispatch}/> <Features phones={phones} features={features} dispatch={dispatch}/>
<Epochs epochs={epochs} dispatch={dispatch} /> <Epochs epochs={epochs} dispatch={dispatch} />
<Options options={options} dispatch={dispatch}/> <Options options={options} dispatch={dispatch}/>
<Output results={results} dispatch={dispatch}/> <Output results={results} options={options} dispatch={dispatch}/>
</div> </div>
); );
} }

View file

@ -2,13 +2,33 @@ import React from 'react';
import './Output.scss'; import './Output.scss';
const Output = props => { const Output = props => {
const { results } = props; const { results, options } = props;
const renderResults = () => {
switch(options.output) {
case 'default':
return renderDefault();
default:
return <></>
}
}
const renderDefault = () => {
return results.map((epoch, i) => {
const lexicon = epoch.lexicon.map(lexeme => <span>{lexeme}</span>);
return (
<div key={`epoch-${i}`} className="Output-epoch">
<h5>{epoch.pass}</h5>
<p className="lexicon">{lexicon}</p>
</div>
)
})
}
return ( return (
<div className="Output" data-testid="Output"> <div className="Output" data-testid="Output">
<h3>Results of Run</h3> <h3>Results of Run</h3>
<div data-testid="Output-lexicon"> <div data-testid="Output-lexicon" className="Output_container">
{results && results.length ? results[0].lexicon.map((lexicalItem, i) => <p key={`output-lexical-item-${i}`}>{lexicalItem}</p>) : <></>} {results && results.length ? renderResults() : <></>}
</div> </div>
</div> </div>
); );

View file

@ -0,0 +1,6 @@
div.Output-epoch {
display: flex;
p.lexicon {
display: flex;
}
}