Skip to content

Commit

Permalink
Show changed vs different results
Browse files Browse the repository at this point in the history
  • Loading branch information
nai888 committed Dec 31, 2018
1 parent ec7daa1 commit 05a6e78
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
22 changes: 16 additions & 6 deletions src/routes/Morph/MorphResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ const MorphResults = props => {
}
}

// Assign the changed class if the result is different from last run
// Assign the 'different' and 'changed' classes appropriately
const classes = result => {
return result.changed && props.showDiff
? classNames(styles.outText, styles.changed)
: styles.outText
if (props.showDiff && result.diff) {
if (result.input !== result.output) {
return classNames(styles.outText, styles.different, styles.changed)
} else {
return classNames(styles.outText, styles.different)
}
} else {
if (result.input !== result.output) {
return classNames(styles.outText, styles.changed)
} else {
return styles.outText
}
}
}

// Return the results text
Expand All @@ -57,7 +67,7 @@ const MorphResults = props => {
if (resultsArr[i].input === resultsArr[i].output) {
unchangedWords++
}
if (resultsArr[i].changed) {
if (resultsArr[i].diff) {
differentWords++
}
}
Expand Down Expand Up @@ -100,7 +110,7 @@ MorphResults.propTypes = {
PropTypes.shape({
input: PropTypes.string.isRequired,
output: PropTypes.string.isRequired,
changed: PropTypes.bool.isRequired
diff: PropTypes.bool.isRequired
})
).isRequired,
PropTypes.arrayOf(PropTypes.string.isRequired).isRequired
Expand Down
10 changes: 5 additions & 5 deletions src/routes/Morph/MorphService.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class MorphService {
this.rewriteLex = this.rewriteLex.bind(this)
this.unrewriteLex = this.unrewriteLex.bind(this)
this.applyChanges = this.applyChanges.bind(this)
this.idChanged = this.idChanged.bind(this)
this.idDiff = this.idDiff.bind(this)
this.morph = this.morph.bind(this)
}

Expand Down Expand Up @@ -320,7 +320,7 @@ class MorphService {
return rwOutput ? this.unrewriteLex(results, rules) : results
}

idChanged (data, results) {
idDiff (data, results) {
const newResults = JSON.parse(JSON.stringify(results))

if (
Expand All @@ -329,13 +329,13 @@ class MorphService {
typeof data.results[0] !== 'string'
) {
for (let i = 0; i < newResults.length; i++) {
newResults[i].changed =
newResults[i].diff =
newResults[i].input !== data.results[i].input &&
newResults[i].output !== data.results[i].output
}
} else {
for (let i = 0; i < newResults.length; i++) {
newResults[i].changed = true
newResults[i].diff = true
}
}

Expand Down Expand Up @@ -372,7 +372,7 @@ class MorphService {
newData.rewriteOutput
)

return this.idChanged(newData, results)
return this.idDiff(newData, results)
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/routes/Morph/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ const styles = {
marginBottom: 0
}
},
changed: {
different: {
fontWeight: 'bold'
},
changed: {
fontStyle: 'italic'
}
}

Expand Down

0 comments on commit 05a6e78

Please sign in to comment.