AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 1 | import React from 'react'; |
Arielk | a51eac0 | 2019-07-07 12:56:11 +0300 | [diff] [blame] | 2 | import { SVGIcon } from 'onap-ui-react'; |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 3 | import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js'; |
| 4 | import Tooltip from 'react-bootstrap/lib/Tooltip.js'; |
| 5 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 6 | function tooltip(msg) { |
| 7 | return ( |
| 8 | <Tooltip |
| 9 | className="select-action-table-error-tooltip" |
| 10 | id="error-tooltip"> |
| 11 | {msg} |
| 12 | </Tooltip> |
| 13 | ); |
Avi Ziv | b8e2faf | 2017-07-18 19:45:38 +0300 | [diff] [blame] | 14 | } |
| 15 | |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 16 | const IconWithOverlay = ({ overlayMsg }) => ( |
| 17 | <OverlayTrigger placement="bottom" overlay={tooltip(overlayMsg)}> |
| 18 | <SVGIcon name="errorCircle" color="negative" /> |
| 19 | </OverlayTrigger> |
| 20 | ); |
| 21 | |
| 22 | function renderErrorOrCheck({ hasError, overlayMsg }) { |
| 23 | if (hasError === undefined) { |
| 24 | return <SVGIcon name="angleRight" className="dummy-icon" />; |
| 25 | } |
| 26 | |
| 27 | if (hasError) { |
| 28 | return overlayMsg ? ( |
| 29 | <IconWithOverlay overlayMsg={overlayMsg} /> |
| 30 | ) : ( |
| 31 | <SVGIcon color="negative" name="errorCircle" /> |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | return <SVGIcon name="checkCircle" color="positive" />; |
| 36 | } |
| 37 | |
| 38 | const SelectActionTableRow = ({ |
| 39 | children, |
| 40 | actionIcon, |
| 41 | onAction, |
| 42 | showAction, |
| 43 | hasError, |
| 44 | hasErrorIndication, |
| 45 | overlayMsg |
| 46 | }) => ( |
| 47 | <div className="select-action-table-row-wrapper"> |
| 48 | <div |
| 49 | className={`select-action-table-row ${ |
| 50 | hasError ? 'has-error' : '' |
| 51 | }`}> |
| 52 | {children} |
| 53 | </div> |
| 54 | {onAction && ( |
| 55 | <SVGIcon |
| 56 | color="secondary" |
| 57 | name={actionIcon} |
| 58 | data-test-id={`select-action-table-${actionIcon}`} |
| 59 | onClick={onAction} |
| 60 | iconClassName={showAction ? '' : 'hideDelete'} |
| 61 | /> |
| 62 | )} |
| 63 | {hasErrorIndication && renderErrorOrCheck({ hasError, overlayMsg })} |
| 64 | </div> |
AviZi | 280f801 | 2017-06-09 02:39:56 +0300 | [diff] [blame] | 65 | ); |
| 66 | |
| 67 | export default SelectActionTableRow; |