output error message for sound change suite
This commit is contained in:
parent
efae25583c
commit
946f1cb930
3 changed files with 19 additions and 6 deletions
|
@ -15,11 +15,12 @@ const PhonoChangeApplier = () => {
|
||||||
const [ epochs, setEpochs ] = useState([{name: 'epoch 1', changes:['[+ feature]>[- feature]/_#']}]);
|
const [ epochs, setEpochs ] = useState([{name: 'epoch 1', changes:['[+ feature]>[- feature]/_#']}]);
|
||||||
const [ options, setOptions ] = useState({output: 'default', save: false})
|
const [ options, setOptions ] = useState({output: 'default', save: false})
|
||||||
const [ results, setResults ] = useState([])
|
const [ results, setResults ] = useState([])
|
||||||
|
const [ errors, setErrors ] = useState({})
|
||||||
|
|
||||||
const runChanges = e => {
|
const runChanges = e => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
// validate rules
|
|
||||||
let error = epochs.reduce((errorObject, epoch) => {
|
let ruleError = epochs.reduce((errorObject, epoch) => {
|
||||||
epoch.changes.map((change, index) => {
|
epoch.changes.map((change, index) => {
|
||||||
if (!change.match(/>.*\/.*_/)) errorObject[epoch.name]
|
if (!change.match(/>.*\/.*_/)) errorObject[epoch.name]
|
||||||
? errorObject[epoch.name].push(index)
|
? errorObject[epoch.name].push(index)
|
||||||
|
@ -27,16 +28,18 @@ const PhonoChangeApplier = () => {
|
||||||
})
|
})
|
||||||
return errorObject;
|
return errorObject;
|
||||||
}, {})
|
}, {})
|
||||||
console.log(error)
|
|
||||||
// validate lexicon
|
|
||||||
|
|
||||||
|
if (Object.entries(ruleError).length) return setErrors(ruleError)
|
||||||
|
setErrors({});
|
||||||
|
|
||||||
|
// setResults
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="PhonoChangeApplier" data-testid="PhonoChangeApplier">
|
<div className="PhonoChangeApplier" data-testid="PhonoChangeApplier">
|
||||||
<ProtoLang lexicon={lexicon} setLexicon={setLexicon}/>
|
<ProtoLang lexicon={lexicon} setLexicon={setLexicon}/>
|
||||||
<Features phonemes={phonemes} setPhonemes={setPhonemes}/>
|
<Features phonemes={phonemes} setPhonemes={setPhonemes}/>
|
||||||
<Epochs epochs={epochs} setEpochs={setEpochs}/>
|
<Epochs epochs={epochs} setEpochs={setEpochs} errors={errors}/>
|
||||||
<Options options={options} setOptions={setOptions} runChanges={runChanges}/>
|
<Options options={options} setOptions={setOptions} runChanges={runChanges}/>
|
||||||
<Output results={results} setResults={setResults}/>
|
<Output results={results} setResults={setResults}/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -28,7 +28,14 @@ const Epochs = props => {
|
||||||
return (
|
return (
|
||||||
<div className="Epochs" data-testid="Epochs">
|
<div className="Epochs" data-testid="Epochs">
|
||||||
<h3>Sound Change Epochs</h3>
|
<h3>Sound Change Epochs</h3>
|
||||||
{props.epochs ? props.epochs.map((epoch, idx) => <SoundChangeSuite key={`epochname-${idx}`} epochIndex={idx} epoch={epoch} updateEpoch={updateEpoch} removeEpoch={removeEpoch}/>) : <></>}
|
{props.epochs
|
||||||
|
? props.epochs.map((epoch, idx) => {
|
||||||
|
return <SoundChangeSuite
|
||||||
|
key={`epochname-${idx}`} epochIndex={idx} epoch={epoch}
|
||||||
|
updateEpoch={updateEpoch} removeEpoch={removeEpoch}
|
||||||
|
error={props.errors[epoch.name]}
|
||||||
|
/>})
|
||||||
|
: <></>}
|
||||||
<form onSubmit={e=>addEpoch(e, props)}>
|
<form onSubmit={e=>addEpoch(e, props)}>
|
||||||
<input type="submit" name="add-epoch" value="Add Epoch" ></input>
|
<input type="submit" name="add-epoch" value="Add Epoch" ></input>
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -23,6 +23,9 @@ const SoundChangeSuite = props => {
|
||||||
)}
|
)}
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|
||||||
|
{props.error
|
||||||
|
? <p><span className="error-message">{`Formatting errors in line(s) ${props.error.join(', ')}`}</span></p>
|
||||||
|
: <></>}
|
||||||
<textarea
|
<textarea
|
||||||
name="changes"
|
name="changes"
|
||||||
id="" cols="30" rows="10"
|
id="" cols="30" rows="10"
|
||||||
|
|
Loading…
Reference in a new issue