blob: 260d39d31cabf9f7f156fdb1d438c36407ea8130 [file] [log] [blame]
AviZi280f8012017-06-09 02:39:56 +03001import React from 'react';
Avi Zivb8e2faf2017-07-18 19:45:38 +03002import SVGIcon from 'sdc-ui/lib/react/SVGIcon.js';
AviZi280f8012017-06-09 02:39:56 +03003import OverlayTrigger from 'react-bootstrap/lib/OverlayTrigger.js';
4import Tooltip from 'react-bootstrap/lib/Tooltip.js';
5
6function tooltip (msg) {
7 return (
8 <Tooltip className='select-action-table-error-tooltip' id='error-tooltip'>{msg}</Tooltip>
9 );
10};
11
12const IconWithOverlay = ({overlayMsg}) => (
13 <OverlayTrigger placement='bottom' overlay={tooltip(overlayMsg)}>
az2497644017c2017-08-10 17:49:40 +030014 <SVGIcon name='errorCircle' color='negative'/>
AviZi280f8012017-06-09 02:39:56 +030015 </OverlayTrigger>
16);
17
Avi Zivb8e2faf2017-07-18 19:45:38 +030018function renderErrorOrCheck({hasError, overlayMsg}) {
19 if (hasError === undefined) {
20 return <SVGIcon name='angleRight' className='dummy-icon' />;
21 }
22
23 if (hasError) {
az2497644017c2017-08-10 17:49:40 +030024 return overlayMsg ? <IconWithOverlay overlayMsg={overlayMsg}/> : <SVGIcon color='negative' name='errorCircle'/>;
Avi Zivb8e2faf2017-07-18 19:45:38 +030025 }
26
az2497644017c2017-08-10 17:49:40 +030027 return <SVGIcon name='checkCircle' color='positive'/>;
Avi Zivb8e2faf2017-07-18 19:45:38 +030028}
29
talig8e9c0652017-12-20 14:30:43 +020030const SelectActionTableRow = ({children, actionIcon, onAction, showAction, hasError, hasErrorIndication, overlayMsg}) => (
AviZi280f8012017-06-09 02:39:56 +030031 <div className='select-action-table-row-wrapper'>
32 <div className={`select-action-table-row ${hasError ? 'has-error' : ''}`}>
33 {children}
34 </div>
talig8e9c0652017-12-20 14:30:43 +020035 {onAction && <SVGIcon color='secondary' name={actionIcon} data-test-id={`select-action-table-${actionIcon}`} onClick={onAction} iconClassName={(showAction) ? '' : 'hideDelete'}/>}
Avi Zivb8e2faf2017-07-18 19:45:38 +030036 {hasErrorIndication && renderErrorOrCheck({hasError, overlayMsg})}
AviZi280f8012017-06-09 02:39:56 +030037 </div>
38);
39
40export default SelectActionTableRow;