@dhis2-ui/select 8.9.0 → 8.10.0

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.
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _index = require("../../multi-select-option/index.js");
8
+
9
+ var _selectionList = require("../selection-list.js");
10
+
11
+ require("@testing-library/jest-dom");
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ describe('<SelectionList />', () => {
16
+ const env = process.env;
17
+ beforeEach(() => {
18
+ // Ensure process.env is also reset for cached modules
19
+ jest.resetModules();
20
+ process.env = { ...env
21
+ }; // Allow spying on console.error and silence rendering errors
22
+
23
+ jest.spyOn(console, 'error').mockImplementation(() => {});
24
+ });
25
+ afterEach(() => {
26
+ // Restore process.env to original state
27
+ process.env = env; // Restore all mocks back to original values
28
+
29
+ jest.restoreAllMocks();
30
+ });
31
+ describe('production', () => {
32
+ it('should not throw an error for a selection that is not in the options', () => {
33
+ process.env.NODE_ENV = 'production';
34
+
35
+ const options = /*#__PURE__*/_react2.default.createElement(_index.MultiSelectOption, {
36
+ key: "1",
37
+ label: "one",
38
+ value: "1"
39
+ });
40
+
41
+ const selected = ['value'];
42
+ expect(() => {
43
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selectionList.SelectionList, {
44
+ selected: selected,
45
+ options: options,
46
+ disabled: false,
47
+ onChange: () => {}
48
+ }));
49
+ }).not.toThrow();
50
+ });
51
+ it('should show the selection for a selection that is not in the options', () => {
52
+ process.env.NODE_ENV = 'production';
53
+
54
+ const options = /*#__PURE__*/_react2.default.createElement(_index.MultiSelectOption, {
55
+ key: "1",
56
+ label: "one",
57
+ value: "1"
58
+ });
59
+
60
+ const selected = ['value'];
61
+ const {
62
+ getByText
63
+ } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selectionList.SelectionList, {
64
+ selected: selected,
65
+ options: options,
66
+ disabled: false,
67
+ onChange: () => {}
68
+ }));
69
+ expect(getByText(selected)).toBeInTheDocument();
70
+ });
71
+ it('log an error for a selection that is not in the options', () => {
72
+ process.env.NODE_ENV = 'production';
73
+
74
+ const options = /*#__PURE__*/_react2.default.createElement(_index.MultiSelectOption, {
75
+ key: "1",
76
+ label: "one",
77
+ value: "1"
78
+ });
79
+
80
+ const selected = ['value'];
81
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selectionList.SelectionList, {
82
+ selected: selected,
83
+ options: options,
84
+ disabled: false,
85
+ onChange: () => {}
86
+ }));
87
+ expect(console.error).toHaveBeenCalledWith('There is no option with the value: "value". Make sure that all the values passed to the selected prop match the value of an existing option.');
88
+ });
89
+ });
90
+ describe('not production', () => {
91
+ it('should throw an error for a selection that is not in the options', () => {
92
+ process.env.NODE_ENV = 'development';
93
+
94
+ const options = /*#__PURE__*/_react2.default.createElement(_index.MultiSelectOption, {
95
+ key: "1",
96
+ label: "one",
97
+ value: "1"
98
+ });
99
+
100
+ const selected = ['value'];
101
+ expect(() => {
102
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selectionList.SelectionList, {
103
+ selected: selected,
104
+ options: options,
105
+ disabled: false,
106
+ onChange: () => {}
107
+ }));
108
+ }).toThrow('There is no option with the value: "value". Make sure that all the values passed to the selected prop match the value of an existing option.');
109
+ });
110
+ });
111
+ });
@@ -38,15 +38,26 @@ const SelectionList = _ref2 => {
38
38
  options
39
39
  } = _ref2;
40
40
  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, selected.map(value => {
41
+ const isProduction = process.env.NODE_ENV === 'production';
41
42
  const selectedOption = (0, _index.findOptionChild)(value, options);
42
43
 
43
44
  if (!selectedOption) {
44
45
  const message = "There is no option with the value: \"".concat(value, "\". ") + 'Make sure that all the values passed to the selected ' + 'prop match the value of an existing option.';
45
- throw new Error(message);
46
- } // The chip should be disabled if the option or the select are disabled
47
46
 
47
+ if (isProduction) {
48
+ // Don't crash the app if in production
49
+ console.error(message);
50
+ } else {
51
+ // Throw error if not in production for maximum visibility
52
+ throw new Error(message);
53
+ }
54
+ }
48
55
 
49
- const isDisabled = selectedOption.props.disabled || disabled; // Create an onRemove handler, but only if it's not disabled
56
+ const isDisabled = selectedOption ? // The chip should be disabled if the option or the select are disabled
57
+ selectedOption.props.disabled || disabled : // If there is no selected option, just look at the select
58
+ disabled; // Use the selected value if we do not have a label
59
+
60
+ const label = selectedOption ? selectedOption.props.label : value; // Create an onRemove handler, but only if it's not disabled
50
61
 
51
62
  const onRemove = isDisabled ? undefined : createRemoveHandler({
52
63
  selected,
@@ -62,7 +73,7 @@ const SelectionList = _ref2 => {
62
73
  marginTop: "0",
63
74
  overflow: true,
64
75
  dense: true
65
- }, selectedOption.props.label);
76
+ }, label);
66
77
  }));
67
78
  };
68
79
 
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+
3
+ var _react = require("@testing-library/react");
4
+
5
+ var _react2 = _interopRequireDefault(require("react"));
6
+
7
+ var _index = require("../../single-select-option/index.js");
8
+
9
+ var _selection = require("../selection.js");
10
+
11
+ require("@testing-library/jest-dom");
12
+
13
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+
15
+ describe('<Selection />', () => {
16
+ const env = process.env;
17
+ beforeEach(() => {
18
+ // Ensure process.env is also reset for cached modules
19
+ jest.resetModules();
20
+ process.env = { ...env
21
+ }; // Allow spying on console.error and silence rendering errors
22
+
23
+ jest.spyOn(console, 'error').mockImplementation(() => {});
24
+ });
25
+ afterEach(() => {
26
+ // Restore process.env to original state
27
+ process.env = env; // Restore all mocks back to original values
28
+
29
+ jest.restoreAllMocks();
30
+ });
31
+ describe('production', () => {
32
+ it('should not throw an error for a selection that is not in the options', () => {
33
+ process.env.NODE_ENV = 'production';
34
+
35
+ const options = /*#__PURE__*/_react2.default.createElement(_index.SingleSelectOption, {
36
+ key: "1",
37
+ label: "one",
38
+ value: "1"
39
+ });
40
+
41
+ const selected = 'value';
42
+ expect(() => {
43
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selection.Selection, {
44
+ selected: selected,
45
+ options: options,
46
+ disabled: false,
47
+ onChange: () => {}
48
+ }));
49
+ }).not.toThrow();
50
+ });
51
+ it('should show the selection for a selection that is not in the options', () => {
52
+ process.env.NODE_ENV = 'production';
53
+
54
+ const options = /*#__PURE__*/_react2.default.createElement(_index.SingleSelectOption, {
55
+ key: "1",
56
+ label: "one",
57
+ value: "1"
58
+ });
59
+
60
+ const selected = 'value';
61
+ const {
62
+ getByText
63
+ } = (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selection.Selection, {
64
+ selected: selected,
65
+ options: options,
66
+ disabled: false,
67
+ onChange: () => {}
68
+ }));
69
+ expect(getByText(selected)).toBeInTheDocument();
70
+ });
71
+ it('log an error for a selection that is not in the options', () => {
72
+ process.env.NODE_ENV = 'production';
73
+
74
+ const options = /*#__PURE__*/_react2.default.createElement(_index.SingleSelectOption, {
75
+ key: "1",
76
+ label: "one",
77
+ value: "1"
78
+ });
79
+
80
+ const selected = 'value';
81
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selection.Selection, {
82
+ selected: selected,
83
+ options: options,
84
+ disabled: false,
85
+ onChange: () => {}
86
+ }));
87
+ expect(console.error).toHaveBeenCalledWith('There is no option with the value: "value". Make sure that the value passed to the selected prop matches the value of an existing option.');
88
+ });
89
+ });
90
+ describe('not production', () => {
91
+ it('should throw an error for a selection that is not in the options', () => {
92
+ process.env.NODE_ENV = 'development';
93
+
94
+ const options = /*#__PURE__*/_react2.default.createElement(_index.SingleSelectOption, {
95
+ key: "1",
96
+ label: "one",
97
+ value: "1"
98
+ });
99
+
100
+ const selected = 'value';
101
+ expect(() => {
102
+ (0, _react.render)( /*#__PURE__*/_react2.default.createElement(_selection.Selection, {
103
+ selected: selected,
104
+ options: options,
105
+ disabled: false,
106
+ onChange: () => {}
107
+ }));
108
+ }).toThrow('There is no option with the value: "value". Make sure that the value passed to the selected prop matches the value of an existing option.');
109
+ });
110
+ });
111
+ });
@@ -25,15 +25,24 @@ const Selection = _ref => {
25
25
  selected,
26
26
  className
27
27
  } = _ref;
28
+ const isProduction = process.env.NODE_ENV === 'production';
28
29
  const selectedOption = (0, _index.findOptionChild)(selected, options);
29
30
 
30
31
  if (!selectedOption) {
31
32
  const message = "There is no option with the value: \"".concat(selected, "\". ") + 'Make sure that the value passed to the selected ' + 'prop matches the value of an existing option.';
32
- throw new Error(message);
33
+
34
+ if (isProduction) {
35
+ // Don't crash the app if in production
36
+ console.error(message);
37
+ } else {
38
+ // Throw error if not in production for maximum visibility
39
+ throw new Error(message);
40
+ }
33
41
  }
34
42
 
35
- const icon = selectedOption.props.icon;
36
- const label = selectedOption.props.label;
43
+ const icon = selectedOption && selectedOption.props.icon; // Use the selected value if we do not have a label
44
+
45
+ const label = selectedOption ? selectedOption.props.label : selected;
37
46
  return /*#__PURE__*/_react.default.createElement("div", {
38
47
  className: _style.default.dynamic([["2249594316", [_uiConstants.spacers.dp8, _uiConstants.spacers.dp16, _uiConstants.spacers.dp16]]]) + " " + ((0, _classnames.default)(className, 'root') || "")
39
48
  }, icon && /*#__PURE__*/_react.default.createElement("div", {
@@ -0,0 +1,94 @@
1
+ import { render } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { MultiSelectOption } from '../../multi-select-option/index.js';
4
+ import { SelectionList } from '../selection-list.js';
5
+ import '@testing-library/jest-dom';
6
+ describe('<SelectionList />', () => {
7
+ const env = process.env;
8
+ beforeEach(() => {
9
+ // Ensure process.env is also reset for cached modules
10
+ jest.resetModules();
11
+ process.env = { ...env
12
+ }; // Allow spying on console.error and silence rendering errors
13
+
14
+ jest.spyOn(console, 'error').mockImplementation(() => {});
15
+ });
16
+ afterEach(() => {
17
+ // Restore process.env to original state
18
+ process.env = env; // Restore all mocks back to original values
19
+
20
+ jest.restoreAllMocks();
21
+ });
22
+ describe('production', () => {
23
+ it('should not throw an error for a selection that is not in the options', () => {
24
+ process.env.NODE_ENV = 'production';
25
+ const options = /*#__PURE__*/React.createElement(MultiSelectOption, {
26
+ key: "1",
27
+ label: "one",
28
+ value: "1"
29
+ });
30
+ const selected = ['value'];
31
+ expect(() => {
32
+ render( /*#__PURE__*/React.createElement(SelectionList, {
33
+ selected: selected,
34
+ options: options,
35
+ disabled: false,
36
+ onChange: () => {}
37
+ }));
38
+ }).not.toThrow();
39
+ });
40
+ it('should show the selection for a selection that is not in the options', () => {
41
+ process.env.NODE_ENV = 'production';
42
+ const options = /*#__PURE__*/React.createElement(MultiSelectOption, {
43
+ key: "1",
44
+ label: "one",
45
+ value: "1"
46
+ });
47
+ const selected = ['value'];
48
+ const {
49
+ getByText
50
+ } = render( /*#__PURE__*/React.createElement(SelectionList, {
51
+ selected: selected,
52
+ options: options,
53
+ disabled: false,
54
+ onChange: () => {}
55
+ }));
56
+ expect(getByText(selected)).toBeInTheDocument();
57
+ });
58
+ it('log an error for a selection that is not in the options', () => {
59
+ process.env.NODE_ENV = 'production';
60
+ const options = /*#__PURE__*/React.createElement(MultiSelectOption, {
61
+ key: "1",
62
+ label: "one",
63
+ value: "1"
64
+ });
65
+ const selected = ['value'];
66
+ render( /*#__PURE__*/React.createElement(SelectionList, {
67
+ selected: selected,
68
+ options: options,
69
+ disabled: false,
70
+ onChange: () => {}
71
+ }));
72
+ expect(console.error).toHaveBeenCalledWith('There is no option with the value: "value". Make sure that all the values passed to the selected prop match the value of an existing option.');
73
+ });
74
+ });
75
+ describe('not production', () => {
76
+ it('should throw an error for a selection that is not in the options', () => {
77
+ process.env.NODE_ENV = 'development';
78
+ const options = /*#__PURE__*/React.createElement(MultiSelectOption, {
79
+ key: "1",
80
+ label: "one",
81
+ value: "1"
82
+ });
83
+ const selected = ['value'];
84
+ expect(() => {
85
+ render( /*#__PURE__*/React.createElement(SelectionList, {
86
+ selected: selected,
87
+ options: options,
88
+ disabled: false,
89
+ onChange: () => {}
90
+ }));
91
+ }).toThrow('There is no option with the value: "value". Make sure that all the values passed to the selected prop match the value of an existing option.');
92
+ });
93
+ });
94
+ });
@@ -26,15 +26,26 @@ const SelectionList = _ref2 => {
26
26
  options
27
27
  } = _ref2;
28
28
  return /*#__PURE__*/React.createElement(React.Fragment, null, selected.map(value => {
29
+ const isProduction = process.env.NODE_ENV === 'production';
29
30
  const selectedOption = findOptionChild(value, options);
30
31
 
31
32
  if (!selectedOption) {
32
33
  const message = "There is no option with the value: \"".concat(value, "\". ") + 'Make sure that all the values passed to the selected ' + 'prop match the value of an existing option.';
33
- throw new Error(message);
34
- } // The chip should be disabled if the option or the select are disabled
35
34
 
35
+ if (isProduction) {
36
+ // Don't crash the app if in production
37
+ console.error(message);
38
+ } else {
39
+ // Throw error if not in production for maximum visibility
40
+ throw new Error(message);
41
+ }
42
+ }
36
43
 
37
- const isDisabled = selectedOption.props.disabled || disabled; // Create an onRemove handler, but only if it's not disabled
44
+ const isDisabled = selectedOption ? // The chip should be disabled if the option or the select are disabled
45
+ selectedOption.props.disabled || disabled : // If there is no selected option, just look at the select
46
+ disabled; // Use the selected value if we do not have a label
47
+
48
+ const label = selectedOption ? selectedOption.props.label : value; // Create an onRemove handler, but only if it's not disabled
38
49
 
39
50
  const onRemove = isDisabled ? undefined : createRemoveHandler({
40
51
  selected,
@@ -50,7 +61,7 @@ const SelectionList = _ref2 => {
50
61
  marginTop: "0",
51
62
  overflow: true,
52
63
  dense: true
53
- }, selectedOption.props.label);
64
+ }, label);
54
65
  }));
55
66
  };
56
67
 
@@ -0,0 +1,94 @@
1
+ import { render } from '@testing-library/react';
2
+ import React from 'react';
3
+ import { SingleSelectOption } from '../../single-select-option/index.js';
4
+ import { Selection } from '../selection.js';
5
+ import '@testing-library/jest-dom';
6
+ describe('<Selection />', () => {
7
+ const env = process.env;
8
+ beforeEach(() => {
9
+ // Ensure process.env is also reset for cached modules
10
+ jest.resetModules();
11
+ process.env = { ...env
12
+ }; // Allow spying on console.error and silence rendering errors
13
+
14
+ jest.spyOn(console, 'error').mockImplementation(() => {});
15
+ });
16
+ afterEach(() => {
17
+ // Restore process.env to original state
18
+ process.env = env; // Restore all mocks back to original values
19
+
20
+ jest.restoreAllMocks();
21
+ });
22
+ describe('production', () => {
23
+ it('should not throw an error for a selection that is not in the options', () => {
24
+ process.env.NODE_ENV = 'production';
25
+ const options = /*#__PURE__*/React.createElement(SingleSelectOption, {
26
+ key: "1",
27
+ label: "one",
28
+ value: "1"
29
+ });
30
+ const selected = 'value';
31
+ expect(() => {
32
+ render( /*#__PURE__*/React.createElement(Selection, {
33
+ selected: selected,
34
+ options: options,
35
+ disabled: false,
36
+ onChange: () => {}
37
+ }));
38
+ }).not.toThrow();
39
+ });
40
+ it('should show the selection for a selection that is not in the options', () => {
41
+ process.env.NODE_ENV = 'production';
42
+ const options = /*#__PURE__*/React.createElement(SingleSelectOption, {
43
+ key: "1",
44
+ label: "one",
45
+ value: "1"
46
+ });
47
+ const selected = 'value';
48
+ const {
49
+ getByText
50
+ } = render( /*#__PURE__*/React.createElement(Selection, {
51
+ selected: selected,
52
+ options: options,
53
+ disabled: false,
54
+ onChange: () => {}
55
+ }));
56
+ expect(getByText(selected)).toBeInTheDocument();
57
+ });
58
+ it('log an error for a selection that is not in the options', () => {
59
+ process.env.NODE_ENV = 'production';
60
+ const options = /*#__PURE__*/React.createElement(SingleSelectOption, {
61
+ key: "1",
62
+ label: "one",
63
+ value: "1"
64
+ });
65
+ const selected = 'value';
66
+ render( /*#__PURE__*/React.createElement(Selection, {
67
+ selected: selected,
68
+ options: options,
69
+ disabled: false,
70
+ onChange: () => {}
71
+ }));
72
+ expect(console.error).toHaveBeenCalledWith('There is no option with the value: "value". Make sure that the value passed to the selected prop matches the value of an existing option.');
73
+ });
74
+ });
75
+ describe('not production', () => {
76
+ it('should throw an error for a selection that is not in the options', () => {
77
+ process.env.NODE_ENV = 'development';
78
+ const options = /*#__PURE__*/React.createElement(SingleSelectOption, {
79
+ key: "1",
80
+ label: "one",
81
+ value: "1"
82
+ });
83
+ const selected = 'value';
84
+ expect(() => {
85
+ render( /*#__PURE__*/React.createElement(Selection, {
86
+ selected: selected,
87
+ options: options,
88
+ disabled: false,
89
+ onChange: () => {}
90
+ }));
91
+ }).toThrow('There is no option with the value: "value". Make sure that the value passed to the selected prop matches the value of an existing option.');
92
+ });
93
+ });
94
+ });
@@ -11,15 +11,24 @@ const Selection = _ref => {
11
11
  selected,
12
12
  className
13
13
  } = _ref;
14
+ const isProduction = process.env.NODE_ENV === 'production';
14
15
  const selectedOption = findOptionChild(selected, options);
15
16
 
16
17
  if (!selectedOption) {
17
18
  const message = "There is no option with the value: \"".concat(selected, "\". ") + 'Make sure that the value passed to the selected ' + 'prop matches the value of an existing option.';
18
- throw new Error(message);
19
+
20
+ if (isProduction) {
21
+ // Don't crash the app if in production
22
+ console.error(message);
23
+ } else {
24
+ // Throw error if not in production for maximum visibility
25
+ throw new Error(message);
26
+ }
19
27
  }
20
28
 
21
- const icon = selectedOption.props.icon;
22
- const label = selectedOption.props.label;
29
+ const icon = selectedOption && selectedOption.props.icon; // Use the selected value if we do not have a label
30
+
31
+ const label = selectedOption ? selectedOption.props.label : selected;
23
32
  return /*#__PURE__*/React.createElement("div", {
24
33
  className: _JSXStyle.dynamic([["2249594316", [spacers.dp8, spacers.dp16, spacers.dp16]]]) + " " + (cx(className, 'root') || "")
25
34
  }, icon && /*#__PURE__*/React.createElement("div", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dhis2-ui/select",
3
- "version": "8.9.0",
3
+ "version": "8.10.0",
4
4
  "description": "UI Select",
5
5
  "repository": {
6
6
  "type": "git",
@@ -33,19 +33,19 @@
33
33
  },
34
34
  "dependencies": {
35
35
  "@dhis2/prop-types": "^3.1.2",
36
- "@dhis2-ui/box": "8.9.0",
37
- "@dhis2-ui/button": "8.9.0",
38
- "@dhis2-ui/card": "8.9.0",
39
- "@dhis2-ui/checkbox": "8.9.0",
40
- "@dhis2-ui/chip": "8.9.0",
41
- "@dhis2-ui/field": "8.9.0",
42
- "@dhis2-ui/input": "8.9.0",
43
- "@dhis2-ui/layer": "8.9.0",
44
- "@dhis2-ui/loader": "8.9.0",
45
- "@dhis2-ui/popper": "8.9.0",
46
- "@dhis2-ui/status-icon": "8.9.0",
47
- "@dhis2/ui-constants": "8.9.0",
48
- "@dhis2/ui-icons": "8.9.0",
36
+ "@dhis2-ui/box": "8.10.0",
37
+ "@dhis2-ui/button": "8.10.0",
38
+ "@dhis2-ui/card": "8.10.0",
39
+ "@dhis2-ui/checkbox": "8.10.0",
40
+ "@dhis2-ui/chip": "8.10.0",
41
+ "@dhis2-ui/field": "8.10.0",
42
+ "@dhis2-ui/input": "8.10.0",
43
+ "@dhis2-ui/layer": "8.10.0",
44
+ "@dhis2-ui/loader": "8.10.0",
45
+ "@dhis2-ui/popper": "8.10.0",
46
+ "@dhis2-ui/status-icon": "8.10.0",
47
+ "@dhis2/ui-constants": "8.10.0",
48
+ "@dhis2/ui-icons": "8.10.0",
49
49
  "classnames": "^2.3.1",
50
50
  "prop-types": "^15.7.2"
51
51
  },