import React, { Component } from 'react'; import PropTypes from 'prop-types'; import { withTranslation } from '../../contextProviders'; import { Icon } from './../../elements/Icon'; import { OverlayTrigger } from './../overlayTrigger'; import { Tooltip } from './../tooltip'; import { TableListItem } from './../tableList/TableListItem.js'; import './MeasurementTableItem.styl'; const ColoredCircle = ({ color }) => { return
; }; ColoredCircle.propTypes = { color: PropTypes.string.isRequired, }; class MeasurementTableItem extends Component { static propTypes = { measurementData: PropTypes.object.isRequired, onItemClick: PropTypes.func.isRequired, onRelabel: PropTypes.func, onDelete: PropTypes.func, onEditDescription: PropTypes.func, itemClass: PropTypes.string, itemIndex: PropTypes.number, t: PropTypes.func, }; constructor(props) { super(props); this.state = { collapsed: true, visible: true, }; } render() { const { warningTitle = '', hasWarnings, isReadOnly, } = this.props.measurementData; return ( {hasWarnings && !isReadOnly ? (
{this.props.t(warningTitle)}
{this.getWarningContent()}
} >
{this.getTableListItem()}
) : ( {this.getTableListItem()} )}
); } getActionButton = (btnLabel, onClickCallback) => { return ( ); }; getTableListItem = () => { const hasWarningClass = this.props.measurementData.hasWarnings && !this.props.measurementData.isReadOnly ? 'hasWarnings' : ''; const actionButtons = []; if (typeof this.props.onRelabel === 'function') { const relabelButton = this.getActionButton( 'Relabel', this.onRelabelClick ); actionButtons.push(relabelButton); } if (typeof this.props.onEditDescription === 'function') { const descriptionButton = this.getActionButton( 'Description', this.onEditDescriptionClick ); actionButtons.push(descriptionButton); } if (typeof this.props.onDelete === 'function') { const deleteButton = this.getActionButton('Delete', this.onDeleteClick); actionButtons.push(deleteButton); } if ( this.props.measurementData.isSRText === true && this.props.measurementData.labels && this.props.measurementData.labels.length > 0 ) { return (
{this.props.t(this.props.measurementData.label, { keySeparator: '>', nsSeparator: '|', })}
{this.getDataDisplayText()}
{ this.props.measurementData.labels.forEach(label => { label.visible = !this.state.visible; }); this.setState({ visible: !this.state.visible, }); }} /> { this.setState({ collapsed: !this.state.collapsed, }); }} />
{this.state.collapsed && this.props.measurementData.labels.map((SRLabel, index) => { return ( } itemMetaClass="item-color-section" onItemClick={this.onItemClick} >
{SRLabel.label + ' : ' + SRLabel.value} { SRLabel.visible = !SRLabel.visible; }} />
); })}
); } else { return (
{this.props.t(this.props.measurementData.label, { keySeparator: '>', nsSeparator: '|', })}
{this.getDataDisplayText()}
{!this.props.measurementData.isReadOnly && (
{actionButtons}
)}
); } }; onItemClick = event => { this.props.onItemClick(event, this.props.measurementData); }; onRelabelClick = event => { // Prevent onItemClick from firing event.stopPropagation(); this.props.onRelabel(event, this.props.measurementData); }; onEditDescriptionClick = event => { // Prevent onItemClick from firing event.stopPropagation(); this.props.onEditDescription(event, this.props.measurementData); }; onDeleteClick = event => { // Prevent onItemClick from firing event.stopPropagation(); this.props.onDelete(event, this.props.measurementData); }; getDataDisplayText = () => { return this.props.measurementData.data.map((data, index) => { return (
{data.displayText ? data.displayText : '...'}
); }); }; getWarningContent = () => { const { warningList = '' } = this.props.measurementData; if (Array.isArray(warningList)) { const listedWarnings = warningList.map((warn, index) => { return
  • {warn}
  • ; }); return
      {listedWarnings}
    ; } else { return {warningList}; } }; } const connectedComponent = withTranslation('MeasurementTable')( MeasurementTableItem ); export { connectedComponent as MeasurementTableItem }; export default connectedComponent;