diff --git a/.eslintrc.json b/.eslintrc.json index 49f82e81c56..55db8c49169 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -16,6 +16,7 @@ }, "globals": { "cy": true, + "before": true, "context": true, "Cypress": true, "assert": true diff --git a/extensions/dicom-html/src/ConnectedDicomHtmlViewport.js b/extensions/dicom-html/src/ConnectedDicomHtmlViewport.js new file mode 100644 index 00000000000..9e66b0b7419 --- /dev/null +++ b/extensions/dicom-html/src/ConnectedDicomHtmlViewport.js @@ -0,0 +1,33 @@ +import OHIF from '@ohif/core'; +import { connect } from 'react-redux'; +import DicomHtmlViewport from './DicomHtmlViewport'; + +const { setViewportActive } = OHIF.redux.actions; + +const mapStateToProps = (state, ownProps) => { + const { viewportIndex, byteArray } = ownProps; + const activeViewportIndex = state.viewports; + + return { + viewportIndex, + activeViewportIndex, + byteArray, + }; +}; + +const mapDispatchToProps = (dispatch, ownProps) => { + const { viewportIndex } = ownProps; + + return { + setViewportActive: () => { + dispatch(setViewportActive(viewportIndex)); + }, + }; +}; + +const ConnectedDicomHtmlViewport = connect( + mapStateToProps, + mapDispatchToProps +)(DicomHtmlViewport); + +export default ConnectedDicomHtmlViewport; diff --git a/extensions/dicom-html/src/DicomHtmlViewport.js b/extensions/dicom-html/src/DicomHtmlViewport.js index 686c0057bd7..1008d92cd75 100644 --- a/extensions/dicom-html/src/DicomHtmlViewport.js +++ b/extensions/dicom-html/src/DicomHtmlViewport.js @@ -1,6 +1,8 @@ import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import * as dcmjs from 'dcmjs'; import TypedArrayProp from './TypedArrayProp'; + import './DicomHtmlViewport.css'; function getRelationshipString(data) { @@ -30,7 +32,7 @@ function getValueString(data) { const { CodeMeaning, CodeValue, - CodingSchemeDesignator + CodingSchemeDesignator, } = data.ConceptNameCodeSequence; return `${CodeMeaning} (${CodeValue}, ${CodingSchemeDesignator})`; @@ -75,7 +77,7 @@ function constructContentSequence(data, header) { } const result = { - items + items, }; if (header) { @@ -106,9 +108,7 @@ const { DicomMetaDictionary, DicomMessage } = dcmjs.data; function getMainData(data) { const root = []; - const patientValue = `${data.PatientName} (${data.PatientSex}, #${ - data.PatientID - })`; + const patientValue = `${data.PatientName} (${data.PatientSex}, #${data.PatientID})`; root.push(getMainDataItem('Patient', patientValue)); const studyValue = data.StudyDescription; @@ -117,15 +117,13 @@ function getMainData(data) { const seriesValue = `${data.SeriesDescription} (#${data.SeriesNumber})`; root.push(getMainDataItem('Series', seriesValue)); - const manufacturerValue = `${data.Manufacturer} (${ - data.ManufacturerModelName - }, #${data.DeviceSerialNumber})`; + const manufacturerValue = `${data.Manufacturer} (${data.ManufacturerModelName}, #${data.DeviceSerialNumber})`; root.push(getMainDataItem('Manufacturer', manufacturerValue)); const mainDataObjects = { CompletionFlag: 'Completion flag', - VerificationFlag: 'Verification flag' + VerificationFlag: 'Verification flag', }; Object.keys(mainDataObjects).forEach(key => { @@ -154,7 +152,7 @@ const getContentSequence = (data, level = 1) => { const { CodeMeaning, CodeValue, - CodingSchemeDesignator + CodingSchemeDesignator, } = data.ConceptNameCodeSequence; header = `${CodeMeaning} (${CodeValue} - ${CodingSchemeDesignator})`; @@ -198,11 +196,14 @@ function getMainDataItem(key, value) { class DicomHtmlViewport extends Component { state = { content: null, - error: null + error: null, }; static propTypes = { - byteArray: TypedArrayProp.uint8 + byteArray: TypedArrayProp.uint8, + setViewportActive: PropTypes.func.isRequired, + viewportIndex: PropTypes.number.isRequired, + activeViewportIndex: PropTypes.number.isRequired, }; componentDidMount() { @@ -225,15 +226,34 @@ class DicomHtmlViewport extends Component { ); this.setState({ - content + content, }); } + setViewportActiveHandler = () => { + const { + setViewportActive, + viewportIndex, + activeViewportIndex, + } = this.props; + + if (viewportIndex !== activeViewportIndex) { + setViewportActive(); + } + }; + render() { + const { content, error } = this.state; + return ( -