Cleanup LabellingFlow and LabellingManager components
This commit is contained in:
parent
29bac8df7a
commit
3bdd434488
@ -5,27 +5,14 @@ import cloneDeep from 'lodash.clonedeep';
|
|||||||
|
|
||||||
import LabellingTransition from './LabellingTransition.js';
|
import LabellingTransition from './LabellingTransition.js';
|
||||||
import OHIFLabellingData from './OHIFLabellingData.js';
|
import OHIFLabellingData from './OHIFLabellingData.js';
|
||||||
|
import './LabellingManager.css';
|
||||||
|
|
||||||
export default class LabellingFlow extends Component {
|
class LabellingFlow extends Component {
|
||||||
static propTypes = {
|
|
||||||
measurementData: PropTypes.object.isRequired,
|
|
||||||
labellingDoneCallback: PropTypes.func.isRequired,
|
|
||||||
updateLabelling: PropTypes.func.isRequired,
|
|
||||||
initialTopDistance: PropTypes.number,
|
|
||||||
skipAddLabelButton: PropTypes.bool,
|
|
||||||
editLocation: PropTypes.bool,
|
|
||||||
editDescription: PropTypes.bool,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const { location, locationLabel, description } = props.measurementData;
|
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
location,
|
measurementData: props.measurementData,
|
||||||
locationLabel,
|
|
||||||
description,
|
|
||||||
skipAddLabelButton: props.skipAddLabelButton,
|
skipAddLabelButton: props.skipAddLabelButton,
|
||||||
editDescription: props.editDescription,
|
editDescription: props.editDescription,
|
||||||
editLocation: props.editLocation,
|
editLocation: props.editLocation,
|
||||||
@ -33,7 +20,6 @@ export default class LabellingFlow extends Component {
|
|||||||
displayComponent: true,
|
displayComponent: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.mainElement = React.createRef();
|
|
||||||
this.descriptionInput = React.createRef();
|
this.descriptionInput = React.createRef();
|
||||||
this.initialItems = OHIFLabellingData;
|
this.initialItems = OHIFLabellingData;
|
||||||
this.currentItems = cloneDeep(this.initialItems);
|
this.currentItems = cloneDeep(this.initialItems);
|
||||||
@ -46,11 +32,6 @@ export default class LabellingFlow extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
let mainElementClassName = 'labellingComponent';
|
|
||||||
if (this.state.editDescription) {
|
|
||||||
mainElementClassName += ' editDescription';
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LabellingTransition
|
<LabellingTransition
|
||||||
displayComponent={this.state.displayComponent}
|
displayComponent={this.state.displayComponent}
|
||||||
@ -58,8 +39,8 @@ export default class LabellingFlow extends Component {
|
|||||||
>
|
>
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
className={mainElementClassName}
|
className={`labellingComponent ${this.state.editDescription &&
|
||||||
ref={this.mainElement}
|
'editDescription'}`}
|
||||||
onMouseLeave={this.fadeOutAndLeave}
|
onMouseLeave={this.fadeOutAndLeave}
|
||||||
onMouseEnter={this.clearFadeOutTimer}
|
onMouseEnter={this.clearFadeOutTimer}
|
||||||
>
|
>
|
||||||
@ -71,12 +52,8 @@ export default class LabellingFlow extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
labellingStateFragment = () => {
|
labellingStateFragment = () => {
|
||||||
const {
|
const { skipAddLabelButton, editLocation, measurementData } = this.state;
|
||||||
skipAddLabelButton,
|
const { description, locationLabel, location } = measurementData;
|
||||||
editLocation,
|
|
||||||
description,
|
|
||||||
locationLabel,
|
|
||||||
} = this.state;
|
|
||||||
|
|
||||||
if (!skipAddLabelButton) {
|
if (!skipAddLabelButton) {
|
||||||
return (
|
return (
|
||||||
@ -86,7 +63,7 @@ export default class LabellingFlow extends Component {
|
|||||||
className="addLabelButton"
|
className="addLabelButton"
|
||||||
onClick={this.showLabelling}
|
onClick={this.showLabelling}
|
||||||
>
|
>
|
||||||
{this.state.location ? 'Edit' : 'Add'} Label
|
{location ? 'Edit' : 'Add'} Label
|
||||||
</button>
|
</button>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
@ -191,21 +168,24 @@ export default class LabellingFlow extends Component {
|
|||||||
|
|
||||||
selectTreeSelectCallback = (event, itemSelected) => {
|
selectTreeSelectCallback = (event, itemSelected) => {
|
||||||
const location = itemSelected.value;
|
const location = itemSelected.value;
|
||||||
|
const locationLabel = itemSelected.label;
|
||||||
this.props.updateLabelling({ location });
|
this.props.updateLabelling({ location });
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
editLocation: false,
|
editLocation: false,
|
||||||
confirmationState: true,
|
confirmationState: true,
|
||||||
location: itemSelected.value,
|
measurementData: {
|
||||||
locationLabel: itemSelected.label,
|
...this.state.measurementData,
|
||||||
|
location,
|
||||||
|
locationLabel,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.isTouchScreen) {
|
if (this.isTouchScreen) {
|
||||||
this.setTimeout = setTimeout(() => {
|
this.setTimeout = setTimeout(
|
||||||
this.setState({
|
() => this.setState({ displayComponent: false }),
|
||||||
displayComponent: false,
|
2000
|
||||||
});
|
);
|
||||||
}, 2000);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -234,3 +214,23 @@ export default class LabellingFlow extends Component {
|
|||||||
clearTimeout(this.fadeOutTimer);
|
clearTimeout(this.fadeOutTimer);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LabellingFlow.propTypes = {
|
||||||
|
measurementData: PropTypes.object.isRequired,
|
||||||
|
labellingDoneCallback: PropTypes.func.isRequired,
|
||||||
|
updateLabelling: PropTypes.func.isRequired,
|
||||||
|
initialTopDistance: PropTypes.number,
|
||||||
|
skipAddLabelButton: PropTypes.bool,
|
||||||
|
editLocation: PropTypes.bool,
|
||||||
|
editDescription: PropTypes.bool,
|
||||||
|
editDescriptionOnDialog: PropTypes.bool,
|
||||||
|
};
|
||||||
|
|
||||||
|
LabellingFlow.defaultProps = {
|
||||||
|
skipAddLabelButton: false,
|
||||||
|
editLocation: false,
|
||||||
|
editDescription: false,
|
||||||
|
editDescriptionOnDialog: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default LabellingFlow;
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import cloneDeep from 'lodash.clonedeep';
|
import cloneDeep from 'lodash.clonedeep';
|
||||||
|
|
||||||
import EditDescriptionDialog from './../EditDescriptionDialog/EditDescriptionDialog.js';
|
import EditDescriptionDialog from './../EditDescriptionDialog/EditDescriptionDialog.js';
|
||||||
@ -7,64 +6,27 @@ import LabellingFlow from './LabellingFlow.js';
|
|||||||
import './LabellingManager.css';
|
import './LabellingManager.css';
|
||||||
|
|
||||||
export default class LabellingManager extends Component {
|
export default class LabellingManager extends Component {
|
||||||
static propTypes = {
|
|
||||||
measurementData: PropTypes.object.isRequired,
|
|
||||||
labellingDoneCallback: PropTypes.func.isRequired,
|
|
||||||
updateLabelling: PropTypes.func.isRequired,
|
|
||||||
skipAddLabelButton: PropTypes.bool,
|
|
||||||
editLocation: PropTypes.bool,
|
|
||||||
editDescription: PropTypes.bool,
|
|
||||||
editDescriptionOnDialog: PropTypes.bool,
|
|
||||||
};
|
|
||||||
|
|
||||||
static defaultProps = {
|
|
||||||
skipAddLabelButton: false,
|
|
||||||
editLocation: false,
|
|
||||||
editDescription: false,
|
|
||||||
editDescriptionOnDialog: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
const measurementData = cloneDeep(props.measurementData);
|
const newMeasurementData = cloneDeep(props.measurementData);
|
||||||
this.treatMeasurementData(measurementData);
|
this.treatMeasurementData(newMeasurementData);
|
||||||
|
|
||||||
let editLocation = props.editLocation;
|
let newEditLocation = props.editLocation;
|
||||||
if (!props.editDescription && !props.editLocation) {
|
if (!props.editDescription && !props.editLocation) {
|
||||||
editLocation = true;
|
newEditLocation = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
skipAddLabelButton: props.skipAddLabelButton,
|
editLocation: newEditLocation,
|
||||||
editLocation: editLocation,
|
measurementData: newMeasurementData,
|
||||||
editDescription: props.editDescription,
|
|
||||||
editDescriptionOnDialog: props.editDescriptionOnDialog,
|
|
||||||
measurementData: measurementData,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount = () => {
|
|
||||||
document.addEventListener('touchstart', this.onTouchStart);
|
|
||||||
};
|
|
||||||
|
|
||||||
componentWillUnmount = () => {
|
|
||||||
document.removeEventListener('touchstart', this.onTouchStart);
|
|
||||||
};
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return this.getRenderComponent();
|
const { editLocation, measurementData } = this.state;
|
||||||
}
|
|
||||||
|
|
||||||
getRenderComponent = () => {
|
if (this.props.editDescriptionOnDialog) {
|
||||||
const {
|
|
||||||
editLocation,
|
|
||||||
editDescription,
|
|
||||||
editDescriptionOnDialog,
|
|
||||||
measurementData,
|
|
||||||
} = this.state;
|
|
||||||
|
|
||||||
if (editDescriptionOnDialog) {
|
|
||||||
return (
|
return (
|
||||||
<EditDescriptionDialog
|
<EditDescriptionDialog
|
||||||
onCancel={this.props.labellingDoneCallback}
|
onCancel={this.props.labellingDoneCallback}
|
||||||
@ -74,10 +36,10 @@ export default class LabellingManager extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (editLocation || editDescription) {
|
if (editLocation || this.props.editDescription) {
|
||||||
return <LabellingFlow {...this.props} />;
|
return <LabellingFlow {...this.props} />;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
treatMeasurementData = measurementData => {
|
treatMeasurementData = measurementData => {
|
||||||
const { editDescription, editLocation } = this.props;
|
const { editDescription, editLocation } = this.props;
|
||||||
@ -91,11 +53,6 @@ export default class LabellingManager extends Component {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
responseDialogUpdate = response => {
|
|
||||||
this.props.updateLabelling({ response });
|
|
||||||
this.props.labellingDoneCallback();
|
|
||||||
};
|
|
||||||
|
|
||||||
descriptionDialogUpdate = description => {
|
descriptionDialogUpdate = description => {
|
||||||
this.props.updateLabelling({ description });
|
this.props.updateLabelling({ description });
|
||||||
this.props.labellingDoneCallback();
|
this.props.labellingDoneCallback();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user