feat(vewportOverlay): Update the extension to be able to pass custom properties to the viewport

This commit is contained in:
Gustavo Lelis 2019-03-27 04:34:23 -03:00
parent c1173e3232
commit aacd0c68b8
2 changed files with 22 additions and 9 deletions

View File

@ -11,9 +11,18 @@ import ToolbarModule from './ToolbarModule.js';
* @param children * @param children
* @return {function(*): *} * @return {function(*): *}
*/ */
function withChildren(WrappedComponent, children) { function componentWithProps(WrappedComponent, children, customProps) {
return function(props) { return function(props) {
return <WrappedComponent children={children} { ...props } />; const extraProps = {
customProps
};
if (children.viewport) {
extraProps.children = children.viewport;
}
const mergedProps = Object.assign({}, props, extraProps);
return <WrappedComponent {...mergedProps} />;
}; };
} }
@ -21,8 +30,10 @@ function withChildren(WrappedComponent, children) {
// https://github.com/whitecolor/yalc // https://github.com/whitecolor/yalc
export default class OHIFCornerstoneExtension { export default class OHIFCornerstoneExtension {
constructor(children) { constructor(props) {
const { children = {}, customProps = {} } = props;
this.children = children; this.children = children;
this.customProps = customProps;
} }
/** /**
@ -33,11 +44,11 @@ export default class OHIFCornerstoneExtension {
} }
getViewportModule() { getViewportModule() {
if (this.children && this.children.viewport) { return componentWithProps(
return withChildren(OHIFCornerstoneViewport, this.children.viewport); OHIFCornerstoneViewport,
} this.children,
this.customProps
return OHIFCornerstoneViewport; );
} }
getSopClassHandler() { getSopClassHandler() {

View File

@ -36,7 +36,8 @@ class OHIFCornerstoneViewport extends Component {
studies: PropTypes.object, studies: PropTypes.object,
displaySet: PropTypes.object, displaySet: PropTypes.object,
viewportIndex: PropTypes.number, viewportIndex: PropTypes.number,
children: PropTypes.node children: PropTypes.node,
customProps: PropTypes.object
}; };
static id = 'OHIFCornerstoneViewport'; static id = 'OHIFCornerstoneViewport';
@ -226,6 +227,7 @@ class OHIFCornerstoneViewport extends Component {
<ConnectedCornerstoneViewport <ConnectedCornerstoneViewport
viewportData={this.state.viewportData} viewportData={this.state.viewportData}
viewportIndex={this.props.viewportIndex} viewportIndex={this.props.viewportIndex}
{...this.props.customProps}
/> />
)} )}
{childrenWithProps} {childrenWithProps}