diff --git a/platform/viewer/src/components/Labelling/LabellingFlow.js b/platform/viewer/src/components/Labelling/LabellingFlow.js
index 877682117..efe54b156 100644
--- a/platform/viewer/src/components/Labelling/LabellingFlow.js
+++ b/platform/viewer/src/components/Labelling/LabellingFlow.js
@@ -1,5 +1,5 @@
import { Icon, SelectTree } from '@ohif/ui';
-import React, { Component } from 'react';
+import React, { useState, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import cloneDeep from 'lodash.clonedeep';
@@ -8,87 +8,140 @@ import OHIFLabellingData from './OHIFLabellingData.js';
import EditDescriptionDialog from './../EditDescriptionDialog/EditDescriptionDialog.js';
import './LabellingFlow.css';
-class LabellingFlow extends Component {
- constructor(props) {
- super(props);
+const LabellingFlow = ({
+ measurementData,
+ editLocation,
+ editDescription,
+ skipAddLabelButton,
+ updateLabelling,
+ labellingDoneCallback,
+ editDescriptionOnDialog,
+}) => {
+ const [fadeOutTimer, setFadeOutTimer] = useState();
+ const [showComponent, setShowComponent] = useState(true);
+ const descriptionInput = useRef();
+ const [state, setState] = useState({
+ measurementData,
+ editLocation,
+ editDescription,
+ skipAddLabelButton,
+ });
- const newMeasurementData = cloneDeep(props.measurementData);
- this.treatMeasurementData(newMeasurementData);
+ const initialItems = OHIFLabellingData;
+ const currentItems = cloneDeep(initialItems);
- let newEditLocation = props.editLocation;
- if (!props.editDescription && !props.editLocation) {
- newEditLocation = true;
- }
+ useEffect(() => {
+ const treatMeasurementData = measurementData => {
+ if (editDescription) {
+ measurementData.description = undefined;
+ }
- this.state = {
- measurementData: newMeasurementData,
- skipAddLabelButton: props.skipAddLabelButton,
- editDescription: props.editDescription,
- editLocation: newEditLocation,
- confirmationState: false,
- displayComponent: true,
+ if (editLocation) {
+ measurementData.location = undefined;
+ }
};
- this.descriptionInput = React.createRef();
- this.initialItems = OHIFLabellingData;
- this.currentItems = cloneDeep(this.initialItems);
- }
+ const newMeasurementData = cloneDeep(measurementData);
+ treatMeasurementData(newMeasurementData);
- componentDidUpdate = () => {
- if (this.state.editDescription) {
- this.descriptionInput.current.focus();
+ let newEditLocation = editLocation;
+ if (!editDescription && !editLocation) {
+ newEditLocation = true;
+ }
+ setState(state => ({
+ ...state,
+ editLocation: newEditLocation,
+ measurementData: newMeasurementData,
+ }));
+ }, [editDescription, editLocation, measurementData]);
+
+ useEffect(() => {
+ if (descriptionInput.current) {
+ descriptionInput.current.focus();
+ }
+ }, [state]);
+
+ const relabel = event =>
+ setState(state => ({ ...state, editLocation: true }));
+
+ const setDescriptionUpdateMode = () => {
+ descriptionInput.current.focus();
+ setState(state => ({ ...state, editDescription: true }));
+ };
+
+ const descriptionCancel = () => {
+ const { description = '' } = cloneDeep(state);
+ descriptionInput.current.value = description;
+ setState(state => ({ ...state, editDescription: false }));
+ };
+
+ const handleKeyPress = e => {
+ if (e.key === 'Enter') {
+ descriptionSave();
}
};
- treatMeasurementData = measurementData => {
- const { editDescription, editLocation } = this.props;
+ const descriptionSave = () => {
+ const description = descriptionInput.current.value;
+ updateLabelling({ description });
- if (editDescription) {
- measurementData.description = undefined;
- }
-
- if (editLocation) {
- measurementData.location = undefined;
- }
+ setState(state => ({
+ ...state,
+ description,
+ editDescription: false,
+ }));
};
- descriptionDialogUpdate = description => {
- this.props.updateLabelling({ description });
- this.props.labellingDoneCallback();
+ const selectTreeSelectCallback = (event, itemSelected) => {
+ const location = itemSelected.value;
+ const locationLabel = itemSelected.label;
+ updateLabelling({ location });
+
+ setState(state => ({
+ ...state,
+ editLocation: false,
+ measurementData: {
+ ...state.measurementData,
+ location,
+ locationLabel,
+ },
+ }));
};
- render() {
- if (this.props.editDescriptionOnDialog) {
- return (
-