Skip to content

Commit

Permalink
OCLOMRS-453: Fix inability to create more than one Name or Descriptio…
Browse files Browse the repository at this point in the history
…n while Creating and Editing Concepts
  • Loading branch information
Bruce Allan Makaaru authored and Bruce Allan Makaaru committed Mar 6, 2019
1 parent 633a479 commit ddd85d5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
23 changes: 10 additions & 13 deletions src/components/dictionaryConcepts/components/ConceptNameRows.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class ConceptNameRows extends Component {
removeDataFromRow: PropTypes.func.isRequired,
pathName: PropTypes.object.isRequired,
existingConcept: PropTypes.object.isRequired,
rowId: PropTypes.string,
};

static defaultProps = {
Expand All @@ -28,15 +29,17 @@ class ConceptNameRows extends Component {
},
index: 0,
nameRows: [],
rowId: '',
};

constructor(props) {
super(props);
const defaultLocale = locale.find(
currentLocale => currentLocale.value === props.pathName.language,
);
const { rowId } = this.props;
this.state = {
id: this.props.newRow.id,
id: rowId,
name: '',
locale: defaultLocale.value,
locale_full: defaultLocale,
Expand All @@ -62,12 +65,12 @@ class ConceptNameRows extends Component {
const { newRow } = this.props;
const defaultLocale = locale.find(
currentLocale => currentLocale.value === newRow.locale,
);
) || locale[0];
this.setState({
...this.state,
uuid: newRow.uuid || '',
name: newRow.name || '',
locale: newRow.locale || defaultLocale,
locale: newRow.locale || defaultLocale.value,
locale_full: defaultLocale,
name_type: newRow.name_type || 'Fully Specified',
locale_preferred: newRow.locale_preferred || 'Yes',
Expand Down Expand Up @@ -98,21 +101,15 @@ class ConceptNameRows extends Component {

handleRemove(event, id) {
const {
nameRows,
index,
removeRow,
removeDataFromRow,
} = this.props;
if (!id) {
removeRow(event, nameRows[index]);
removeDataFromRow(nameRows[index], 'names');
} else {
removeRow(event, id);
removeDataFromRow(id, 'names');
}
removeRow(event, id);
removeDataFromRow({ uuid: id }, 'names');
}

render() {
const { rowId } = this.props;
return (
<tr>
<td>
Expand Down Expand Up @@ -169,7 +166,7 @@ class ConceptNameRows extends Component {
className="btn btn-danger concept-form-table-link"
id="remove-name"
type="button"
onClick={event => this.handleRemove(event, this.props.newRow.uuid)}
onClick={event => this.handleRemove(event, rowId)}
>
remove
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ const CreateConceptTable = props => (
<tbody>
{props.existingConcept && props.existingConcept.names
? props.existingConcept.names.map(newRow => (
<ConceptNameRows newRow={newRow} key={newRow.uuid} {...props} />
<ConceptNameRows newRow={newRow} rowId={newRow.uuid} key={newRow.uuid} {...props} />
))
: props.nameRows.map((newRow, index) => (
<ConceptNameRows key={newRow} index={index} {...props} />
<ConceptNameRows key={newRow} rowId={newRow} index={index} {...props} />
))}
</tbody>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import locale from '../../dashboard/components/dictionary/common/Languages';

class DescriptionRow extends Component {
static propTypes = {
rowId: PropTypes.string,
newRow: PropTypes.object,
newRowUuid: PropTypes.string,
addDataFromDescription: PropTypes.func.isRequired,
Expand All @@ -27,15 +28,17 @@ class DescriptionRow extends Component {
name_type: '',
},
newRowUuid: '',
rowId: '',
};

constructor(props) {
super(props);
const defaultLocale = locale.find(
currentLocale => currentLocale.value === props.pathName.language,
);
const { rowId } = this.props;
this.state = {
id: this.props.newRow,
id: rowId,
locale: defaultLocale.value,
locale_full: defaultLocale,
description: '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ const DescriptionTable = props => (
? props.existingConcept.descriptions.map(newRow => (
<DescriptionRow
newRow={newRow}
rowId={newRow.uuid}
key={newRow.uuid}
{...props}
/>
))
: props.description.map(newRow => (
<DescriptionRow
newRowUuid={newRow}
rowId={newRow}
key={newRow}
{...props}
/>))
Expand Down

0 comments on commit ddd85d5

Please sign in to comment.