@reltio/components 1.4.2049 → 1.4.2051

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.
@@ -30,7 +30,10 @@ export var BarChart = function (_a) {
30
30
  var width = _a.width, height = _a.height, data = _a.data, _b = _a.options, options = _b === void 0 ? {} : _b, onItemClick = _a.onItemClick;
31
31
  var _c = getBarChartSettings(options), barChart = _c.barChart, cartesianGrid = _c.cartesianGrid, bar = _c.bar, tooltip = _c.tooltip, xAxis = _c.xAxis, yAxis = _c.yAxis;
32
32
  var _d = useDynamicYAxisWidth({ chartYAxisProps: yAxis }), chartRef = _d.chartRef, dynamicYAxisWidth = __rest(_d, ["chartRef"]);
33
- var onBarClick = onItemClick && (function (data) { return onItemClick(data.group); });
33
+ var onBarClick = onItemClick && (function (_a) {
34
+ var group = _a.group;
35
+ return onItemClick(group);
36
+ });
34
37
  var clickable = useClickableChartStyle(onBarClick);
35
38
  return (React.createElement(BarChartWidget, __assign({ width: width, height: height, data: data }, barChart, { ref: chartRef }),
36
39
  React.createElement(CartesianGrid, __assign({}, cartesianGrid)),
@@ -6,6 +6,7 @@ type Props = {
6
6
  onChangeColumns: (columns: string[]) => void;
7
7
  title?: string;
8
8
  tooltipTitle?: string;
9
+ inputPlaceholder?: string;
9
10
  };
10
- export declare const ColumnsSettings: ({ columnsData, selectedColumns, onChangeColumns, title, tooltipTitle }: Props) => React.JSX.Element;
11
+ export declare const ColumnsSettings: ({ columnsData, selectedColumns, onChangeColumns, title, tooltipTitle, inputPlaceholder }: Props) => React.JSX.Element;
11
12
  export {};
@@ -6,7 +6,7 @@ import { SmallIconButtonWithTooltip } from '../SmallIconButton';
6
6
  import { ColumnsSettingsPopup } from './components/ColumnsSettingsPopup';
7
7
  import { getChildColumns, isColumnSelected } from './helpers';
8
8
  export var ColumnsSettings = function (_a) {
9
- var columnsData = _a.columnsData, selectedColumns = _a.selectedColumns, onChangeColumns = _a.onChangeColumns, title = _a.title, tooltipTitle = _a.tooltipTitle;
9
+ var columnsData = _a.columnsData, selectedColumns = _a.selectedColumns, onChangeColumns = _a.onChangeColumns, title = _a.title, tooltipTitle = _a.tooltipTitle, inputPlaceholder = _a.inputPlaceholder;
10
10
  var _b = useState(null), anchorEl = _b[0], setAnchorEl = _b[1];
11
11
  var openPopup = function (event) { return setAnchorEl(event.currentTarget); };
12
12
  var closePopup = function () { return setAnchorEl(null); };
@@ -19,5 +19,5 @@ export var ColumnsSettings = function (_a) {
19
19
  }, [selectedColumns, onChangeColumns]);
20
20
  return (React.createElement(React.Fragment, null,
21
21
  React.createElement(SmallIconButtonWithTooltip, { "data-reltio-id": "reltio-columns-settings-button", tooltipTitle: tooltipTitle || i18n.text('Show/hide columns'), size: "L", icon: TableIcon, onClick: openPopup }),
22
- React.createElement(ColumnsSettingsPopup, { onColumnClick: handleColumnClick, anchorEl: anchorEl, columnsData: columnsData, onClose: closePopup, title: title, selectedColumns: selectedColumns })));
22
+ React.createElement(ColumnsSettingsPopup, { onColumnClick: handleColumnClick, anchorEl: anchorEl, columnsData: columnsData, onClose: closePopup, title: title, inputPlaceholder: inputPlaceholder, selectedColumns: selectedColumns })));
23
23
  };
@@ -105,6 +105,20 @@ describe('ColumnsSettings', function () {
105
105
  }
106
106
  });
107
107
  }); });
108
+ it('should use custom placeholder', function () { return __awaiter(void 0, void 0, void 0, function () {
109
+ var user;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ user = setUp({ props: { inputPlaceholder: 'test placeholder' } }).user;
114
+ return [4 /*yield*/, user.click(screen.getByTestId('reltio-columns-settings-button'))];
115
+ case 1:
116
+ _a.sent();
117
+ expect(screen.getByRole('textbox')).toHaveAttribute('placeholder', 'test placeholder');
118
+ return [2 /*return*/];
119
+ }
120
+ });
121
+ }); });
108
122
  });
109
123
  describe('plain columns data behavior', function () {
110
124
  var columnsData = [
@@ -4,6 +4,7 @@ type Props = {
4
4
  anchorEl: HTMLElement;
5
5
  onClose: () => void;
6
6
  title?: string;
7
+ inputPlaceholder?: string;
7
8
  columnsData: GroupedColumnsData[];
8
9
  onColumnClick: (column: {
9
10
  id: string;
@@ -11,5 +12,5 @@ type Props = {
11
12
  selectedColumns: string[];
12
13
  hideCheckBox?: boolean;
13
14
  };
14
- export declare const ColumnsSettingsPopup: ({ anchorEl, onClose, title, columnsData, onColumnClick, selectedColumns, hideCheckBox }: Props) => React.JSX.Element;
15
+ export declare const ColumnsSettingsPopup: ({ anchorEl, onClose, title, inputPlaceholder, columnsData, onColumnClick, selectedColumns, hideCheckBox }: Props) => React.JSX.Element;
15
16
  export {};
@@ -14,7 +14,7 @@ var DEFAULT_MIN_CONTAINER_WIDTH = 308;
14
14
  var CONTAINER_HEADER_HEIGHT = 108;
15
15
  var MIN_CONTAINER_HEIGHT = 140;
16
16
  export var ColumnsSettingsPopup = function (_a) {
17
- var anchorEl = _a.anchorEl, onClose = _a.onClose, title = _a.title, columnsData = _a.columnsData, onColumnClick = _a.onColumnClick, selectedColumns = _a.selectedColumns, hideCheckBox = _a.hideCheckBox;
17
+ var anchorEl = _a.anchorEl, onClose = _a.onClose, title = _a.title, inputPlaceholder = _a.inputPlaceholder, columnsData = _a.columnsData, onColumnClick = _a.onColumnClick, selectedColumns = _a.selectedColumns, hideCheckBox = _a.hideCheckBox;
18
18
  var styles = useStyles();
19
19
  var _b = useState(''), filterText = _b[0], setFilterText = _b[1];
20
20
  var clearFilter = function () { return setFilterText(''); };
@@ -39,6 +39,6 @@ export var ColumnsSettingsPopup = function (_a) {
39
39
  };
40
40
  var listHeight = Math.min(MAX_LIST_CONTAINER_HEIGHT, ITEM_HEIGHT * items.length);
41
41
  var containerHeight = Math.max(MIN_CONTAINER_HEIGHT, listHeight + CONTAINER_HEADER_HEIGHT);
42
- return (React.createElement(SelectionPopup, { className: styles.popup, open: !!anchorEl, anchorEl: anchorEl, onClose: handleClose, onSearch: setFilterText, title: title || i18n.text('Show/hide columns'), containerWidth: containerWidth, containerHeight: containerHeight, searchInputOnKeyDown: handleKeyDown },
42
+ return (React.createElement(SelectionPopup, { className: styles.popup, open: !!anchorEl, anchorEl: anchorEl, onClose: handleClose, onSearch: setFilterText, inputPlaceholder: inputPlaceholder, title: title || i18n.text('Show/hide columns'), containerWidth: containerWidth, containerHeight: containerHeight, searchInputOnKeyDown: handleKeyDown },
43
43
  React.createElement(VirtualGroupedList, { fixedTitle: false, height: listHeight, renderItem: renderColumnItem, items: items, getItemSize: function () { return ITEM_HEIGHT; }, focusIndex: focusIndex })));
44
44
  };
@@ -11,8 +11,9 @@ type Props = {
11
11
  className?: string;
12
12
  hideTitle?: boolean;
13
13
  hideSearchInput?: boolean;
14
+ inputPlaceholder?: string;
14
15
  headerPlacement?: 'top' | 'bottom';
15
16
  searchInputRef?: React.Ref<unknown>;
16
17
  } & PopoverProps;
17
- export declare const SelectionPopup: ({ title, className, onSearch, hideTitle, hideSearchInput, headerPlacement, containerWidth, containerHeight, searchInputOnKeyDown, children, searchInputRef, anchorOrigin, transformOrigin, ...otherProps }: Props) => React.JSX.Element;
18
+ export declare const SelectionPopup: ({ title, className, onSearch, hideTitle, hideSearchInput, inputPlaceholder, headerPlacement, containerWidth, containerHeight, searchInputOnKeyDown, children, searchInputRef, anchorOrigin, transformOrigin, ...otherProps }: Props) => React.JSX.Element;
18
19
  export {};
@@ -29,18 +29,18 @@ import { useStyles } from './styles';
29
29
  import { useTheme } from '@mui/styles';
30
30
  export var SelectionPopup = function (_a) {
31
31
  var _b;
32
- var title = _a.title, className = _a.className, onSearch = _a.onSearch, hideTitle = _a.hideTitle, hideSearchInput = _a.hideSearchInput, _c = _a.headerPlacement, headerPlacement = _c === void 0 ? 'top' : _c, containerWidth = _a.containerWidth, containerHeight = _a.containerHeight, searchInputOnKeyDown = _a.searchInputOnKeyDown, children = _a.children, searchInputRef = _a.searchInputRef, _d = _a.anchorOrigin, anchorOrigin = _d === void 0 ? {
32
+ var title = _a.title, className = _a.className, onSearch = _a.onSearch, hideTitle = _a.hideTitle, hideSearchInput = _a.hideSearchInput, inputPlaceholder = _a.inputPlaceholder, _c = _a.headerPlacement, headerPlacement = _c === void 0 ? 'top' : _c, containerWidth = _a.containerWidth, containerHeight = _a.containerHeight, searchInputOnKeyDown = _a.searchInputOnKeyDown, children = _a.children, searchInputRef = _a.searchInputRef, _d = _a.anchorOrigin, anchorOrigin = _d === void 0 ? {
33
33
  vertical: 'top',
34
34
  horizontal: 'right'
35
35
  } : _d, _e = _a.transformOrigin, transformOrigin = _e === void 0 ? {
36
36
  vertical: 'top',
37
37
  horizontal: 'right'
38
- } : _e, otherProps = __rest(_a, ["title", "className", "onSearch", "hideTitle", "hideSearchInput", "headerPlacement", "containerWidth", "containerHeight", "searchInputOnKeyDown", "children", "searchInputRef", "anchorOrigin", "transformOrigin"]);
38
+ } : _e, otherProps = __rest(_a, ["title", "className", "onSearch", "hideTitle", "hideSearchInput", "inputPlaceholder", "headerPlacement", "containerWidth", "containerHeight", "searchInputOnKeyDown", "children", "searchInputRef", "anchorOrigin", "transformOrigin"]);
39
39
  var classes = useStyles({ containerWidth: containerWidth, containerHeight: containerHeight });
40
40
  var currentTheme = useTheme();
41
41
  var header = (React.createElement(React.Fragment, null,
42
42
  !hideTitle && React.createElement("div", { className: classes.header }, title),
43
- !hideSearchInput && (React.createElement(SearchInput, { onSearch: onSearch, autofocus: true, onKeyDown: searchInputOnKeyDown, inputRef: searchInputRef, classes: { root: classes.searchInputContainer }, placeholder: i18n.text('Search & add attributes'), height: 40 }))));
43
+ !hideSearchInput && (React.createElement(SearchInput, { onSearch: onSearch, autofocus: true, onKeyDown: searchInputOnKeyDown, inputRef: searchInputRef, classes: { root: classes.searchInputContainer }, placeholder: inputPlaceholder || i18n.text('Search & add attributes'), height: 40 }))));
44
44
  return (React.createElement(Popover, __assign({ anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, "data-mui-color-scheme": (_b = currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.palette) === null || _b === void 0 ? void 0 : _b.mode }, otherProps),
45
45
  React.createElement("div", { className: classnames(classes.container, className), style: { width: containerWidth } },
46
46
  headerPlacement === 'top' && header,
@@ -9,49 +9,109 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["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
+ };
12
48
  import React from 'react';
13
- import { shallow } from 'enzyme';
14
- import Popover from '@mui/material/Popover';
49
+ import { render, screen } from '@testing-library/react';
50
+ import userEvent from '@testing-library/user-event';
15
51
  import { SelectionPopup } from './SelectionPopup';
16
- import { SearchInput } from '../SearchInput';
17
52
  describe('SelectionPopup tests', function () {
18
53
  var defaultProps = {
54
+ title: 'Title',
19
55
  anchorEl: document.createElement('div'),
20
- open: true
56
+ open: true,
57
+ containerWidth: 100,
58
+ containerHeight: 100,
59
+ children: React.createElement("div", { "data-reltio-id": "children" }),
60
+ onClose: jest.fn(),
61
+ onSearch: jest.fn(),
62
+ searchInputOnKeyDown: jest.fn()
21
63
  };
22
- it('should render main components correctly', function () {
23
- var props = __assign(__assign({}, defaultProps), { children: React.createElement("div", { className: 'testChildren' }), title: 'Title', onSearch: jest.fn(), searchInputOnKeyDown: jest.fn(), onClose: jest.fn() });
24
- var component = shallow(React.createElement(SelectionPopup, __assign({}, props)));
25
- var popover = component.find(Popover);
26
- expect(popover.props()).toMatchObject({
27
- open: props.open,
28
- onClose: props.onClose
29
- });
30
- expect(popover.find('.header').text()).toBe(props.title);
31
- expect(popover.find(SearchInput).props()).toMatchObject({
32
- onKeyDown: props.searchInputOnKeyDown,
33
- onSearch: props.onSearch
64
+ var setUp = function (props) {
65
+ if (props === void 0) { props = {}; }
66
+ var user = userEvent.setup();
67
+ return __assign({ user: user }, render(React.createElement(SelectionPopup, __assign({}, defaultProps, props))));
68
+ };
69
+ it('should render main components correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
70
+ var user, textbox, backdrop;
71
+ return __generator(this, function (_a) {
72
+ switch (_a.label) {
73
+ case 0:
74
+ user = setUp().user;
75
+ textbox = screen.getByRole('textbox');
76
+ expect(textbox).toHaveAttribute('placeholder', 'Search & add attributes');
77
+ expect(screen.getByText('Title')).toBeInTheDocument();
78
+ expect(screen.getByTestId('children')).toBeInTheDocument();
79
+ return [4 /*yield*/, user.type(textbox, 'test')];
80
+ case 1:
81
+ _a.sent();
82
+ expect(defaultProps.onSearch).toHaveBeenCalledWith('test');
83
+ expect(defaultProps.searchInputOnKeyDown).toHaveBeenCalledTimes(4);
84
+ backdrop = screen.getByRole('presentation').firstChild;
85
+ return [4 /*yield*/, user.click(backdrop)];
86
+ case 2:
87
+ _a.sent();
88
+ expect(defaultProps.onClose).toHaveBeenCalled();
89
+ return [2 /*return*/];
90
+ }
34
91
  });
35
- expect(popover.find('.testChildren').length).toBe(1);
36
- });
92
+ }); });
37
93
  it('should hide title if props.hideTitle is true', function () {
38
- var component = shallow(React.createElement(SelectionPopup, __assign({}, defaultProps, { hideTitle: true })));
39
- expect(component.find('.header')).toHaveLength(0);
94
+ setUp({ hideTitle: true });
95
+ expect(screen.queryByText('Title')).not.toBeInTheDocument();
40
96
  });
41
97
  it('should hide search input if props.hideSearchInput is true', function () {
42
- var component = shallow(React.createElement(SelectionPopup, __assign({}, defaultProps, { hideSearchInput: true })));
43
- expect(component.find(SearchInput)).toHaveLength(0);
98
+ setUp({ hideSearchInput: true });
99
+ expect(screen.queryByRole('textbox')).not.toBeInTheDocument();
100
+ });
101
+ it('should use placeholder from props.inputPlaceholder', function () {
102
+ setUp({ inputPlaceholder: 'test placeholder' });
103
+ expect(screen.getByRole('textbox')).toHaveAttribute('placeholder', 'test placeholder');
44
104
  });
45
105
  it('should render header at the top if props.headerPlacement is "top"', function () {
46
- var component = shallow(React.createElement(SelectionPopup, __assign({}, defaultProps, { headerPlacement: "top" })));
47
- var content = component.find('.container').children();
48
- expect(content.at(0).prop('className')).toBe('header');
49
- expect(content.at(1).prop('placeholder')).toBe('Search & add attributes');
106
+ setUp({ headerPlacement: 'top' });
107
+ var container = screen.getByRole('presentation').querySelector('.container');
108
+ expect(container.firstChild).toHaveClass('header');
109
+ expect(container.lastChild).toHaveClass('list');
50
110
  });
51
111
  it('should render header at the bottom if props.headerPlacement is "bottom"', function () {
52
- var component = shallow(React.createElement(SelectionPopup, __assign({}, defaultProps, { headerPlacement: "bottom" })));
53
- var content = component.find('.container').children();
54
- expect(content.at(content.length - 2).prop('className')).toBe('header');
55
- expect(content.at(content.length - 1).prop('placeholder')).toBe('Search & add attributes');
112
+ setUp({ headerPlacement: 'bottom' });
113
+ var container = screen.getByRole('presentation').querySelector('.container');
114
+ expect(container.firstChild).toHaveClass('list');
115
+ expect(container.lastChild).toHaveClass('searchInputContainer');
56
116
  });
57
117
  });
@@ -36,7 +36,10 @@ var BarChart = function (_a) {
36
36
  var width = _a.width, height = _a.height, data = _a.data, _b = _a.options, options = _b === void 0 ? {} : _b, onItemClick = _a.onItemClick;
37
37
  var _c = (0, helpers_1.getBarChartSettings)(options), barChart = _c.barChart, cartesianGrid = _c.cartesianGrid, bar = _c.bar, tooltip = _c.tooltip, xAxis = _c.xAxis, yAxis = _c.yAxis;
38
38
  var _d = (0, useDynamicYAxisWidth_1.useDynamicYAxisWidth)({ chartYAxisProps: yAxis }), chartRef = _d.chartRef, dynamicYAxisWidth = __rest(_d, ["chartRef"]);
39
- var onBarClick = onItemClick && (function (data) { return onItemClick(data.group); });
39
+ var onBarClick = onItemClick && (function (_a) {
40
+ var group = _a.group;
41
+ return onItemClick(group);
42
+ });
40
43
  var clickable = (0, useClickableChartStyle_1.useClickableChartStyle)(onBarClick);
41
44
  return (react_1.default.createElement(recharts_1.BarChart, __assign({ width: width, height: height, data: data }, barChart, { ref: chartRef }),
42
45
  react_1.default.createElement(recharts_1.CartesianGrid, __assign({}, cartesianGrid)),
@@ -6,6 +6,7 @@ type Props = {
6
6
  onChangeColumns: (columns: string[]) => void;
7
7
  title?: string;
8
8
  tooltipTitle?: string;
9
+ inputPlaceholder?: string;
9
10
  };
10
- export declare const ColumnsSettings: ({ columnsData, selectedColumns, onChangeColumns, title, tooltipTitle }: Props) => React.JSX.Element;
11
+ export declare const ColumnsSettings: ({ columnsData, selectedColumns, onChangeColumns, title, tooltipTitle, inputPlaceholder }: Props) => React.JSX.Element;
11
12
  export {};
@@ -35,7 +35,7 @@ var SmallIconButton_1 = require("../SmallIconButton");
35
35
  var ColumnsSettingsPopup_1 = require("./components/ColumnsSettingsPopup");
36
36
  var helpers_1 = require("./helpers");
37
37
  var ColumnsSettings = function (_a) {
38
- var columnsData = _a.columnsData, selectedColumns = _a.selectedColumns, onChangeColumns = _a.onChangeColumns, title = _a.title, tooltipTitle = _a.tooltipTitle;
38
+ var columnsData = _a.columnsData, selectedColumns = _a.selectedColumns, onChangeColumns = _a.onChangeColumns, title = _a.title, tooltipTitle = _a.tooltipTitle, inputPlaceholder = _a.inputPlaceholder;
39
39
  var _b = (0, react_1.useState)(null), anchorEl = _b[0], setAnchorEl = _b[1];
40
40
  var openPopup = function (event) { return setAnchorEl(event.currentTarget); };
41
41
  var closePopup = function () { return setAnchorEl(null); };
@@ -48,6 +48,6 @@ var ColumnsSettings = function (_a) {
48
48
  }, [selectedColumns, onChangeColumns]);
49
49
  return (react_1.default.createElement(react_1.default.Fragment, null,
50
50
  react_1.default.createElement(SmallIconButton_1.SmallIconButtonWithTooltip, { "data-reltio-id": "reltio-columns-settings-button", tooltipTitle: tooltipTitle || ui_i18n_1.default.text('Show/hide columns'), size: "L", icon: Table_1.default, onClick: openPopup }),
51
- react_1.default.createElement(ColumnsSettingsPopup_1.ColumnsSettingsPopup, { onColumnClick: handleColumnClick, anchorEl: anchorEl, columnsData: columnsData, onClose: closePopup, title: title, selectedColumns: selectedColumns })));
51
+ react_1.default.createElement(ColumnsSettingsPopup_1.ColumnsSettingsPopup, { onColumnClick: handleColumnClick, anchorEl: anchorEl, columnsData: columnsData, onClose: closePopup, title: title, inputPlaceholder: inputPlaceholder, selectedColumns: selectedColumns })));
52
52
  };
53
53
  exports.ColumnsSettings = ColumnsSettings;
@@ -110,6 +110,20 @@ describe('ColumnsSettings', function () {
110
110
  }
111
111
  });
112
112
  }); });
113
+ it('should use custom placeholder', function () { return __awaiter(void 0, void 0, void 0, function () {
114
+ var user;
115
+ return __generator(this, function (_a) {
116
+ switch (_a.label) {
117
+ case 0:
118
+ user = setUp({ props: { inputPlaceholder: 'test placeholder' } }).user;
119
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId('reltio-columns-settings-button'))];
120
+ case 1:
121
+ _a.sent();
122
+ expect(react_2.screen.getByRole('textbox')).toHaveAttribute('placeholder', 'test placeholder');
123
+ return [2 /*return*/];
124
+ }
125
+ });
126
+ }); });
113
127
  });
114
128
  describe('plain columns data behavior', function () {
115
129
  var columnsData = [
@@ -4,6 +4,7 @@ type Props = {
4
4
  anchorEl: HTMLElement;
5
5
  onClose: () => void;
6
6
  title?: string;
7
+ inputPlaceholder?: string;
7
8
  columnsData: GroupedColumnsData[];
8
9
  onColumnClick: (column: {
9
10
  id: string;
@@ -11,5 +12,5 @@ type Props = {
11
12
  selectedColumns: string[];
12
13
  hideCheckBox?: boolean;
13
14
  };
14
- export declare const ColumnsSettingsPopup: ({ anchorEl, onClose, title, columnsData, onColumnClick, selectedColumns, hideCheckBox }: Props) => React.JSX.Element;
15
+ export declare const ColumnsSettingsPopup: ({ anchorEl, onClose, title, inputPlaceholder, columnsData, onColumnClick, selectedColumns, hideCheckBox }: Props) => React.JSX.Element;
15
16
  export {};
@@ -43,7 +43,7 @@ var DEFAULT_MIN_CONTAINER_WIDTH = 308;
43
43
  var CONTAINER_HEADER_HEIGHT = 108;
44
44
  var MIN_CONTAINER_HEIGHT = 140;
45
45
  var ColumnsSettingsPopup = function (_a) {
46
- var anchorEl = _a.anchorEl, onClose = _a.onClose, title = _a.title, columnsData = _a.columnsData, onColumnClick = _a.onColumnClick, selectedColumns = _a.selectedColumns, hideCheckBox = _a.hideCheckBox;
46
+ var anchorEl = _a.anchorEl, onClose = _a.onClose, title = _a.title, inputPlaceholder = _a.inputPlaceholder, columnsData = _a.columnsData, onColumnClick = _a.onColumnClick, selectedColumns = _a.selectedColumns, hideCheckBox = _a.hideCheckBox;
47
47
  var styles = (0, styles_1.useStyles)();
48
48
  var _b = (0, react_1.useState)(''), filterText = _b[0], setFilterText = _b[1];
49
49
  var clearFilter = function () { return setFilterText(''); };
@@ -68,7 +68,7 @@ var ColumnsSettingsPopup = function (_a) {
68
68
  };
69
69
  var listHeight = Math.min(MAX_LIST_CONTAINER_HEIGHT, ITEM_HEIGHT * items.length);
70
70
  var containerHeight = Math.max(MIN_CONTAINER_HEIGHT, listHeight + CONTAINER_HEADER_HEIGHT);
71
- return (react_1.default.createElement(SelectionPopup_1.SelectionPopup, { className: styles.popup, open: !!anchorEl, anchorEl: anchorEl, onClose: handleClose, onSearch: setFilterText, title: title || ui_i18n_1.default.text('Show/hide columns'), containerWidth: containerWidth, containerHeight: containerHeight, searchInputOnKeyDown: handleKeyDown },
71
+ return (react_1.default.createElement(SelectionPopup_1.SelectionPopup, { className: styles.popup, open: !!anchorEl, anchorEl: anchorEl, onClose: handleClose, onSearch: setFilterText, inputPlaceholder: inputPlaceholder, title: title || ui_i18n_1.default.text('Show/hide columns'), containerWidth: containerWidth, containerHeight: containerHeight, searchInputOnKeyDown: handleKeyDown },
72
72
  react_1.default.createElement(VirtualGroupedList_1.VirtualGroupedList, { fixedTitle: false, height: listHeight, renderItem: renderColumnItem, items: items, getItemSize: function () { return ITEM_HEIGHT; }, focusIndex: focusIndex })));
73
73
  };
74
74
  exports.ColumnsSettingsPopup = ColumnsSettingsPopup;
@@ -11,8 +11,9 @@ type Props = {
11
11
  className?: string;
12
12
  hideTitle?: boolean;
13
13
  hideSearchInput?: boolean;
14
+ inputPlaceholder?: string;
14
15
  headerPlacement?: 'top' | 'bottom';
15
16
  searchInputRef?: React.Ref<unknown>;
16
17
  } & PopoverProps;
17
- export declare const SelectionPopup: ({ title, className, onSearch, hideTitle, hideSearchInput, headerPlacement, containerWidth, containerHeight, searchInputOnKeyDown, children, searchInputRef, anchorOrigin, transformOrigin, ...otherProps }: Props) => React.JSX.Element;
18
+ export declare const SelectionPopup: ({ title, className, onSearch, hideTitle, hideSearchInput, inputPlaceholder, headerPlacement, containerWidth, containerHeight, searchInputOnKeyDown, children, searchInputRef, anchorOrigin, transformOrigin, ...otherProps }: Props) => React.JSX.Element;
18
19
  export {};
@@ -35,18 +35,18 @@ var styles_1 = require("./styles");
35
35
  var styles_2 = require("@mui/styles");
36
36
  var SelectionPopup = function (_a) {
37
37
  var _b;
38
- var title = _a.title, className = _a.className, onSearch = _a.onSearch, hideTitle = _a.hideTitle, hideSearchInput = _a.hideSearchInput, _c = _a.headerPlacement, headerPlacement = _c === void 0 ? 'top' : _c, containerWidth = _a.containerWidth, containerHeight = _a.containerHeight, searchInputOnKeyDown = _a.searchInputOnKeyDown, children = _a.children, searchInputRef = _a.searchInputRef, _d = _a.anchorOrigin, anchorOrigin = _d === void 0 ? {
38
+ var title = _a.title, className = _a.className, onSearch = _a.onSearch, hideTitle = _a.hideTitle, hideSearchInput = _a.hideSearchInput, inputPlaceholder = _a.inputPlaceholder, _c = _a.headerPlacement, headerPlacement = _c === void 0 ? 'top' : _c, containerWidth = _a.containerWidth, containerHeight = _a.containerHeight, searchInputOnKeyDown = _a.searchInputOnKeyDown, children = _a.children, searchInputRef = _a.searchInputRef, _d = _a.anchorOrigin, anchorOrigin = _d === void 0 ? {
39
39
  vertical: 'top',
40
40
  horizontal: 'right'
41
41
  } : _d, _e = _a.transformOrigin, transformOrigin = _e === void 0 ? {
42
42
  vertical: 'top',
43
43
  horizontal: 'right'
44
- } : _e, otherProps = __rest(_a, ["title", "className", "onSearch", "hideTitle", "hideSearchInput", "headerPlacement", "containerWidth", "containerHeight", "searchInputOnKeyDown", "children", "searchInputRef", "anchorOrigin", "transformOrigin"]);
44
+ } : _e, otherProps = __rest(_a, ["title", "className", "onSearch", "hideTitle", "hideSearchInput", "inputPlaceholder", "headerPlacement", "containerWidth", "containerHeight", "searchInputOnKeyDown", "children", "searchInputRef", "anchorOrigin", "transformOrigin"]);
45
45
  var classes = (0, styles_1.useStyles)({ containerWidth: containerWidth, containerHeight: containerHeight });
46
46
  var currentTheme = (0, styles_2.useTheme)();
47
47
  var header = (react_1.default.createElement(react_1.default.Fragment, null,
48
48
  !hideTitle && react_1.default.createElement("div", { className: classes.header }, title),
49
- !hideSearchInput && (react_1.default.createElement(SearchInput_1.SearchInput, { onSearch: onSearch, autofocus: true, onKeyDown: searchInputOnKeyDown, inputRef: searchInputRef, classes: { root: classes.searchInputContainer }, placeholder: ui_i18n_1.default.text('Search & add attributes'), height: 40 }))));
49
+ !hideSearchInput && (react_1.default.createElement(SearchInput_1.SearchInput, { onSearch: onSearch, autofocus: true, onKeyDown: searchInputOnKeyDown, inputRef: searchInputRef, classes: { root: classes.searchInputContainer }, placeholder: inputPlaceholder || ui_i18n_1.default.text('Search & add attributes'), height: 40 }))));
50
50
  return (react_1.default.createElement(Popover_1.default, __assign({ anchorOrigin: anchorOrigin, transformOrigin: transformOrigin, "data-mui-color-scheme": (_b = currentTheme === null || currentTheme === void 0 ? void 0 : currentTheme.palette) === null || _b === void 0 ? void 0 : _b.mode }, otherProps),
51
51
  react_1.default.createElement("div", { className: (0, classnames_1.default)(classes.container, className), style: { width: containerWidth } },
52
52
  headerPlacement === 'top' && header,
@@ -10,53 +10,113 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
24
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
51
  };
16
52
  Object.defineProperty(exports, "__esModule", { value: true });
17
53
  var react_1 = __importDefault(require("react"));
18
- var enzyme_1 = require("enzyme");
19
- var Popover_1 = __importDefault(require("@mui/material/Popover"));
54
+ var react_2 = require("@testing-library/react");
55
+ var user_event_1 = __importDefault(require("@testing-library/user-event"));
20
56
  var SelectionPopup_1 = require("./SelectionPopup");
21
- var SearchInput_1 = require("../SearchInput");
22
57
  describe('SelectionPopup tests', function () {
23
58
  var defaultProps = {
59
+ title: 'Title',
24
60
  anchorEl: document.createElement('div'),
25
- open: true
61
+ open: true,
62
+ containerWidth: 100,
63
+ containerHeight: 100,
64
+ children: react_1.default.createElement("div", { "data-reltio-id": "children" }),
65
+ onClose: jest.fn(),
66
+ onSearch: jest.fn(),
67
+ searchInputOnKeyDown: jest.fn()
26
68
  };
27
- it('should render main components correctly', function () {
28
- var props = __assign(__assign({}, defaultProps), { children: react_1.default.createElement("div", { className: 'testChildren' }), title: 'Title', onSearch: jest.fn(), searchInputOnKeyDown: jest.fn(), onClose: jest.fn() });
29
- var component = (0, enzyme_1.shallow)(react_1.default.createElement(SelectionPopup_1.SelectionPopup, __assign({}, props)));
30
- var popover = component.find(Popover_1.default);
31
- expect(popover.props()).toMatchObject({
32
- open: props.open,
33
- onClose: props.onClose
34
- });
35
- expect(popover.find('.header').text()).toBe(props.title);
36
- expect(popover.find(SearchInput_1.SearchInput).props()).toMatchObject({
37
- onKeyDown: props.searchInputOnKeyDown,
38
- onSearch: props.onSearch
69
+ var setUp = function (props) {
70
+ if (props === void 0) { props = {}; }
71
+ var user = user_event_1.default.setup();
72
+ return __assign({ user: user }, (0, react_2.render)(react_1.default.createElement(SelectionPopup_1.SelectionPopup, __assign({}, defaultProps, props))));
73
+ };
74
+ it('should render main components correctly', function () { return __awaiter(void 0, void 0, void 0, function () {
75
+ var user, textbox, backdrop;
76
+ return __generator(this, function (_a) {
77
+ switch (_a.label) {
78
+ case 0:
79
+ user = setUp().user;
80
+ textbox = react_2.screen.getByRole('textbox');
81
+ expect(textbox).toHaveAttribute('placeholder', 'Search & add attributes');
82
+ expect(react_2.screen.getByText('Title')).toBeInTheDocument();
83
+ expect(react_2.screen.getByTestId('children')).toBeInTheDocument();
84
+ return [4 /*yield*/, user.type(textbox, 'test')];
85
+ case 1:
86
+ _a.sent();
87
+ expect(defaultProps.onSearch).toHaveBeenCalledWith('test');
88
+ expect(defaultProps.searchInputOnKeyDown).toHaveBeenCalledTimes(4);
89
+ backdrop = react_2.screen.getByRole('presentation').firstChild;
90
+ return [4 /*yield*/, user.click(backdrop)];
91
+ case 2:
92
+ _a.sent();
93
+ expect(defaultProps.onClose).toHaveBeenCalled();
94
+ return [2 /*return*/];
95
+ }
39
96
  });
40
- expect(popover.find('.testChildren').length).toBe(1);
41
- });
97
+ }); });
42
98
  it('should hide title if props.hideTitle is true', function () {
43
- var component = (0, enzyme_1.shallow)(react_1.default.createElement(SelectionPopup_1.SelectionPopup, __assign({}, defaultProps, { hideTitle: true })));
44
- expect(component.find('.header')).toHaveLength(0);
99
+ setUp({ hideTitle: true });
100
+ expect(react_2.screen.queryByText('Title')).not.toBeInTheDocument();
45
101
  });
46
102
  it('should hide search input if props.hideSearchInput is true', function () {
47
- var component = (0, enzyme_1.shallow)(react_1.default.createElement(SelectionPopup_1.SelectionPopup, __assign({}, defaultProps, { hideSearchInput: true })));
48
- expect(component.find(SearchInput_1.SearchInput)).toHaveLength(0);
103
+ setUp({ hideSearchInput: true });
104
+ expect(react_2.screen.queryByRole('textbox')).not.toBeInTheDocument();
105
+ });
106
+ it('should use placeholder from props.inputPlaceholder', function () {
107
+ setUp({ inputPlaceholder: 'test placeholder' });
108
+ expect(react_2.screen.getByRole('textbox')).toHaveAttribute('placeholder', 'test placeholder');
49
109
  });
50
110
  it('should render header at the top if props.headerPlacement is "top"', function () {
51
- var component = (0, enzyme_1.shallow)(react_1.default.createElement(SelectionPopup_1.SelectionPopup, __assign({}, defaultProps, { headerPlacement: "top" })));
52
- var content = component.find('.container').children();
53
- expect(content.at(0).prop('className')).toBe('header');
54
- expect(content.at(1).prop('placeholder')).toBe('Search & add attributes');
111
+ setUp({ headerPlacement: 'top' });
112
+ var container = react_2.screen.getByRole('presentation').querySelector('.container');
113
+ expect(container.firstChild).toHaveClass('header');
114
+ expect(container.lastChild).toHaveClass('list');
55
115
  });
56
116
  it('should render header at the bottom if props.headerPlacement is "bottom"', function () {
57
- var component = (0, enzyme_1.shallow)(react_1.default.createElement(SelectionPopup_1.SelectionPopup, __assign({}, defaultProps, { headerPlacement: "bottom" })));
58
- var content = component.find('.container').children();
59
- expect(content.at(content.length - 2).prop('className')).toBe('header');
60
- expect(content.at(content.length - 1).prop('placeholder')).toBe('Search & add attributes');
117
+ setUp({ headerPlacement: 'bottom' });
118
+ var container = react_2.screen.getByRole('presentation').querySelector('.container');
119
+ expect(container.firstChild).toHaveClass('list');
120
+ expect(container.lastChild).toHaveClass('searchInputContainer');
61
121
  });
62
122
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.2049",
3
+ "version": "1.4.2051",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -36,7 +36,7 @@
36
36
  "react-simple-maps": "^3.0.0",
37
37
  "react-virtualized": "^9.22.5",
38
38
  "react-window": "^1.8.10",
39
- "recharts": "^2.14.1",
39
+ "recharts": "^2.15.0",
40
40
  "sanitize-html": "^2.13.1",
41
41
  "sigma": "^2.4.0",
42
42
  "topojson-client": "^3.1.0"