-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OCLOMRS-173: Changes to create concept form options for Q-and-A conce…
…pt (#133)
- Loading branch information
Showing
20 changed files
with
490 additions
and
17 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
src/components/dictionaryConcepts/components/AnswersRow.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import React, { Component } from 'react'; | ||
import autoBind from 'react-autobind'; | ||
import PropTypes from 'prop-types'; | ||
|
||
class AnswersRow extends Component { | ||
static propTypes = { | ||
newRow: PropTypes.object.isRequired, | ||
addDataFromAnswer: PropTypes.func.isRequired, | ||
removeAnswer: PropTypes.func.isRequired, | ||
removeDataFromRow: PropTypes.func.isRequired, | ||
existingConcept: PropTypes.object.isRequired, | ||
} | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
id: this.props.newRow.uuid, | ||
answer: [], | ||
}; | ||
autoBind(this); | ||
} | ||
|
||
componentDidMount() { | ||
if (this.props.existingConcept) { | ||
this.updateState(); | ||
} | ||
} | ||
|
||
componentDidUpdate(prevProps, prevState) { | ||
if (prevState !== this.state) { | ||
this.sendToTopComponent(); | ||
} | ||
} | ||
|
||
updateState() { | ||
const { newRow } = this.props; | ||
this.setState({ | ||
...this.state, | ||
id: newRow.uuid, | ||
answer: newRow.answer || '', | ||
}); | ||
} | ||
|
||
handleChange(event) { | ||
const { | ||
target: { value, name }, | ||
} = event; | ||
this.setState(() => ({ [name]: value })); | ||
this.sendToTopComponent(); | ||
} | ||
|
||
sendToTopComponent() { | ||
this.props.addDataFromAnswer(this.state); | ||
} | ||
|
||
handleRemove(event, id) { | ||
event.preventDefault(); | ||
const { removeAnswer, removeDataFromRow } = this.props; | ||
removeAnswer(id); | ||
removeDataFromRow(id, 'answers'); | ||
} | ||
|
||
render() { | ||
return ( | ||
<tr> | ||
<td> | ||
<input | ||
type="text" | ||
className="form-control answer" | ||
placeholder="eg. /orgs/Regenstrief/sources/loinc2/concepts/32700-7/" | ||
name="answer" | ||
value={this.state.answer} | ||
onChange={this.handleChange} | ||
id="concept-answer" | ||
required | ||
/> | ||
</td> | ||
<td> | ||
<a | ||
href="#!" | ||
className="concept-form-table-link answer" | ||
id="remove-answer" | ||
onClick={event => this.handleRemove(event, this.props.newRow.uuid)} | ||
> | ||
remove | ||
</a> | ||
</td> | ||
</tr> | ||
); | ||
} | ||
} | ||
|
||
export default AnswersRow; |
28 changes: 28 additions & 0 deletions
28
src/components/dictionaryConcepts/components/AnswersTable.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import AnswersRow from './AnswersRow'; | ||
|
||
const AnswersTable = props => ( | ||
<table className="table table-striped table-bordered concept-form-table"> | ||
<thead className="header text-white"> | ||
<tr> | ||
<th scope="col">To Concept URL</th> | ||
<th scope="col">Actions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{props.answer.map(newRow => ( | ||
<AnswersRow | ||
newRow={{ uuid: newRow }} | ||
key={newRow} | ||
{...props} | ||
/>))} | ||
</tbody> | ||
</table> | ||
); | ||
|
||
AnswersTable.propTypes = { | ||
answer: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default AnswersTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/components/dictionaryConcepts/components/DescriptionRow.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.