Skip to content

Commit

Permalink
fix: Set SR viewport as active by interaction (OHIF#1118)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rodrigoea authored and dannyrb committed Oct 29, 2019
1 parent 20bfc82 commit 5b33417
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 19 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"globals": {
"cy": true,
"before": true,
"context": true,
"Cypress": true,
"assert": true
Expand Down
33 changes: 33 additions & 0 deletions extensions/dicom-html/src/ConnectedDicomHtmlViewport.js
Original file line number Diff line number Diff line change
@@ -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;
52 changes: 36 additions & 16 deletions extensions/dicom-html/src/DicomHtmlViewport.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -30,7 +32,7 @@ function getValueString(data) {
const {
CodeMeaning,
CodeValue,
CodingSchemeDesignator
CodingSchemeDesignator,
} = data.ConceptNameCodeSequence;

return `${CodeMeaning} (${CodeValue}, ${CodingSchemeDesignator})`;
Expand Down Expand Up @@ -75,7 +77,7 @@ function constructContentSequence(data, header) {
}

const result = {
items
items,
};

if (header) {
Expand Down Expand Up @@ -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;
Expand All @@ -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 => {
Expand Down Expand Up @@ -154,7 +152,7 @@ const getContentSequence = (data, level = 1) => {
const {
CodeMeaning,
CodeValue,
CodingSchemeDesignator
CodingSchemeDesignator,
} = data.ConceptNameCodeSequence;

header = `${CodeMeaning} (${CodeValue} - ${CodingSchemeDesignator})`;
Expand Down Expand Up @@ -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() {
Expand All @@ -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>
);
}
Expand Down
9 changes: 7 additions & 2 deletions extensions/dicom-html/src/OHIFDicomHtmlViewport.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
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 {
static propTypes = {
studies: PropTypes.object,
displaySet: PropTypes.object,
viewportIndex: PropTypes.number,
viewportData: PropTypes.object,
};

state = {
Expand Down Expand Up @@ -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>}
</>
Expand Down
19 changes: 19 additions & 0 deletions platform/viewer/cypress/integration/pwa/OHIFExtensionHTML.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
});
17 changes: 16 additions & 1 deletion platform/viewer/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -364,4 +379,4 @@ function canvasToImage(selectorOrEl) {
canvas.setAttribute('data-percy-canvas', true);
canvas.parentElement.appendChild(image);
canvas.style = 'display: none';
}
}

0 comments on commit 5b33417

Please sign in to comment.