Files
ohif-viewer/platform/viewer/src/components/EditDescriptionDialog/EditDescriptionDialog.js
T

83 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-05-29 08:39:54 -04:00
import { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import SimpleDialog from '../SimpleDialog/SimpleDialog.js';
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
import bounding from '../../lib/utils/bounding.js';
import { getDialogStyle } from './../Labelling/labellingPositionUtils.js';
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
import './EditDescriptionDialog.css';
2019-05-02 17:12:06 -04:00
export default class EditDescriptionDialog extends Component {
static defaultProps = {
componentRef: React.createRef(),
componentStyle: {},
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
static propTypes = {
measurementData: PropTypes.object.isRequired,
onCancel: PropTypes.func.isRequired,
componentRef: PropTypes.object,
componentStyle: PropTypes.object,
onUpdate: PropTypes.func.isRequired,
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
constructor(props) {
2019-05-29 08:39:54 -04:00
super(props);
2019-05-02 17:12:06 -04:00
this.state = {
description: props.measurementData.description || '',
2019-05-29 08:39:54 -04:00
};
2019-05-02 17:12:06 -04:00
2019-05-29 08:39:54 -04:00
this.mainElement = React.createRef();
2019-05-02 17:12:06 -04:00
}
componentDidMount = () => {
2019-05-29 08:39:54 -04:00
bounding(this.mainElement);
};
2019-05-02 17:12:06 -04:00
componentDidUpdate(prevProps) {
if (this.props.description !== prevProps.description) {
this.setState({
description: this.props.description,
2019-05-29 08:39:54 -04:00
});
2019-05-02 17:12:06 -04:00
}
}
render() {
2019-05-29 08:39:54 -04:00
const style = getDialogStyle(this.props.componentStyle);
2019-05-02 17:12:06 -04:00
return (
<SimpleDialog
headerTitle="Edit Description"
onClose={this.onClose}
onConfirm={this.onConfirm}
rootClass="editDescriptionDialog"
componentRef={this.mainElement}
componentStyle={style}
>
<input
value={this.state.description}
className="simpleDialogInput"
id="description"
autoComplete="off"
autoFocus
onChange={this.handleChange}
/>
</SimpleDialog>
2019-05-29 08:39:54 -04:00
);
2019-05-02 17:12:06 -04:00
}
onClose = () => {
2019-05-29 08:39:54 -04:00
this.props.onCancel();
};
2019-05-02 17:12:06 -04:00
onConfirm = e => {
e.preventDefault();
2019-05-29 08:39:54 -04:00
this.props.onUpdate(this.state.description);
};
2019-05-02 17:12:06 -04:00
handleChange = event => {
2019-05-29 08:39:54 -04:00
this.setState({ description: event.target.value });
};
2019-05-02 17:12:06 -04:00
}