fix: Set SR viewport as active by interaction (#1118)
* fix: Set SR viewport as active by interaction * quick fix * (eslint) add "before" as global variables * add data-cy * add data-cy * create E2E test * (E2E) create custom command to set layout size * remove .only e2e * remove throttle for onScroll
This commit is contained in:
parent
20bfc829f7
commit
5b334175c3
@ -16,6 +16,7 @@
|
||||
},
|
||||
"globals": {
|
||||
"cy": true,
|
||||
"before": true,
|
||||
"context": true,
|
||||
"Cypress": true,
|
||||
"assert": true
|
||||
|
||||
33
extensions/dicom-html/src/ConnectedDicomHtmlViewport.js
Normal file
33
extensions/dicom-html/src/ConnectedDicomHtmlViewport.js
Normal file
@ -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;
|
||||
@ -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 (
|
||||
<div className={'DicomHtmlViewport'}>
|
||||
{this.state.content}
|
||||
{this.state.error && <h2>{JSON.stringify(this.state.error)}</h2>}
|
||||
<div
|
||||
data-cy="dicom-html-viewport"
|
||||
className="DicomHtmlViewport"
|
||||
onClick={this.setViewportActiveHandler}
|
||||
onScroll={this.setViewportActiveHandler}
|
||||
>
|
||||
{content}
|
||||
{error && <h2>{JSON.stringify(error)}</h2>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import React, { Component } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
import DicomHtmlViewport from './DicomHtmlViewport';
|
||||
import OHIF from '@ohif/core';
|
||||
import ConnectedDicomHtmlViewport from './ConnectedDicomHtmlViewport';
|
||||
|
||||
const { DicomLoaderService } = OHIF.utils;
|
||||
|
||||
class OHIFDicomHtmlViewport extends Component {
|
||||
@ -9,6 +10,7 @@ class OHIFDicomHtmlViewport extends Component {
|
||||
studies: PropTypes.object,
|
||||
displaySet: PropTypes.object,
|
||||
viewportIndex: PropTypes.number,
|
||||
viewportData: PropTypes.object,
|
||||
};
|
||||
|
||||
state = {
|
||||
@ -40,7 +42,10 @@ class OHIFDicomHtmlViewport extends Component {
|
||||
return (
|
||||
<>
|
||||
{this.state.byteArray && (
|
||||
<DicomHtmlViewport byteArray={this.state.byteArray} />
|
||||
<ConnectedDicomHtmlViewport
|
||||
byteArray={this.state.byteArray}
|
||||
viewportIndex={this.props.viewportIndex}
|
||||
/>
|
||||
)}
|
||||
{this.state.error && <h2>{JSON.stringify(this.state.error)}</h2>}
|
||||
</>
|
||||
|
||||
@ -22,4 +22,23 @@ describe('OHIF HTML Extension', () => {
|
||||
'Imaging Measurement Report'
|
||||
);
|
||||
});
|
||||
|
||||
it('checks if the HTML viewport has been set to active by interaction', () => {
|
||||
cy.setLayout('3', '3');
|
||||
|
||||
// check if viewport has been set as active by CLICKING
|
||||
cy.get('[data-cy=viewprt-grid] > :nth-child(4)')
|
||||
.click()
|
||||
.then($viewport => {
|
||||
cy.wrap($viewport).should('have.class', 'active');
|
||||
});
|
||||
|
||||
// check if viewport has been set as active by SCROLLING
|
||||
cy.get('[data-cy=viewprt-grid] > :nth-child(7)').then($viewport => {
|
||||
cy.wrap($viewport)
|
||||
.find('[data-cy=dicom-html-viewport]')
|
||||
.scrollTo('bottom');
|
||||
cy.wrap($viewport).should('have.class', 'active');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -328,6 +328,21 @@ Cypress.Commands.add('percyCanvasSnapshot', (name, options = {}) => {
|
||||
});
|
||||
});
|
||||
|
||||
Cypress.Commands.add('setLayout', (columns = 1, rows = 1) => {
|
||||
cy.get('.toolbar-button-label')
|
||||
.contains('Layout')
|
||||
.click();
|
||||
|
||||
cy.get('.layoutChooser')
|
||||
.find('tr')
|
||||
.eq(rows - 1)
|
||||
.find('td')
|
||||
.eq(columns - 1)
|
||||
.click();
|
||||
|
||||
cy.wait(1000);
|
||||
});
|
||||
|
||||
function convertCanvas(documentClone) {
|
||||
documentClone
|
||||
.querySelectorAll('canvas')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user