Skip to content

Commit

Permalink
Print errors if any
Browse files Browse the repository at this point in the history
  • Loading branch information
nai888 committed Dec 31, 2018
1 parent 573c562 commit c8bb2a5
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
35 changes: 25 additions & 10 deletions src/routes/Morph/MorphResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ const MorphResults = props => {
let resultsArr = props.results || []

const outputText = styles => {
// If there were errors, print them
if (typeof resultsArr[0] === 'string') {
return resultsArr.map((error, i) => (
<p className={classNames(styles.outText, props.classes.error)} key={i}>
{error}
</p>
))
}

// Format the results according to the selected option
const format = result => {
if (props.outputFormat === 'oo') {
return result.output.trim()
Expand All @@ -20,20 +30,22 @@ const MorphResults = props => {
}
}

// Assign the changed class if the result is different from last run
const classes = result => {
return result.changed && props.showDiff
? classNames(props.styles.outText, props.styles.changed)
: props.styles.outText
? classNames(styles.outText, styles.changed)
: styles.outText
}

// Return the results text
return resultsArr.length > 0 ? (
resultsArr.map((result, i) => (
<p className={classes(result)} key={i}>
{format(result)}
</p>
))
) : (
<p className={props.styles.outText} />
<p className={styles.outText} />
)
}

Expand Down Expand Up @@ -83,13 +95,16 @@ MorphResults.propTypes = {
classes: PropTypes.object,
styles: PropTypes.object,
outputFormat: PropTypes.string.isRequired,
results: PropTypes.arrayOf(
PropTypes.shape({
input: PropTypes.string.isRequired,
output: PropTypes.string.isRequired,
changed: PropTypes.bool.isRequired
})
),
results: PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.shape({
input: PropTypes.string.isRequired,
output: PropTypes.string.isRequired,
changed: PropTypes.bool.isRequired
})
).isRequired,
PropTypes.arrayOf(PropTypes.string.isRequired).isRequired
]),
showDiff: PropTypes.bool.isRequired
}

Expand Down
12 changes: 9 additions & 3 deletions src/routes/Morph/MorphService.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,15 @@ class MorphService {
const categories = this.splitCategories(newData.categories)
const rewriteRules = this.splitRewriteRules(newData.rewriteRules)
const soundChanges = this.splitSoundChanges(newData.soundChanges)
console.log(categories)
console.log(rewriteRules)
console.log(soundChanges)

let allErrors = []
if (typeof categories[0] === 'string')
allErrors = allErrors.concat(categories)
if (typeof rewriteRules[0] === 'string')
allErrors = allErrors.concat(rewriteRules)
if (typeof soundChanges[0] === 'string')
allErrors = allErrors.concat(soundChanges)
if (allErrors.length) return allErrors

let results = [
{
Expand Down

0 comments on commit c8bb2a5

Please sign in to comment.