blob: a03f8441a400ce48aeee3859cbdbcc07c98e45af [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
Avi Ziv61070c92017-07-26 17:37:57 +030030const SelectActionTableRow = ({children, onDelete, hasError, hasErrorIndication, overlayMsg, showDelete}) => (
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>
az2497644017c2017-08-10 17:49:40 +030035 {onDelete && <SVGIcon color='secondary' name='trashO' data-test-id='select-action-table-delete' onClick={onDelete} iconClassName={(showDelete) ? '' : '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;