orc-shared 5.8.0-dev.6 → 5.8.0-dev.8
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/dist/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js +12 -5
- package/dist/components/MaterialUI/Inputs/InputBase.js +3 -0
- package/dist/utils/inputHelper.js +59 -0
- package/package.json +1 -1
- package/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.js +8 -3
- package/src/components/MaterialUI/Inputs/InputBase.js +2 -0
- package/src/components/MaterialUI/Inputs/InputBase.test.js +49 -0
- package/src/utils/inputHelper.js +6 -0
- package/src/utils/inputHelper.test.js +31 -0
|
@@ -20,6 +20,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
20
20
|
var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
|
|
21
21
|
enterModule && enterModule(module);
|
|
22
22
|
})();
|
|
23
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
24
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
|
|
25
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
23
26
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
24
27
|
return a;
|
|
25
28
|
};
|
|
@@ -30,12 +33,13 @@ var useStyles = (0, _styles.makeStyles)(function (theme) {
|
|
|
30
33
|
return {
|
|
31
34
|
title: {
|
|
32
35
|
fontSize: theme.typography.fieldLabelSize,
|
|
33
|
-
color:
|
|
34
|
-
return !props.error ? theme.palette.text.hint : theme.palette.error.main;
|
|
35
|
-
},
|
|
36
|
+
color: theme.palette.text.hint,
|
|
36
37
|
fontFamily: theme.typography.fontFamily,
|
|
37
38
|
marginBottom: theme.spacing(1)
|
|
38
39
|
},
|
|
40
|
+
titleError: {
|
|
41
|
+
color: theme.palette.error.main
|
|
42
|
+
},
|
|
39
43
|
titleRequired: {
|
|
40
44
|
paddingLeft: theme.spacing(0.5),
|
|
41
45
|
color: theme.palette.error.main
|
|
@@ -110,10 +114,12 @@ var InformationItemHeader = function InformationItemHeader(_ref2) {
|
|
|
110
114
|
label = _ref2.label,
|
|
111
115
|
headerIcon = _ref2.headerIcon,
|
|
112
116
|
headerIconClassName = _ref2.headerIconClassName,
|
|
113
|
-
required = _ref2.required
|
|
117
|
+
required = _ref2.required,
|
|
118
|
+
error = _ref2.error;
|
|
114
119
|
var formattedLabel = typeof label === "object" ? /*#__PURE__*/_react.default.createElement(_reactIntl.FormattedMessage, label) : label;
|
|
120
|
+
var titleClasses = (0, _classnames.default)(classes.title, _defineProperty({}, classes.titleError, error));
|
|
115
121
|
var headerText = (_ref3 = formattedLabel && /*#__PURE__*/_react.default.createElement(_Typography.default, {
|
|
116
|
-
className:
|
|
122
|
+
className: titleClasses,
|
|
117
123
|
children: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, formattedLabel, required && /*#__PURE__*/_react.default.createElement("span", {
|
|
118
124
|
"data-qa": "required",
|
|
119
125
|
className: classes.titleRequired
|
|
@@ -157,6 +163,7 @@ var InformationItem = function InformationItem(_ref4) {
|
|
|
157
163
|
classes: classes,
|
|
158
164
|
label: label,
|
|
159
165
|
required: required,
|
|
166
|
+
error: error,
|
|
160
167
|
headerIcon: headerIcon,
|
|
161
168
|
headerIconClassName: headerIconClassName
|
|
162
169
|
}), /*#__PURE__*/_react.default.createElement(InformationItemChildren, {
|
|
@@ -8,6 +8,7 @@ var _InputBase = _interopRequireDefault(require("@material-ui/core/InputBase"));
|
|
|
8
8
|
var _InputBaseProps = _interopRequireWildcard(require("./InputBaseProps"));
|
|
9
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
10
|
var _reactNumberFormat = require("react-number-format");
|
|
11
|
+
var _inputHelper = require("../../../utils/inputHelper");
|
|
11
12
|
var _excluded = ["inputRef", "onChange"];
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
14
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
|
@@ -227,11 +228,13 @@ var InputBase = function InputBase(_ref) {
|
|
|
227
228
|
timerId.current = null;
|
|
228
229
|
}
|
|
229
230
|
if (isAdvancedNumericInput) {
|
|
231
|
+
var _numericInputProps$de2;
|
|
230
232
|
var formattingProps = _objectSpread({}, numericInputProps);
|
|
231
233
|
delete formattingProps.blurFormattingSkipFixedDecimalScale;
|
|
232
234
|
if ((numericInputProps == null ? void 0 : numericInputProps.blurFormattingSkipFixedDecimalScale) !== true) {
|
|
233
235
|
formattingProps.fixedDecimalScale = true;
|
|
234
236
|
}
|
|
237
|
+
updateValue = (0, _inputHelper.trimSpacesAndLeadingZeros)(updateValue, (_numericInputProps$de2 = numericInputProps == null ? void 0 : numericInputProps.defaultValue) != null ? _numericInputProps$de2 : "");
|
|
235
238
|
updateValue = (0, _reactNumberFormat.numericFormatter)(updateValue, formattingProps);
|
|
236
239
|
}
|
|
237
240
|
update(updateValue, metadata);
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
exports.__esModule = true;
|
|
4
|
+
exports.trimSpacesAndLeadingZeros = exports.limitNumericValueLength = void 0;
|
|
5
|
+
(function () {
|
|
6
|
+
var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
|
|
7
|
+
enterModule && enterModule(module);
|
|
8
|
+
})();
|
|
9
|
+
(function () {
|
|
10
|
+
var enterModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.enterModule : undefined;
|
|
11
|
+
enterModule && enterModule(module);
|
|
12
|
+
})();
|
|
13
|
+
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
14
|
+
return a;
|
|
15
|
+
};
|
|
16
|
+
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var trimSpacesAndLeadingZeros = exports.trimSpacesAndLeadingZeros = function trimSpacesAndLeadingZeros(value, fallback) {
|
|
20
|
+
if (fallback === void 0) {
|
|
21
|
+
fallback = "";
|
|
22
|
+
}
|
|
23
|
+
var trimmed = (value != null ? value : "").trim().replace(/^0+/, "");
|
|
24
|
+
return trimmed === "" ? fallback : limitNumericValueLength(trimmed);
|
|
25
|
+
};
|
|
26
|
+
var limitNumericValueLength = exports.limitNumericValueLength = function limitNumericValueLength(value, maximum) {
|
|
27
|
+
if (maximum === void 0) {
|
|
28
|
+
maximum = 9;
|
|
29
|
+
}
|
|
30
|
+
return value.substring(0, maximum);
|
|
31
|
+
};
|
|
32
|
+
;
|
|
33
|
+
(function () {
|
|
34
|
+
var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
|
|
35
|
+
if (!reactHotLoader) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
reactHotLoader.register(trimSpacesAndLeadingZeros, "trimSpacesAndLeadingZeros", "/home/vsts/work/1/s/src/utils/inputHelper.js");
|
|
39
|
+
reactHotLoader.register(limitNumericValueLength, "limitNumericValueLength", "/home/vsts/work/1/s/src/utils/inputHelper.js");
|
|
40
|
+
})();
|
|
41
|
+
;
|
|
42
|
+
(function () {
|
|
43
|
+
var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
|
|
44
|
+
leaveModule && leaveModule(module);
|
|
45
|
+
})();
|
|
46
|
+
;
|
|
47
|
+
(function () {
|
|
48
|
+
var reactHotLoader = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default : undefined;
|
|
49
|
+
if (!reactHotLoader) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
reactHotLoader.register(trimSpacesAndLeadingZeros, "trimSpacesAndLeadingZeros", "/home/vsts/work/1/s/src/utils/inputHelper.js");
|
|
53
|
+
reactHotLoader.register(limitNumericValueLength, "limitNumericValueLength", "/home/vsts/work/1/s/src/utils/inputHelper.js");
|
|
54
|
+
})();
|
|
55
|
+
;
|
|
56
|
+
(function () {
|
|
57
|
+
var leaveModule = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.leaveModule : undefined;
|
|
58
|
+
leaveModule && leaveModule(module);
|
|
59
|
+
})();
|
package/package.json
CHANGED
|
@@ -12,10 +12,13 @@ import classNames from "classnames";
|
|
|
12
12
|
const useStyles = makeStyles(theme => ({
|
|
13
13
|
title: {
|
|
14
14
|
fontSize: theme.typography.fieldLabelSize,
|
|
15
|
-
color:
|
|
15
|
+
color: theme.palette.text.hint,
|
|
16
16
|
fontFamily: theme.typography.fontFamily,
|
|
17
17
|
marginBottom: theme.spacing(1),
|
|
18
18
|
},
|
|
19
|
+
titleError: {
|
|
20
|
+
color: theme.palette.error.main,
|
|
21
|
+
},
|
|
19
22
|
titleRequired: {
|
|
20
23
|
paddingLeft: theme.spacing(0.5),
|
|
21
24
|
color: theme.palette.error.main,
|
|
@@ -76,12 +79,13 @@ const InformationItemChildren = ({
|
|
|
76
79
|
return <MultipleLinesText textProps={multipleLinesTextProps} children={value} tooltipClasses={tooltipClasses} />;
|
|
77
80
|
};
|
|
78
81
|
|
|
79
|
-
const InformationItemHeader = ({ classes, label, headerIcon, headerIconClassName, required }) => {
|
|
82
|
+
const InformationItemHeader = ({ classes, label, headerIcon, headerIconClassName, required, error }) => {
|
|
80
83
|
const formattedLabel = typeof label === "object" ? <FormattedMessage {...label} /> : label;
|
|
84
|
+
const titleClasses = classNames(classes.title, { [classes.titleError]: error });
|
|
81
85
|
const headerText =
|
|
82
86
|
(formattedLabel && (
|
|
83
87
|
<Typography
|
|
84
|
-
className={
|
|
88
|
+
className={titleClasses}
|
|
85
89
|
children={
|
|
86
90
|
<>
|
|
87
91
|
{formattedLabel}
|
|
@@ -129,6 +133,7 @@ const InformationItem = ({
|
|
|
129
133
|
classes={classes}
|
|
130
134
|
label={label}
|
|
131
135
|
required={required}
|
|
136
|
+
error={error}
|
|
132
137
|
headerIcon={headerIcon}
|
|
133
138
|
headerIconClassName={headerIconClassName}
|
|
134
139
|
/>
|
|
@@ -4,6 +4,7 @@ import InputBaseMUI from "@material-ui/core/InputBase";
|
|
|
4
4
|
import InputBaseProps, { isInputProps } from "./InputBaseProps";
|
|
5
5
|
import classNames from "classnames";
|
|
6
6
|
import { NumericFormat, numericFormatter } from "react-number-format";
|
|
7
|
+
import { trimSpacesAndLeadingZeros } from "../../../utils/inputHelper";
|
|
7
8
|
|
|
8
9
|
export const useStyles = makeStyles(theme => ({
|
|
9
10
|
container: {
|
|
@@ -207,6 +208,7 @@ const InputBase = ({ inputProps }) => {
|
|
|
207
208
|
formattingProps.fixedDecimalScale = true;
|
|
208
209
|
}
|
|
209
210
|
|
|
211
|
+
updateValue = trimSpacesAndLeadingZeros(updateValue, numericInputProps?.defaultValue ?? "");
|
|
210
212
|
updateValue = numericFormatter(updateValue, formattingProps);
|
|
211
213
|
}
|
|
212
214
|
|
|
@@ -643,6 +643,55 @@ describe("AdvancedNumericInput", () => {
|
|
|
643
643
|
expect(update, "to have calls satisfying", [{ args: ["12.20", metadata] }]);
|
|
644
644
|
});
|
|
645
645
|
|
|
646
|
+
it("OnBlur trims spaces and leading zeros of values", () => {
|
|
647
|
+
const inputProps = new InputBaseProps();
|
|
648
|
+
const aLabel = "aLabel";
|
|
649
|
+
const aValue = "012.2";
|
|
650
|
+
const metadata = {
|
|
651
|
+
test: "value",
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
inputProps.set(InputBaseProps.propNames.update, update);
|
|
655
|
+
inputProps.set(InputBaseProps.propNames.value, aValue);
|
|
656
|
+
inputProps.set(InputBaseProps.propNames.label, aLabel);
|
|
657
|
+
inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
|
|
658
|
+
inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 1 });
|
|
659
|
+
inputProps.set(InputBaseProps.propNames.metadata, metadata);
|
|
660
|
+
|
|
661
|
+
const component = <InputBase inputProps={inputProps} />;
|
|
662
|
+
const mountedComponent = mount(component);
|
|
663
|
+
const input = mountedComponent.find("input");
|
|
664
|
+
|
|
665
|
+
input.simulate("blur", {});
|
|
666
|
+
|
|
667
|
+
// Update is called twice, once from onChangeHandler (from React) and once from onBlurInternal
|
|
668
|
+
expect(update, "to have calls satisfying", [{ args: ["12.2", metadata] }, { args: ["12.2", metadata] }]);
|
|
669
|
+
});
|
|
670
|
+
|
|
671
|
+
it("OnBlur use default value if trim spaces and leading zeroes returns empty ", () => {
|
|
672
|
+
const inputProps = new InputBaseProps();
|
|
673
|
+
const aLabel = "aLabel";
|
|
674
|
+
const aValue = "";
|
|
675
|
+
const metadata = {
|
|
676
|
+
test: "value",
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
inputProps.set(InputBaseProps.propNames.update, update);
|
|
680
|
+
inputProps.set(InputBaseProps.propNames.value, aValue);
|
|
681
|
+
inputProps.set(InputBaseProps.propNames.label, aLabel);
|
|
682
|
+
inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
|
|
683
|
+
inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 2, defaultValue: "84" });
|
|
684
|
+
inputProps.set(InputBaseProps.propNames.metadata, metadata);
|
|
685
|
+
|
|
686
|
+
const component = <InputBase inputProps={inputProps} />;
|
|
687
|
+
const mountedComponent = mount(component);
|
|
688
|
+
const input = mountedComponent.find("input");
|
|
689
|
+
|
|
690
|
+
input.simulate("blur", {});
|
|
691
|
+
|
|
692
|
+
expect(update, "to have calls satisfying", [{ args: ["84.00", metadata] }]);
|
|
693
|
+
});
|
|
694
|
+
|
|
646
695
|
it("Onblur send a formatted string instead of a number", () => {
|
|
647
696
|
const inputProps = new InputBaseProps();
|
|
648
697
|
const aLabel = "aLabel";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const trimSpacesAndLeadingZeros = (value, fallback = "") => {
|
|
2
|
+
const trimmed = (value ?? "").trim().replace(/^0+/, "");
|
|
3
|
+
return trimmed === "" ? fallback : limitNumericValueLength(trimmed);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
export const limitNumericValueLength = (value, maximum = 9) => value.substring(0, maximum);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { limitNumericValueLength, trimSpacesAndLeadingZeros } from "./inputHelper";
|
|
2
|
+
|
|
3
|
+
describe("Numeric Input Helper", () => {
|
|
4
|
+
it("trimSpacesAndLeadingZeros trims spaces and leading zeros", () => {
|
|
5
|
+
expect(trimSpacesAndLeadingZeros, "when called with", [" 00013 "], "to equal", "13");
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("trimSpacesAndLeadingZeros trims spaces and leading zeros returning fallback value", () => {
|
|
9
|
+
expect(trimSpacesAndLeadingZeros, "when called with", [" 000 ", "def"], "to equal", "def");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("trimSpacesAndLeadingZeros should work on floating values", () => {
|
|
13
|
+
expect(trimSpacesAndLeadingZeros, "when called with", ["042.2", "def"], "to equal", "42.2");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("trimSpacesAndLeadingZeros returns fallback on null value", () => {
|
|
17
|
+
expect(trimSpacesAndLeadingZeros, "when called with", [null, "def"], "to equal", "def");
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
it("trimSpacesAndLeadingZeros returns fallback on undefined value", () => {
|
|
21
|
+
expect(trimSpacesAndLeadingZeros, "when called with", [undefined, "def"], "to equal", "def");
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("limitNumericValueLength trims extra characters", () => {
|
|
25
|
+
expect(limitNumericValueLength, "when called with", ["01234567890"], "to equal", "012345678");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("limitNumericValueLength trims extra characters with another maximum", () => {
|
|
29
|
+
expect(limitNumericValueLength, "when called with", ["01234567890", 5], "to equal", "01234");
|
|
30
|
+
});
|
|
31
|
+
});
|