blob: 1c2c1529f2d7f4864a77590689fbb11fdeac9f4b [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
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +02006function tooltip(msg) {
7 return (
8 <Tooltip
9 className="select-action-table-error-tooltip"
10 id="error-tooltip">
11 {msg}
12 </Tooltip>
13 );
Avi Zivb8e2faf2017-07-18 19:45:38 +030014}
15
Einav Weiss Keidar7fdf7332018-03-20 14:45:40 +020016const IconWithOverlay = ({ overlayMsg }) => (
17 <OverlayTrigger placement="bottom" overlay={tooltip(overlayMsg)}>
18 <SVGIcon name="errorCircle" color="negative" />
19 </OverlayTrigger>
20);
21
22function 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
38const 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>
AviZi280f8012017-06-09 02:39:56 +030065);
66
67export default SelectActionTableRow;