prettier applied to all files in src/

This commit is contained in:
dannyrb committed 2019-05-29 08:39:54 -04:00
1 parent 433bb219b0
commit fb7c229b43
69 files changed
+1128 -1116

No files matched your search

+8 -8
View File
@@ -4,34 +4,34 @@
* Link: https://serverless-stack.com/chapters/code-splitting-in-create-react-app.html
*/
import React, { Component } from 'react'
import React, { Component } from 'react';
export default function asyncComponent(importComponent) {
class AsyncComponent extends Component {
constructor(props) {
super(props)
super(props);
this.state = {
component: null,
}
};
}
async componentDidMount() {
// Add dynamically loaded component to state
const { default: component } = await importComponent()
const { default: component } = await importComponent();
this.setState({
component: component,
})
});
}
render() {
const C = this.state.component
const C = this.state.component;
// Render the loaded component, or null
return C ? <C {...this.props} /> : null
return C ? <C {...this.props} /> : null;
}
}
return AsyncComponent
return AsyncComponent;
}
@@ -1,18 +1,18 @@
import { Component } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import SimpleDialog from '../SimpleDialog/SimpleDialog.js'
import { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import SimpleDialog from '../SimpleDialog/SimpleDialog.js';
import bounding from '../../lib/utils/bounding.js'
import { getDialogStyle } from './../Labelling/labellingPositionUtils.js'
import bounding from '../../lib/utils/bounding.js';
import { getDialogStyle } from './../Labelling/labellingPositionUtils.js';
import './EditDescriptionDialog.css'
import './EditDescriptionDialog.css';
export default class EditDescriptionDialog extends Component {
static defaultProps = {
componentRef: React.createRef(),
componentStyle: {},
}
};
static propTypes = {
measurementData: PropTypes.object.isRequired,
@@ -20,32 +20,32 @@ export default class EditDescriptionDialog extends Component {
componentRef: PropTypes.object,
componentStyle: PropTypes.object,
onUpdate: PropTypes.func.isRequired,
}
};
constructor(props) {
super(props)
super(props);
this.state = {
description: props.measurementData.description || '',
}
};
this.mainElement = React.createRef()
this.mainElement = React.createRef();
}
componentDidMount = () => {
bounding(this.mainElement)
}
bounding(this.mainElement);
};
componentDidUpdate(prevProps) {
if (this.props.description !== prevProps.description) {
this.setState({
description: this.props.description,
})
});
}
}
render() {
const style = getDialogStyle(this.props.componentStyle)
const style = getDialogStyle(this.props.componentStyle);
return (
<SimpleDialog
@@ -65,18 +65,18 @@ export default class EditDescriptionDialog extends Component {
onChange={this.handleChange}
/>
</SimpleDialog>
)
);
}
onClose = () => {
this.props.onCancel()
}
this.props.onCancel();
};
onConfirm = () => {
this.props.onUpdate(this.state.description)
}
this.props.onUpdate(this.state.description);
};
handleChange = event => {
this.setState({ description: event.target.value })
}
this.setState({ description: event.target.value });
};
}
+7 -7
View File
@@ -11,32 +11,32 @@ class Header extends Component {
home: PropTypes.bool.isRequired,
location: PropTypes.object.isRequired,
openUserPreferencesModal: PropTypes.func,
children: PropTypes.node
children: PropTypes.node,
};
static defaultProps = {
home: true,
children: OHIFLogo()
children: OHIFLogo(),
};
constructor(props) {
super(props);
this.state = {
userPreferencesOpen: false
userPreferencesOpen: false,
};
this.options = [
{
title: 'Preferences ',
icon: 'fa fa-user',
onClick: this.props.openUserPreferencesModal
onClick: this.props.openUserPreferencesModal,
},
{
title: 'About',
icon: 'fa fa-info',
link: 'http://ohif.org'
}
link: 'http://ohif.org',
},
];
}
@@ -60,7 +60,7 @@ class Header extends Component {
className="header-btn header-studyListLinkSection"
to={{
pathname: '/',
state: { studyLink: this.props.location.pathname }
state: { studyLink: this.props.location.pathname },
}}
>
Study list
+2 -2
View File
@@ -1,3 +1,3 @@
import Header from './Header'
import Header from './Header';
export default Header
export default Header;
+68 -65
View File
@@ -1,14 +1,14 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cloneDeep from 'lodash.clonedeep'
import bounding from '../../lib/utils/bounding.js'
import cloneDeep from 'lodash.clonedeep';
import bounding from '../../lib/utils/bounding.js';
import LabellingTransition from './LabellingTransition.js'
import { SelectTree } from 'react-viewerbase'
import { getAddLabelButtonStyle } from './labellingPositionUtils.js'
import LabellingTransition from './LabellingTransition.js';
import { SelectTree } from 'react-viewerbase';
import { getAddLabelButtonStyle } from './labellingPositionUtils.js';
import OHIFLabellingData from './OHIFLabellingData.js'
import OHIFLabellingData from './OHIFLabellingData.js';
export default class LabellingFlow extends Component {
static propTypes = {
@@ -21,16 +21,16 @@ export default class LabellingFlow extends Component {
skipAddLabelButton: PropTypes.bool,
editLocation: PropTypes.bool,
editDescription: PropTypes.bool,
}
};
constructor(props) {
super(props)
super(props);
const { location, locationLabel, description } = props.measurementData
const { location, locationLabel, description } = props.measurementData;
let style = props.componentStyle
let style = props.componentStyle;
if (!props.skipAddLabelButton) {
style = getAddLabelButtonStyle(props.measurementData, props.eventData)
style = getAddLabelButtonStyle(props.measurementData, props.eventData);
}
this.state = {
@@ -43,28 +43,28 @@ export default class LabellingFlow extends Component {
componentStyle: style,
confirmationState: false,
displayComponent: true,
}
};
this.mainElement = React.createRef()
this.descriptionInput = React.createRef()
this.mainElement = React.createRef();
this.descriptionInput = React.createRef();
this.initialItems = OHIFLabellingData
this.currentItems = cloneDeep(this.initialItems)
this.initialItems = OHIFLabellingData;
this.currentItems = cloneDeep(this.initialItems);
}
componentDidUpdate = () => {
this.repositionComponent()
}
this.repositionComponent();
};
render() {
let mainElementClassName = 'labellingComponent'
let mainElementClassName = 'labellingComponent';
if (this.state.editDescription) {
mainElementClassName += ' editDescription'
mainElementClassName += ' editDescription';
}
const style = Object.assign({}, this.state.componentStyle)
const style = Object.assign({}, this.state.componentStyle);
if (this.state.skipAddLabelButton) {
style.left -= 160
style.left -= 160;
}
return (
@@ -82,7 +82,7 @@ export default class LabellingFlow extends Component {
{this.labellingStateFragment()}
</div>
</LabellingTransition>
)
);
}
labellingStateFragment = () => {
@@ -91,9 +91,12 @@ export default class LabellingFlow extends Component {
editLocation,
description,
locationLabel,
} = this.state
} = this.state;
const Icons = `${window.config.routerBasename}/icons.svg`.replace('//', '/')
const Icons = `${window.config.routerBasename}/icons.svg`.replace(
'//',
'/'
);
if (!skipAddLabelButton) {
return (
@@ -106,7 +109,7 @@ export default class LabellingFlow extends Component {
{this.state.location ? 'Edit' : 'Add'} Label
</button>
</>
)
);
} else {
if (editLocation) {
return (
@@ -117,7 +120,7 @@ export default class LabellingFlow extends Component {
selectTreeFirstTitle="Assign Label"
onComponentChange={this.repositionComponent}
/>
)
);
} else {
return (
<>
@@ -174,53 +177,53 @@ export default class LabellingFlow extends Component {
</button>
</div>
</>
)
);
}
}
}
};
relabel = () => {
this.setState({
editLocation: true,
})
}
});
};
setDescriptionUpdateMode = () => {
this.descriptionInput.current.focus()
this.descriptionInput.current.focus();
this.setState({
editDescription: true,
})
}
});
};
descriptionCancel = () => {
const { description = '' } = cloneDeep(this.state)
this.descriptionInput.current.value = description
const { description = '' } = cloneDeep(this.state);
this.descriptionInput.current.value = description;
this.setState({
editDescription: false,
})
}
});
};
descriptionSave = () => {
const description = this.descriptionInput.current.value
this.props.updateLabelling({ description })
const description = this.descriptionInput.current.value;
this.props.updateLabelling({ description });
this.setState({
description,
editDescription: false,
})
}
});
};
selectTreeSelectCalback = (event, itemSelected) => {
const location = itemSelected.value
this.props.updateLabelling({ location })
const location = itemSelected.value;
this.props.updateLabelling({ location });
const viewportTopPosition = this.mainElement.current.offsetParent.offsetTop
const viewportTopPosition = this.mainElement.current.offsetParent.offsetTop;
const componentStyle = {
top: event.nativeEvent.y - viewportTopPosition - 25,
left: this.state.componentStyle.left,
}
};
this.setState({
editLocation: false,
@@ -228,51 +231,51 @@ export default class LabellingFlow extends Component {
location: itemSelected.value,
locationLabel: itemSelected.label,
componentStyle,
})
});
if (this.isTouchScreen) {
this.setTimeout = setTimeout(() => {
this.setState({
displayComponent: false,
})
}, 2000)
});
}, 2000);
}
}
};
showLabelling = () => {
this.setState({
skipAddLabelButton: true,
editLocation: false,
})
}
});
};
fadeOutAndLeave = () => {
// Wait for 1 sec to dismiss the labelling component
this.fadeOutTimer = setTimeout(() => {
this.setState({
displayComponent: false,
})
}, 1000)
}
});
}, 1000);
};
fadeOutAndLeaveFast = () => {
this.setState({
displayComponent: false,
})
}
});
};
clearFadeOutTimer = () => {
if (!this.fadeOutTimer) {
return
return;
}
clearTimeout(this.fadeOutTimer)
}
clearTimeout(this.fadeOutTimer);
};
repositionComponent = () => {
// SetTimeout for the css animation to end.
setTimeout(() => {
bounding(this.mainElement)
}, 200)
}
bounding(this.mainElement);
}, 200);
};
}
+35 -35
View File
@@ -1,12 +1,12 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import cloneDeep from 'lodash.clonedeep'
import cloneDeep from 'lodash.clonedeep';
import EditDescriptionDialog from './../EditDescriptionDialog/EditDescriptionDialog.js'
import LabellingFlow from './LabellingFlow.js'
import EditDescriptionDialog from './../EditDescriptionDialog/EditDescriptionDialog.js';
import LabellingFlow from './LabellingFlow.js';
import './LabellingManager.css'
import './LabellingManager.css';
export default class LabellingManager extends Component {
static propTypes = {
@@ -20,24 +20,24 @@ export default class LabellingManager extends Component {
editLocation: PropTypes.bool,
editDescription: PropTypes.bool,
editDescriptionOnDialog: PropTypes.bool,
}
};
static defaultProps = {
skipAddLabelButton: false,
editLocation: false,
editDescription: false,
editDescriptionOnDialog: false,
}
};
constructor(props) {
super(props)
super(props);
const measurementData = cloneDeep(props.measurementData)
this.treatMeasurementData(measurementData)
const measurementData = cloneDeep(props.measurementData);
this.treatMeasurementData(measurementData);
let editLocation = props.editLocation
let editLocation = props.editLocation;
if (!props.editDescription && !props.editLocation) {
editLocation = true
editLocation = true;
}
this.state = {
@@ -47,19 +47,19 @@ export default class LabellingManager extends Component {
editDescription: props.editDescription,
editDescriptionOnDialog: props.editDescriptionOnDialog,
measurementData: measurementData,
}
};
}
componentDidMount = () => {
document.addEventListener('touchstart', this.onTouchStart)
}
document.addEventListener('touchstart', this.onTouchStart);
};
componentWillUnmount = () => {
document.removeEventListener('touchstart', this.onTouchStart)
}
document.removeEventListener('touchstart', this.onTouchStart);
};
render() {
return this.getRenderComponent()
return this.getRenderComponent();
}
getRenderComponent = () => {
@@ -68,7 +68,7 @@ export default class LabellingManager extends Component {
editDescription,
editDescriptionOnDialog,
measurementData,
} = this.state
} = this.state;
if (editDescriptionOnDialog) {
return (
@@ -79,7 +79,7 @@ export default class LabellingManager extends Component {
componentStyle={this.state.componentStyle}
measurementData={measurementData}
/>
)
);
}
if (editLocation || editDescription) {
@@ -88,43 +88,43 @@ export default class LabellingManager extends Component {
{...this.props}
componentStyle={this.state.componentStyle}
/>
)
);
}
}
};
treatMeasurementData = measurementData => {
const { editDescription, editLocation } = this.props
const { editDescription, editLocation } = this.props;
if (editDescription) {
measurementData.description = undefined
measurementData.description = undefined;
}
if (editLocation) {
measurementData.location = undefined
measurementData.location = undefined;
}
}
};
responseDialogUpdate = response => {
this.props.updateLabelling({
response,
})
this.props.labellingDoneCallback()
}
});
this.props.labellingDoneCallback();
};
descriptionDialogUpdate = description => {
this.props.updateLabelling({
description,
})
this.props.labellingDoneCallback()
}
});
this.props.labellingDoneCallback();
};
}
function getComponentPosition(eventData) {
const {
event: { clientX: left, clientY: top },
} = eventData
} = eventData;
return {
left,
top,
}
};
}
@@ -1,20 +1,20 @@
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { CSSTransition } from 'react-transition-group'
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { CSSTransition } from 'react-transition-group';
import './LabellingTransition.css'
import './LabellingTransition.css';
// If these variables changes, CSS must be updated
const transitionDuration = 500
const transitionClassName = 'labelling'
const transitionOnAppear = true
const transitionDuration = 500;
const transitionClassName = 'labelling';
const transitionOnAppear = true;
export default class LabellingTransition extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
displayComponent: PropTypes.bool.isRequired,
onTransitionExit: PropTypes.func.isRequired,
}
};
render() {
return (
<CSSTransition
@@ -26,6 +26,6 @@ export default class LabellingTransition extends Component {
>
{this.props.children}
</CSSTransition>
)
);
}
}
@@ -27,13 +27,13 @@ const items = [
'Spleen',
'Stomach',
'Subcutaneous',
]
];
const OHIFLabellingData = items.map(item => {
return {
label: item,
value: item,
}
})
};
});
export default OHIFLabellingData
export default OHIFLabellingData;
@@ -1,53 +1,53 @@
import cornerstone from 'cornerstone-core'
import cornerstone from 'cornerstone-core';
const buttonSize = {
width: 96,
height: 28,
}
};
export function getAddLabelButtonStyle(measurementData, eventData) {
const { start, end } = measurementData.handles
const { client } = eventData.currentPoints
const clientStart = cornerstone.pixelToCanvas(eventData.element, start)
const clientEnd = cornerstone.pixelToCanvas(eventData.element, end)
const canvasOffSetLeft = client.x - clientStart.x
const canvasOffSetTop = client.y - clientStart.y
const { start, end } = measurementData.handles;
const { client } = eventData.currentPoints;
const clientStart = cornerstone.pixelToCanvas(eventData.element, start);
const clientEnd = cornerstone.pixelToCanvas(eventData.element, end);
const canvasOffSetLeft = client.x - clientStart.x;
const canvasOffSetTop = client.y - clientStart.y;
const position = {
left: clientEnd.x + canvasOffSetLeft,
top: clientEnd.y + canvasOffSetTop,
}
};
if (start.y > end.y) {
position.top -= buttonSize.height
position.top -= buttonSize.height;
}
if (start.x > end.x) {
position.left -= buttonSize.width
position.left -= buttonSize.width;
}
return position
return position;
}
export function getDialogStyle(componentStyle) {
const style = Object.assign({}, componentStyle)
const style = Object.assign({}, componentStyle);
const dialogProps = {
width: 320,
height: 230,
}
};
// Get max values to avoid position out of the screen
const maxLeft = window.innerWidth - dialogProps.width
const maxTop = window.innerHeight - dialogProps.height
const maxLeft = window.innerWidth - dialogProps.width;
const maxTop = window.innerHeight - dialogProps.height;
// Positioning the dialog with its center on the click event
style.left -= dialogProps.width / 2
style.top -= dialogProps.height / 2
style.left -= dialogProps.width / 2;
style.top -= dialogProps.height / 2;
if (style.left > maxLeft) {
style.left = maxLeft
style.left = maxLeft;
}
if (style.top > maxTop) {
style.top = maxTop
style.top = maxTop;
}
return style
return style;
}
+5 -5
View File
@@ -1,7 +1,7 @@
import React from 'react'
import './OHIFLogo.css'
import React from 'react';
import './OHIFLogo.css';
const Icons = `${window.config.routerBasename}/icons.svg`.replace('//', '/')
const Icons = `${window.config.routerBasename}/icons.svg`.replace('//', '/');
function OHIFLogo() {
return (
@@ -16,7 +16,7 @@ function OHIFLogo() {
</svg>
<div className="header-logo-text">Open Health Imaging Foundation</div>
</a>
)
);
}
export default OHIFLogo
export default OHIFLogo;
+8 -8
View File
@@ -1,14 +1,14 @@
import { Component } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import { Component } from 'react';
import React from 'react';
import PropTypes from 'prop-types';
import './SimpleDialog.css'
import './SimpleDialog.css';
class SimpleDialog extends Component {
static defaultProps = {
componentStyle: {},
rootClass: '',
}
};
render() {
return (
@@ -43,7 +43,7 @@ class SimpleDialog extends Component {
</div>
</form>
</div>
)
);
}
}
@@ -51,6 +51,6 @@ SimpleDialog.propTypes = {
headerTitle: PropTypes.string.isRequired,
onClose: PropTypes.func.isRequired,
onConfirm: PropTypes.func.isRequired,
}
};
export default SimpleDialog
export default SimpleDialog;
+32 -33
View File
@@ -1,43 +1,42 @@
import { Component } from "react";
import PropTypes from "prop-types";
import { Component } from 'react';
import PropTypes from 'prop-types';
import OHIF from 'ohif-core';
class StudyLoadingMonitor extends Component {
static propTypes = {
studies: PropTypes.array.isRequired,
setStudyLoadingProgress: PropTypes.func.isRequired,
clearStudyLoadingProgress: PropTypes.func.isRequired,
static propTypes = {
studies: PropTypes.array.isRequired,
setStudyLoadingProgress: PropTypes.func.isRequired,
clearStudyLoadingProgress: PropTypes.func.isRequired,
};
componentDidMount() {
// TODO: This is pretty ugly. The thing is that the StudyLoadingListener
// needs to update the Redux store, but shouldn't know that it exists.
// I am therefore passing in some functions to update the store instead,
// but this should definitely be cleaned up somehow.
const options = {
_setProgressData: (progressId, progressData) => {
this.props.setStudyLoadingProgress(progressId, progressData);
},
_clearProgressById: progressId => {
this.props.clearStudyLoadingProgress(progressId);
},
};
componentDidMount() {
// TODO: This is pretty ugly. The thing is that the StudyLoadingListener
// needs to update the Redux store, but shouldn't know that it exists.
// I am therefore passing in some functions to update the store instead,
// but this should definitely be cleaned up somehow.
const options = {
_setProgressData: (progressId, progressData) => {
this.props.setStudyLoadingProgress(progressId, progressData)
},
_clearProgressById: (progressId) => {
this.props.clearStudyLoadingProgress(progressId)
}
}
const { StudyLoadingListener } = OHIF.classes;
this.studyLoadingListener = StudyLoadingListener.getInstance(options);
this.studyLoadingListener.clear();
this.studyLoadingListener.addStudies(this.props.studies);
}
const { StudyLoadingListener } = OHIF.classes;
this.studyLoadingListener = StudyLoadingListener.getInstance(options);
this.studyLoadingListener.clear();
this.studyLoadingListener.addStudies(this.props.studies);
}
render() {
return null;
}
render() {
return null;
}
componentWillUnmount() {
// Destroy stack loading listeners when we close the viewer
this.studyLoadingListener.clear();
}
componentWillUnmount() {
// Destroy stack loading listeners when we close the viewer
this.studyLoadingListener.clear();
}
}
export default StudyLoadingMonitor;
+17 -18
View File
@@ -1,30 +1,29 @@
import { Component } from "react";
import PropTypes from "prop-types";
import { Component } from 'react';
import PropTypes from 'prop-types';
import OHIF from 'ohif-core';
const { StudyPrefetcher } = OHIF.classes;
class StudyPrefetcherComponent extends Component {
static propTypes = {
studies: PropTypes.array,
};
static propTypes = {
studies: PropTypes.array,
};
componentDidMount() {
const { studies } = this.props;
componentDidMount() {
const { studies } = this.props;
this.studyPrefetcher = StudyPrefetcher.getInstance();
this.studyPrefetcher.setStudies(studies);
}
this.studyPrefetcher = StudyPrefetcher.getInstance();
this.studyPrefetcher.setStudies(studies);
}
render() {
return null;
}
render() {
return null;
}
componentWillUnmount() {
// Stop prefetching when we close the viewer
this.studyPrefetcher.destroy();
}
componentWillUnmount() {
// Stop prefetching when we close the viewer
this.studyPrefetcher.destroy();
}
}
export default StudyPrefetcherComponent;