@reltio/components 1.4.1908 → 1.4.1910
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/MatchRulesTooltip/MatchRulesTooltip.js +11 -7
- package/cjs/MatchRulesTooltip/MatchRulesTooltip.test.js +20 -24
- package/cjs/MatchRulesTooltip/styles.d.ts +1 -1
- package/cjs/MatchRulesTooltip/styles.js +5 -1
- package/cjs/ProfileResizablePanes/ProfileResizablePanes.spec.js +113 -68
- package/cjs/ResizablePanes/ResizablePanes.d.ts +3 -2
- package/cjs/ResizablePanes/ResizablePanes.js +83 -16
- package/cjs/ResizablePanes/ResizablePanes.test.js +289 -0
- package/cjs/ResizablePanes/styles.d.ts +1 -1
- package/cjs/ResizablePanes/styles.js +47 -38
- package/cjs/SimpleMatchRules/SimpleMatchRules.js +16 -13
- package/cjs/SimpleMatchRules/SimpleMatchRules.test.js +8 -35
- package/cjs/SimpleMatchRules/styles.d.ts +1 -1
- package/cjs/SimpleMatchRules/styles.js +8 -0
- package/cjs/SimpleMatchRulesBlock/SimpleMatchRulesBlock.js +3 -3
- package/cjs/SimpleMatchRulesBlock/SimpleMatchRulesBlock.test.js +1 -1
- package/cjs/icons/AIPowered.d.ts +5 -0
- package/cjs/icons/AIPowered.js +76 -0
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +2 -1
- package/cjs/test-utils/index.d.ts +1 -0
- package/cjs/test-utils/index.js +15 -1
- package/esm/MatchRulesTooltip/MatchRulesTooltip.js +11 -7
- package/esm/MatchRulesTooltip/MatchRulesTooltip.test.js +20 -24
- package/esm/MatchRulesTooltip/styles.d.ts +1 -1
- package/esm/MatchRulesTooltip/styles.js +5 -1
- package/esm/ProfileResizablePanes/ProfileResizablePanes.spec.js +113 -68
- package/esm/ResizablePanes/ResizablePanes.d.ts +3 -2
- package/esm/ResizablePanes/ResizablePanes.js +84 -17
- package/esm/ResizablePanes/ResizablePanes.test.js +284 -0
- package/esm/ResizablePanes/styles.d.ts +1 -1
- package/esm/ResizablePanes/styles.js +47 -38
- package/esm/SimpleMatchRules/SimpleMatchRules.js +16 -13
- package/esm/SimpleMatchRules/SimpleMatchRules.test.js +8 -35
- package/esm/SimpleMatchRules/styles.d.ts +1 -1
- package/esm/SimpleMatchRules/styles.js +8 -0
- package/esm/SimpleMatchRulesBlock/SimpleMatchRulesBlock.js +3 -3
- package/esm/SimpleMatchRulesBlock/SimpleMatchRulesBlock.test.js +1 -1
- package/esm/icons/AIPowered.d.ts +5 -0
- package/esm/icons/AIPowered.js +71 -0
- package/esm/index.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/test-utils/index.d.ts +1 -0
- package/esm/test-utils/index.js +13 -0
- package/package.json +3 -3
- package/cjs/MatchRulesTitle/MatchRulesTitle.d.ts +0 -5
- package/cjs/MatchRulesTitle/MatchRulesTitle.js +0 -13
- package/cjs/MatchRulesTitle/MatchRulesTitle.test.js +0 -18
- package/cjs/MatchRulesTitle/index.d.ts +0 -1
- package/cjs/MatchRulesTitle/index.js +0 -5
- package/cjs/ResizablePanes/ResizablePanes.spec.js +0 -192
- package/esm/MatchRulesTitle/MatchRulesTitle.d.ts +0 -5
- package/esm/MatchRulesTitle/MatchRulesTitle.js +0 -6
- package/esm/MatchRulesTitle/MatchRulesTitle.test.d.ts +0 -1
- package/esm/MatchRulesTitle/MatchRulesTitle.test.js +0 -13
- package/esm/MatchRulesTitle/index.d.ts +0 -1
- package/esm/MatchRulesTitle/index.js +0 -1
- package/esm/ResizablePanes/ResizablePanes.spec.d.ts +0 -1
- package/esm/ResizablePanes/ResizablePanes.spec.js +0 -164
- /package/cjs/{MatchRulesTitle/MatchRulesTitle.test.d.ts → ResizablePanes/ResizablePanes.test.d.ts} +0 -0
- /package/{cjs/ResizablePanes/ResizablePanes.spec.d.ts → esm/ResizablePanes/ResizablePanes.test.d.ts} +0 -0
|
@@ -1,39 +1,106 @@
|
|
|
1
|
-
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
import React, { useCallback, useMemo, useState, useRef, useEffect } from 'react';
|
|
2
13
|
import classnames from 'classnames';
|
|
3
|
-
import
|
|
14
|
+
import { Panel, PanelGroup, PanelResizeHandle } from 'react-resizable-panels';
|
|
4
15
|
import { useTheme } from '@mui/material/styles';
|
|
16
|
+
import ReactResizeDetector from 'react-resize-detector';
|
|
5
17
|
import { debounce } from '@reltio/mdm-sdk';
|
|
6
18
|
import { useStyles } from './styles';
|
|
7
19
|
var HANDLE_CHANGE_DEBOUNCE_INTERVAL = 250;
|
|
8
20
|
var isHorizontal = function (orientation) { return orientation === 'horizontal'; };
|
|
21
|
+
var isEqualSize = function (a, b) { return a.toFixed(2) === b.toFixed(2); };
|
|
9
22
|
export var ResizablePanes = function (_a) {
|
|
10
|
-
var
|
|
23
|
+
var _b;
|
|
24
|
+
var className = _a.className, children = _a.children, _c = _a.orientation, orientation = _c === void 0 ? 'vertical' : _c, _d = _a.primary, primary = _d === void 0 ? 'first' : _d, size = _a.size, minSize = _a.minSize, maxSize = _a.maxSize, allowResize = _a.allowResize, _e = _a.debounceInterval, debounceInterval = _e === void 0 ? HANDLE_CHANGE_DEBOUNCE_INTERVAL : _e, onChange = _a.onChange;
|
|
11
25
|
var styles = useStyles();
|
|
12
26
|
var theme = useTheme();
|
|
13
|
-
var
|
|
14
|
-
var
|
|
27
|
+
var panelRef = useRef();
|
|
28
|
+
var _f = useState(null), containerEl = _f[0], setContainerEl = _f[1];
|
|
29
|
+
var _g = useState(0), percentageMinSize = _g[0], setPercentageMinSize = _g[1];
|
|
30
|
+
var _h = useState(0), percentageMaxSize = _h[0], setPercentageMaxSize = _h[1];
|
|
31
|
+
var _j = useState(true), isPaneAnimationEnabled = _j[0], setIsPaneAnimationEnabled = _j[1];
|
|
15
32
|
var enableAnimation = useCallback(function () { return setIsPaneAnimationEnabled(true); }, []);
|
|
16
33
|
var disableAnimation = useCallback(function () { return setIsPaneAnimationEnabled(false); }, []);
|
|
17
|
-
var getContainerSize = function () { return (isHorizontal(orientation) ? containerEl === null || containerEl === void 0 ? void 0 : containerEl.clientHeight : containerEl === null || containerEl === void 0 ? void 0 : containerEl.clientWidth); };
|
|
34
|
+
var getContainerSize = useCallback(function () { return (isHorizontal(orientation) ? containerEl === null || containerEl === void 0 ? void 0 : containerEl.clientHeight : containerEl === null || containerEl === void 0 ? void 0 : containerEl.clientWidth); }, [containerEl, orientation]);
|
|
35
|
+
if (typeof size === 'number' && size < 0) {
|
|
36
|
+
size = (getContainerSize() || 0) + size;
|
|
37
|
+
}
|
|
38
|
+
var convertSize = useCallback(function (size) {
|
|
39
|
+
if (typeof size === 'string' && size.endsWith('%')) {
|
|
40
|
+
return +size.replace('%', '');
|
|
41
|
+
}
|
|
42
|
+
if (typeof size === 'string' && size.endsWith('px')) {
|
|
43
|
+
size = size.replace('px', '');
|
|
44
|
+
}
|
|
45
|
+
return isNaN(+size) ? null : (+size / getContainerSize()) * 100;
|
|
46
|
+
}, [getContainerSize]);
|
|
47
|
+
var convertMinMaxSize = useCallback(function (size, minMaxSize) {
|
|
48
|
+
if (size === 0 || size === 100)
|
|
49
|
+
return 0;
|
|
50
|
+
return convertSize(minMaxSize) || 0;
|
|
51
|
+
}, [convertSize]);
|
|
52
|
+
var actualizeSizes = useCallback(function () {
|
|
53
|
+
if (containerEl && panelRef.current) {
|
|
54
|
+
var convertedSize = convertSize(size);
|
|
55
|
+
if (convertedSize != null && !isNaN(convertedSize)) {
|
|
56
|
+
setPercentageMaxSize(convertMinMaxSize(convertedSize, maxSize));
|
|
57
|
+
setPercentageMinSize(convertMinMaxSize(convertedSize, minSize));
|
|
58
|
+
panelRef.current.resize(convertedSize);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, [convertSize, convertMinMaxSize, minSize, maxSize, size, containerEl]);
|
|
62
|
+
useEffect(function () {
|
|
63
|
+
actualizeSizes();
|
|
64
|
+
}, [actualizeSizes, percentageMaxSize, percentageMinSize]);
|
|
18
65
|
var handleChange = useCallback(debounce(function (size) {
|
|
66
|
+
if (size === undefined)
|
|
67
|
+
return;
|
|
19
68
|
var containerSize = getContainerSize();
|
|
20
69
|
onChange({
|
|
21
|
-
percentageSize:
|
|
22
|
-
isMaxSize: +
|
|
23
|
-
|
|
24
|
-
|
|
70
|
+
percentageSize: size + '%',
|
|
71
|
+
isMaxSize: +percentageMaxSize > 0
|
|
72
|
+
? isEqualSize(size, percentageMaxSize)
|
|
73
|
+
: isEqualSize(size, 100 + percentageMaxSize),
|
|
74
|
+
isMinSize: isEqualSize(size, percentageMinSize),
|
|
75
|
+
size: Math.round((size * containerSize) / 100)
|
|
25
76
|
});
|
|
26
|
-
}, debounceInterval), [onChange,
|
|
77
|
+
}, debounceInterval), [onChange, percentageMaxSize, percentageMinSize, getContainerSize]);
|
|
78
|
+
var handleDragging = useCallback(function (isDragging) {
|
|
79
|
+
if (isDragging) {
|
|
80
|
+
// Why do we need handleChange() here?
|
|
81
|
+
// Case - user resized panels, and then immediately started resizing again.
|
|
82
|
+
// We need to prevent onChange calling with "previous" data (handleChange is debounced calling of onChange)
|
|
83
|
+
handleChange();
|
|
84
|
+
disableAnimation();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
handleChange(panelRef.current.getSize());
|
|
88
|
+
enableAnimation();
|
|
89
|
+
}
|
|
90
|
+
}, [disableAnimation, enableAnimation, handleChange]);
|
|
27
91
|
var paneAnimationStyle = useMemo(function () { return ({
|
|
28
|
-
transition: theme.transitions.create(
|
|
92
|
+
transition: theme.transitions.create('flex', {
|
|
29
93
|
easing: theme.transitions.easing.sharp,
|
|
30
94
|
duration: theme.transitions.duration.leavingScreen
|
|
31
95
|
})
|
|
32
|
-
}); }, [
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
96
|
+
}); }, [theme]);
|
|
97
|
+
var primaryPanelProps = __assign(__assign({ className: styles.panel, minSize: percentageMinSize }, (percentageMaxSize > 0 ? { maxSize: percentageMaxSize } : {})), { ref: panelRef, style: isPaneAnimationEnabled ? paneAnimationStyle : undefined });
|
|
98
|
+
var secondaryPanelProps = __assign({ className: styles.panel, style: isPaneAnimationEnabled ? paneAnimationStyle : undefined }, (percentageMaxSize < 0 ? { minSize: -percentageMaxSize } : {}));
|
|
36
99
|
return (React.createElement("div", { ref: setContainerEl, className: classnames(styles.container, className) },
|
|
37
|
-
React.createElement(
|
|
100
|
+
React.createElement(ReactResizeDetector, { handleHeight: isHorizontal(orientation), handleWidth: !isHorizontal(orientation), onResize: actualizeSizes, refreshMode: "debounce", refreshRate: 50 }),
|
|
101
|
+
React.createElement(PanelGroup, { direction: isHorizontal(orientation) ? 'vertical' : 'horizontal' },
|
|
102
|
+
React.createElement(Panel, __assign({}, (primary === 'first' ? primaryPanelProps : secondaryPanelProps)), children[0]),
|
|
103
|
+
React.createElement(PanelResizeHandle, { className: classnames(styles.resizer, styles[orientation], (_b = {}, _b[styles.disabled] = !allowResize, _b)), disabled: !allowResize, hitAreaMargins: { coarse: 0, fine: 0 }, onDragging: handleDragging }),
|
|
104
|
+
React.createElement(Panel, __assign({}, (primary === 'second' ? primaryPanelProps : secondaryPanelProps)), children[1]))));
|
|
38
105
|
};
|
|
39
106
|
ResizablePanes.displayName = 'ResizablePanes';
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import React from 'react';
|
|
49
|
+
import { render, screen } from '@testing-library/react';
|
|
50
|
+
import userEvent from '@testing-library/user-event';
|
|
51
|
+
import { ResizablePanes } from './ResizablePanes';
|
|
52
|
+
import { delayPromise } from '../test-utils';
|
|
53
|
+
var defaultProps = {
|
|
54
|
+
allowResize: true,
|
|
55
|
+
children: []
|
|
56
|
+
};
|
|
57
|
+
var setUp = function (props) {
|
|
58
|
+
if (props === void 0) { props = defaultProps; }
|
|
59
|
+
var user = userEvent.setup();
|
|
60
|
+
return __assign(__assign({}, render(React.createElement(ResizablePanes, __assign({}, props),
|
|
61
|
+
React.createElement("div", null, "Panel 1 content"),
|
|
62
|
+
React.createElement("div", null, "Panel 2 content")))), { user: user });
|
|
63
|
+
};
|
|
64
|
+
var getPanel1 = function (container) { return container.querySelectorAll('[data-panel-id]')[0]; };
|
|
65
|
+
var getPanel2 = function (container) { return container.querySelectorAll('[data-panel-id]')[1]; };
|
|
66
|
+
var getResizeHandle = function (container) { return container.querySelector('[data-resize-handle]'); };
|
|
67
|
+
var isResizingDisabled = function (container) {
|
|
68
|
+
return getResizeHandle(container).getAttribute('data-panel-resize-handle-enabled') === 'false';
|
|
69
|
+
};
|
|
70
|
+
var checkPanelSize = function (panel, size) { return expect(panel.getAttribute('data-panel-size')).toBe(size); };
|
|
71
|
+
var moveResizeHandle = function (container, user, from, to) { return __awaiter(void 0, void 0, void 0, function () {
|
|
72
|
+
var resizeHandle;
|
|
73
|
+
return __generator(this, function (_a) {
|
|
74
|
+
switch (_a.label) {
|
|
75
|
+
case 0:
|
|
76
|
+
resizeHandle = getResizeHandle(container);
|
|
77
|
+
return [4 /*yield*/, user.pointer([
|
|
78
|
+
{
|
|
79
|
+
keys: '[MouseLeft>]',
|
|
80
|
+
target: resizeHandle,
|
|
81
|
+
coords: {
|
|
82
|
+
x: from.x,
|
|
83
|
+
y: from.y
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
target: resizeHandle,
|
|
88
|
+
coords: {
|
|
89
|
+
x: to.x,
|
|
90
|
+
y: to.y
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
keys: '[/MouseLeft]',
|
|
95
|
+
target: resizeHandle,
|
|
96
|
+
coords: {
|
|
97
|
+
x: to.x,
|
|
98
|
+
y: to.y
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
])];
|
|
102
|
+
case 1:
|
|
103
|
+
_a.sent();
|
|
104
|
+
return [2 /*return*/];
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}); };
|
|
108
|
+
describe('ResizablePanes tests', function () {
|
|
109
|
+
beforeAll(function () {
|
|
110
|
+
jest.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(1000);
|
|
111
|
+
jest.spyOn(HTMLElement.prototype, 'getBoundingClientRect').mockReturnValue({
|
|
112
|
+
width: 1000,
|
|
113
|
+
height: 1000,
|
|
114
|
+
top: 0,
|
|
115
|
+
left: 0,
|
|
116
|
+
right: 1000,
|
|
117
|
+
bottom: 1000,
|
|
118
|
+
x: 0,
|
|
119
|
+
y: 0,
|
|
120
|
+
toJSON: function () { return ''; }
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
it('should render main parts', function () {
|
|
124
|
+
var container = setUp().container;
|
|
125
|
+
expect(getPanel1(container)).toBeInTheDocument();
|
|
126
|
+
expect(screen.getByText('Panel 1 content')).toBeInTheDocument();
|
|
127
|
+
expect(getPanel2(container)).toBeInTheDocument();
|
|
128
|
+
expect(screen.getByText('Panel 2 content')).toBeInTheDocument();
|
|
129
|
+
expect(getResizeHandle(container)).toBeInTheDocument();
|
|
130
|
+
});
|
|
131
|
+
it('should allow to resize the panels', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
132
|
+
var _a, container, user;
|
|
133
|
+
return __generator(this, function (_b) {
|
|
134
|
+
switch (_b.label) {
|
|
135
|
+
case 0:
|
|
136
|
+
_a = setUp(__assign(__assign({}, defaultProps), { size: '320px', minSize: '320px', maxSize: '640px', onChange: function () { }, debounceInterval: 0 })), container = _a.container, user = _a.user;
|
|
137
|
+
expect(isResizingDisabled(container)).toBe(false);
|
|
138
|
+
checkPanelSize(getPanel1(container), '32.0');
|
|
139
|
+
checkPanelSize(getPanel2(container), '68.0');
|
|
140
|
+
// move mouse to an x-coordinate between minSize and maxSize
|
|
141
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 320, y: 0 }, { x: 500, y: 20 })];
|
|
142
|
+
case 1:
|
|
143
|
+
// move mouse to an x-coordinate between minSize and maxSize
|
|
144
|
+
_b.sent();
|
|
145
|
+
checkPanelSize(getPanel1(container), '50.0');
|
|
146
|
+
checkPanelSize(getPanel2(container), '50.0');
|
|
147
|
+
// move mouse to a larger x-coordinate than max size
|
|
148
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 500, y: 0 }, { x: 650, y: 20 })];
|
|
149
|
+
case 2:
|
|
150
|
+
// move mouse to a larger x-coordinate than max size
|
|
151
|
+
_b.sent();
|
|
152
|
+
checkPanelSize(getPanel1(container), '64.0');
|
|
153
|
+
checkPanelSize(getPanel2(container), '36.0');
|
|
154
|
+
// move mouse to a smaller x-coordinate than min size
|
|
155
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 640, y: 0 }, { x: 310, y: 20 })];
|
|
156
|
+
case 3:
|
|
157
|
+
// move mouse to a smaller x-coordinate than min size
|
|
158
|
+
_b.sent();
|
|
159
|
+
checkPanelSize(getPanel1(container), '32.0');
|
|
160
|
+
checkPanelSize(getPanel2(container), '68.0');
|
|
161
|
+
return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
}); });
|
|
165
|
+
it('should call onChange prop with debounce on panels resizing', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
166
|
+
var debounceInterval, props, _a, user, container;
|
|
167
|
+
return __generator(this, function (_b) {
|
|
168
|
+
switch (_b.label) {
|
|
169
|
+
case 0:
|
|
170
|
+
debounceInterval = 200;
|
|
171
|
+
props = __assign(__assign({}, defaultProps), { size: 320, debounceInterval: debounceInterval, onChange: jest.fn() });
|
|
172
|
+
_a = setUp(props), user = _a.user, container = _a.container;
|
|
173
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 320, y: 0 }, { x: 510, y: 20 })];
|
|
174
|
+
case 1:
|
|
175
|
+
_b.sent();
|
|
176
|
+
expect(props.onChange).not.toHaveBeenCalled();
|
|
177
|
+
return [4 /*yield*/, delayPromise(debounceInterval + 1)];
|
|
178
|
+
case 2:
|
|
179
|
+
_b.sent();
|
|
180
|
+
expect(props.onChange).toHaveBeenCalledWith({
|
|
181
|
+
isMaxSize: false,
|
|
182
|
+
isMinSize: false,
|
|
183
|
+
percentageSize: '51%',
|
|
184
|
+
size: 510
|
|
185
|
+
});
|
|
186
|
+
return [2 /*return*/];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}); });
|
|
190
|
+
it('should set correct isMaxSize in props.onChange argument for positive props.maxSize', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
191
|
+
var debounceInterval, props, _a, user, container;
|
|
192
|
+
return __generator(this, function (_b) {
|
|
193
|
+
switch (_b.label) {
|
|
194
|
+
case 0:
|
|
195
|
+
debounceInterval = 0;
|
|
196
|
+
props = __assign(__assign({}, defaultProps), { size: 320, maxSize: 500, debounceInterval: debounceInterval, onChange: jest.fn() });
|
|
197
|
+
_a = setUp(props), user = _a.user, container = _a.container;
|
|
198
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 320, y: 0 }, { x: 510, y: 20 })];
|
|
199
|
+
case 1:
|
|
200
|
+
_b.sent();
|
|
201
|
+
expect(props.onChange).toHaveBeenCalledWith({
|
|
202
|
+
isMaxSize: true,
|
|
203
|
+
isMinSize: false,
|
|
204
|
+
percentageSize: '50%',
|
|
205
|
+
size: 500
|
|
206
|
+
});
|
|
207
|
+
return [2 /*return*/];
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
}); });
|
|
211
|
+
it('should set correct isMaxSize in props.onChange argument for negative props.maxSize', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
212
|
+
var debounceInterval, props, _a, user, container;
|
|
213
|
+
return __generator(this, function (_b) {
|
|
214
|
+
switch (_b.label) {
|
|
215
|
+
case 0:
|
|
216
|
+
debounceInterval = 0;
|
|
217
|
+
props = __assign(__assign({}, defaultProps), { size: 320, maxSize: -200, debounceInterval: debounceInterval, onChange: jest.fn() });
|
|
218
|
+
_a = setUp(props), user = _a.user, container = _a.container;
|
|
219
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 320, y: 0 }, { x: 800, y: 20 })];
|
|
220
|
+
case 1:
|
|
221
|
+
_b.sent();
|
|
222
|
+
expect(props.onChange).toHaveBeenCalledWith({
|
|
223
|
+
isMaxSize: true,
|
|
224
|
+
isMinSize: false,
|
|
225
|
+
percentageSize: '80%',
|
|
226
|
+
size: 800
|
|
227
|
+
});
|
|
228
|
+
return [2 /*return*/];
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
}); });
|
|
232
|
+
it('should set correct isMaxSize in props.onChange argument if props.maxSize omitted', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
233
|
+
var debounceInterval, props, _a, user, container;
|
|
234
|
+
return __generator(this, function (_b) {
|
|
235
|
+
switch (_b.label) {
|
|
236
|
+
case 0:
|
|
237
|
+
debounceInterval = 0;
|
|
238
|
+
props = __assign(__assign({}, defaultProps), { size: 320, debounceInterval: debounceInterval, onChange: jest.fn() });
|
|
239
|
+
_a = setUp(props), user = _a.user, container = _a.container;
|
|
240
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 320, y: 0 }, { x: 1000, y: 20 })];
|
|
241
|
+
case 1:
|
|
242
|
+
_b.sent();
|
|
243
|
+
expect(props.onChange).toHaveBeenCalledWith({
|
|
244
|
+
isMaxSize: true,
|
|
245
|
+
isMinSize: false,
|
|
246
|
+
percentageSize: '100%',
|
|
247
|
+
size: 1000
|
|
248
|
+
});
|
|
249
|
+
return [2 /*return*/];
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}); });
|
|
253
|
+
it('should set correct isMinSize in props.onChange argument for positive props.minSize', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
254
|
+
var debounceInterval, props, _a, user, container;
|
|
255
|
+
return __generator(this, function (_b) {
|
|
256
|
+
switch (_b.label) {
|
|
257
|
+
case 0:
|
|
258
|
+
debounceInterval = 0;
|
|
259
|
+
props = __assign(__assign({}, defaultProps), { size: 320, minSize: 200, debounceInterval: debounceInterval, onChange: jest.fn() });
|
|
260
|
+
_a = setUp(props), user = _a.user, container = _a.container;
|
|
261
|
+
return [4 /*yield*/, moveResizeHandle(container, user, { x: 320, y: 0 }, { x: 200, y: 20 })];
|
|
262
|
+
case 1:
|
|
263
|
+
_b.sent();
|
|
264
|
+
expect(props.onChange).toHaveBeenCalledWith({
|
|
265
|
+
isMaxSize: false,
|
|
266
|
+
isMinSize: true,
|
|
267
|
+
percentageSize: '20%',
|
|
268
|
+
size: 200
|
|
269
|
+
});
|
|
270
|
+
return [2 /*return*/];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}); });
|
|
274
|
+
it('should apply negative size correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
275
|
+
var props, container;
|
|
276
|
+
return __generator(this, function (_a) {
|
|
277
|
+
props = __assign(__assign({}, defaultProps), { size: -40 });
|
|
278
|
+
container = setUp(props).container;
|
|
279
|
+
checkPanelSize(getPanel1(container), '96.0');
|
|
280
|
+
checkPanelSize(getPanel2(container), '4.0');
|
|
281
|
+
return [2 /*return*/];
|
|
282
|
+
});
|
|
283
|
+
}); });
|
|
284
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"container">;
|
|
1
|
+
export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"container" | "horizontal" | "vertical" | "resizer" | "disabled" | "panel">;
|
|
@@ -1,46 +1,55 @@
|
|
|
1
1
|
import { makeStyles } from '@mui/styles';
|
|
2
2
|
export var useStyles = makeStyles(function () { return ({
|
|
3
3
|
container: {
|
|
4
|
-
position: 'relative'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
position: 'relative'
|
|
5
|
+
},
|
|
6
|
+
panel: {
|
|
7
|
+
position: 'relative'
|
|
8
|
+
},
|
|
9
|
+
horizontal: {},
|
|
10
|
+
vertical: {},
|
|
11
|
+
disabled: {},
|
|
12
|
+
resizer: {
|
|
13
|
+
zIndex: 1,
|
|
14
|
+
boxSizing: 'border-box',
|
|
15
|
+
backgroundClip: 'padding-box',
|
|
16
|
+
'&$disabled': {
|
|
17
|
+
cursor: 'initial',
|
|
18
|
+
height: 0,
|
|
19
|
+
margin: 0
|
|
20
|
+
},
|
|
21
|
+
'&$horizontal': {
|
|
22
|
+
height: '11px',
|
|
23
|
+
backgroundImage: 'linear-gradient(rgba(0,0,0,0.33), rgba(0,0,0,0.33))',
|
|
24
|
+
backgroundRepeat: 'no-repeat',
|
|
25
|
+
backgroundSize: '100% 1px',
|
|
26
|
+
backgroundPosition: 'top',
|
|
27
|
+
width: '100%',
|
|
28
|
+
marginBottom: '-10px',
|
|
29
|
+
'&$disabled': {
|
|
30
|
+
background: 'transparent'
|
|
13
31
|
},
|
|
14
|
-
'
|
|
15
|
-
|
|
16
|
-
backgroundImage: 'linear-gradient(rgba(0,0,0,0.
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
32
|
+
'&:not($disabled):hover': {
|
|
33
|
+
cursor: 'ns-resize',
|
|
34
|
+
backgroundImage: 'linear-gradient(rgba(0, 114, 206, 0), rgba(0, 114, 206, 0.35), rgba(0, 114, 206, 1))',
|
|
35
|
+
backgroundSize: '100% 3px'
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
'&$vertical': {
|
|
39
|
+
width: '11px',
|
|
40
|
+
backgroundImage: 'linear-gradient(rgba(0,0,0,0.33), rgba(0,0,0,0.33))',
|
|
41
|
+
backgroundRepeat: 'no-repeat',
|
|
42
|
+
backgroundSize: '1px 100%',
|
|
43
|
+
backgroundPosition: 'left',
|
|
44
|
+
height: '100%',
|
|
45
|
+
marginRight: '-10px',
|
|
46
|
+
'&$disabled': {
|
|
47
|
+
background: 'transparent'
|
|
30
48
|
},
|
|
31
|
-
'
|
|
32
|
-
|
|
33
|
-
backgroundImage: 'linear-gradient(rgba(0,
|
|
34
|
-
|
|
35
|
-
backgroundSize: '1px 100%',
|
|
36
|
-
backgroundPosition: 'left',
|
|
37
|
-
height: '100%',
|
|
38
|
-
marginRight: '-10px',
|
|
39
|
-
'&:not(.disabled):hover': {
|
|
40
|
-
cursor: 'col-resize',
|
|
41
|
-
backgroundImage: 'linear-gradient(to left, rgba(0, 114, 206, 0.35), rgba(0, 114, 206, 1), rgba(0, 114, 206, 0.35))',
|
|
42
|
-
backgroundSize: '3px 100%'
|
|
43
|
-
}
|
|
49
|
+
'&:not($disabled):hover': {
|
|
50
|
+
cursor: 'ew-resize',
|
|
51
|
+
backgroundImage: 'linear-gradient(to left, rgba(0, 114, 206, 0.35), rgba(0, 114, 206, 1), rgba(0, 114, 206, 0.35))',
|
|
52
|
+
backgroundSize: '3px 100%'
|
|
44
53
|
}
|
|
45
54
|
}
|
|
46
55
|
}
|
|
@@ -4,22 +4,25 @@ import classnames from 'classnames';
|
|
|
4
4
|
import { getMatchRuleSummary, formatRelevanceScore } from '@reltio/mdm-sdk';
|
|
5
5
|
import Tooltip from '@mui/material/Tooltip';
|
|
6
6
|
import NegativeRuleIcon from '../icons/NegativeRuleIcon';
|
|
7
|
-
import { MatchRulesTitle } from '../MatchRulesTitle';
|
|
8
7
|
import { useStyles } from './styles';
|
|
9
8
|
export var SimpleMatchRules = function (_a) {
|
|
10
9
|
var isMlMatch = _a.isMlMatch, matchRules = _a.matchRules, className = _a.className, matchRuleSummaries = _a.matchRuleSummaries;
|
|
11
10
|
var styles = useStyles();
|
|
11
|
+
var hasMatchRules = matchRules.length > 0;
|
|
12
|
+
var showTitle = !isMlMatch && hasMatchRules;
|
|
12
13
|
return (React.createElement("div", { "data-reltio-id": "simple-match-rules", className: classnames(styles.container, className) },
|
|
13
|
-
React.createElement("div", { className: styles.
|
|
14
|
-
React.createElement(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
React.createElement("div", { className: showTitle ? styles.bodyWithMargin : styles.bodyWithoutMargin },
|
|
15
|
+
showTitle && React.createElement("div", { className: styles.title }, i18n.text('Match rules')),
|
|
16
|
+
React.createElement("div", { className: styles.labelsContainer }, hasMatchRules
|
|
17
|
+
? matchRules.map(function (matchRule) {
|
|
18
|
+
var matchRuleSummary = getMatchRuleSummary(matchRuleSummaries, matchRule.uri);
|
|
19
|
+
var relevancePercentage = formatRelevanceScore(matchRuleSummary);
|
|
20
|
+
return (React.createElement("div", { className: styles.matchRuleInfo, key: matchRule.uri, "data-reltio-id": "match-rule-info" },
|
|
21
|
+
React.createElement("div", { className: styles.matchRuleLabel },
|
|
22
|
+
'- ',
|
|
23
|
+
matchRule.negativeRule && (React.createElement(NegativeRuleIcon, { className: styles.negativeRuleIcon })), "".concat(matchRule.label)),
|
|
24
|
+
relevancePercentage && (React.createElement(Tooltip, { title: i18n.text('Relevance score') },
|
|
25
|
+
React.createElement("div", { className: styles.relevanceScore }, relevancePercentage)))));
|
|
26
|
+
})
|
|
27
|
+
: null))));
|
|
25
28
|
};
|
|
@@ -1,45 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { MatchRulesTitle } from '../MatchRulesTitle';
|
|
4
|
-
import NegativeRuleIcon from '../icons/NegativeRuleIcon';
|
|
2
|
+
import { render, screen } from '@testing-library/react';
|
|
5
3
|
import { SimpleMatchRules } from './SimpleMatchRules';
|
|
6
4
|
describe('SimpleMatchRules tests', function () {
|
|
7
|
-
var getMatchRulesTitle = function (component) { return component.find(MatchRulesTitle); };
|
|
8
|
-
var getLabelContainer = function (component) { return component.find('.labelsContainer'); };
|
|
9
|
-
var getContainer = function (component) { return component.find('.container'); };
|
|
10
|
-
it('should provide isMlMatch prop to MatchRulesTitle', function () {
|
|
11
|
-
var component = shallow(React.createElement(SimpleMatchRules, { isMlMatch: true, matchRules: [] }));
|
|
12
|
-
expect(getMatchRulesTitle(component).prop('isMlMatch')).toBe(true);
|
|
13
|
-
component.setProps({ isMlMatch: false });
|
|
14
|
-
expect(getMatchRulesTitle(component).prop('isMlMatch')).toBe(false);
|
|
15
|
-
});
|
|
16
|
-
it('should render match rule correctly', function () {
|
|
17
|
-
var matchRules = [
|
|
18
|
-
{ uri: 'uri1', label: 'label1' },
|
|
19
|
-
{ uri: 'uri2', label: 'label2' }
|
|
20
|
-
];
|
|
21
|
-
var component = shallow(React.createElement(SimpleMatchRules, { matchRules: matchRules }));
|
|
22
|
-
var labelContainer = getLabelContainer(component);
|
|
23
|
-
expect(labelContainer.children()).toHaveLength(2);
|
|
24
|
-
expect(labelContainer.childAt(0).text()).toContain(matchRules[0].label);
|
|
25
|
-
expect(labelContainer.childAt(1).text()).toContain(matchRules[1].label);
|
|
26
|
-
});
|
|
27
|
-
it('should provide className prop to container', function () {
|
|
28
|
-
var className = 'myClassName';
|
|
29
|
-
var component = shallow(React.createElement(SimpleMatchRules, { className: className, matchRules: [] }));
|
|
30
|
-
expect(getContainer(component).prop('className')).toContain(className);
|
|
31
|
-
});
|
|
32
5
|
it('should render negative rule correctly', function () {
|
|
33
6
|
var matchRules = [
|
|
34
7
|
{ uri: 'uri1', label: 'label1' },
|
|
35
8
|
{ uri: 'uri2', label: 'label2', negativeRule: {} }
|
|
36
9
|
];
|
|
37
|
-
|
|
38
|
-
var
|
|
39
|
-
expect(
|
|
40
|
-
expect(
|
|
41
|
-
expect(
|
|
42
|
-
expect(
|
|
43
|
-
expect(
|
|
10
|
+
render(React.createElement(SimpleMatchRules, { matchRules: matchRules }));
|
|
11
|
+
var ruleItems = screen.getAllByText(/^-\s+/);
|
|
12
|
+
expect(ruleItems).toHaveLength(2);
|
|
13
|
+
expect(ruleItems[0]).toHaveTextContent(matchRules[0].label);
|
|
14
|
+
expect(ruleItems[0].querySelector('svg')).not.toBeInTheDocument();
|
|
15
|
+
expect(ruleItems[1]).toHaveTextContent(matchRules[1].label);
|
|
16
|
+
expect(ruleItems[1].querySelector('svg')).toBeInTheDocument();
|
|
44
17
|
});
|
|
45
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"container" | "title" | "relevanceScore" | "negativeRuleIcon" | "labelsContainer" | "matchRuleInfo" | "matchRuleLabel">;
|
|
1
|
+
export declare const useStyles: (props?: any) => import("@mui/styles").ClassNameMap<"container" | "title" | "relevanceScore" | "bodyWithMargin" | "bodyWithoutMargin" | "negativeRuleIcon" | "labelsContainer" | "matchRuleInfo" | "matchRuleLabel">;
|
|
@@ -8,6 +8,14 @@ export var useStyles = makeStyles(function (theme) { return ({
|
|
|
8
8
|
color: theme.palette.text.secondary,
|
|
9
9
|
marginBottom: '7px'
|
|
10
10
|
},
|
|
11
|
+
bodyWithMargin: {
|
|
12
|
+
fontWeight: 'normal',
|
|
13
|
+
marginLeft: '16px'
|
|
14
|
+
},
|
|
15
|
+
bodyWithoutMargin: {
|
|
16
|
+
fontWeight: 'normal',
|
|
17
|
+
marginLeft: '0px'
|
|
18
|
+
},
|
|
11
19
|
labelsContainer: {
|
|
12
20
|
color: theme.palette.text.primary,
|
|
13
21
|
marginBottom: '8px'
|
|
@@ -4,7 +4,7 @@ import { MatchRulesTooltip } from '../MatchRulesTooltip';
|
|
|
4
4
|
import { SimpleMatchRules } from '../SimpleMatchRules';
|
|
5
5
|
import { MatchRulesBadge } from '../MatchRulesBadge';
|
|
6
6
|
import { withTooltip } from '../HOCs/withTooltip';
|
|
7
|
-
import
|
|
7
|
+
import AIPowered from '../icons/AIPowered';
|
|
8
8
|
import { useStyles } from './styles';
|
|
9
9
|
export var MatchRuleBadgeWithTooltip = withTooltip(MatchRulesBadge);
|
|
10
10
|
export var SimpleMatchRulesBlock = function (_a) {
|
|
@@ -14,7 +14,7 @@ export var SimpleMatchRulesBlock = function (_a) {
|
|
|
14
14
|
var handleOnExpand = useCallback(function () { return setExpanded(function (expand) { return !expand; }); }, []);
|
|
15
15
|
return (React.createElement("div", { className: styles.container, "data-reltio-id": "simple-match-rules-block" },
|
|
16
16
|
React.createElement(MatchRuleBadgeWithTooltip, { tooltipTitle: React.createElement(MatchRulesTooltip, { matchRules: matchRules, isMlMatch: isMlMatch }), tooltipPlacement: "bottom-start", onExpand: handleOnExpand, expanded: expanded }, isMlMatch ? (React.createElement(React.Fragment, null,
|
|
17
|
-
React.createElement(
|
|
18
|
-
i18n.text('
|
|
17
|
+
React.createElement(AIPowered, { className: styles.icon }),
|
|
18
|
+
i18n.text('AI-powered'))) : (i18n.text('Rules'))),
|
|
19
19
|
expanded ? (React.createElement(SimpleMatchRules, { className: styles.rulesContainer, matchRules: matchRules, isMlMatch: isMlMatch, matchRuleSummaries: matchRuleSummaries })) : null));
|
|
20
20
|
};
|