Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STORY-7335: fix priority of pricefield helpertext #7

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions build/Component/PriceInput/PriceInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,12 @@ var Number_1 = require("../../Utilities/Format/Number");
var Definition_1 = __importDefault(require("../App/Stateless/Style/Theme/Definition"));
var PriceField = function (_a) {
var _b;
var _c = _a.currency, currency = _c === void 0 ? 'eur' : _c, valueInCent = _a.valueInCent, _d = _a.language, language = _d === void 0 ? Language_1.LANGUAGE.GERMAN : _d, _e = _a.selectOnFocus, selectOnFocus = _e === void 0 ? false : _e, _f = _a.showDecimals, showDecimals = _f === void 0 ? false : _f, _g = _a.min, min = _g === void 0 ? Number.NEGATIVE_INFINITY : _g, _h = _a.max, max = _h === void 0 ? Number.POSITIVE_INFINITY : _h, textFieldProps = _a.textFieldProps, _j = _a.currencyPosition, currencyPosition = _j === void 0 ? usePriceFieldAdornment_1.AdornmentPosition.end : _j, disabled = _a.disabled, setValue = _a.setValue, required = _a.required, error = _a.error, _k = _a.autoCorrection, autoCorrection = _k === void 0 ? false : _k, getValidationState = _a.getValidationState;
var _l = (0, usePriceFieldAdornment_1.default)(currencyPosition), position = _l[0], at = _l[1];
var _m = (0, react_intl_1.useIntl)(), formatNumber = _m.formatNumber, formatMessage = _m.formatMessage;
var _c;
var _d = _a.currency, currency = _d === void 0 ? 'eur' : _d, valueInCent = _a.valueInCent, _e = _a.language, language = _e === void 0 ? Language_1.LANGUAGE.GERMAN : _e, _f = _a.selectOnFocus, selectOnFocus = _f === void 0 ? false : _f, _g = _a.showDecimals, showDecimals = _g === void 0 ? false : _g, _h = _a.min, min = _h === void 0 ? Number.NEGATIVE_INFINITY : _h, _j = _a.max, max = _j === void 0 ? Number.POSITIVE_INFINITY : _j, textFieldProps = _a.textFieldProps, _k = _a.currencyPosition, currencyPosition = _k === void 0 ? usePriceFieldAdornment_1.AdornmentPosition.end : _k, disabled = _a.disabled, setValue = _a.setValue, required = _a.required, error = _a.error, _l = _a.autoCorrection, autoCorrection = _l === void 0 ? false : _l, getValidationState = _a.getValidationState;
var _m = (0, usePriceFieldAdornment_1.default)(currencyPosition), position = _m[0], at = _m[1];
var _o = (0, react_intl_1.useIntl)(), formatNumber = _o.formatNumber, formatMessage = _o.formatMessage;
var locale = (0, Locale_1.mapLanguageToLocale)(language);
var _o = react_1.default.useState((0, PriceInput_helper_1.getLocaleString)(locale, (0, Number_1.divideBy100)(valueInCent, showDecimals), true, showDecimals)), localValue = _o[0], setLocalValue = _o[1];
var _p = react_1.default.useState((0, PriceInput_helper_1.getLocaleString)(locale, (0, Number_1.divideBy100)(valueInCent, showDecimals), true, showDecimals)), localValue = _p[0], setLocalValue = _p[1];
var decimalSeparator = (0, Number_1.getDecimalSeparator)(locale);
var groupingSeparator = (0, Number_1.getGroupingSeparator)(locale);
var outOfRange = (!!valueInCent) && ((min !== -Infinity && valueInCent < min) || (max !== Infinity && valueInCent > max));
Expand Down Expand Up @@ -112,11 +113,11 @@ var PriceField = function (_a) {
(0, react_1.useEffect)(function () {
getValidationState === null || getValidationState === void 0 ? void 0 : getValidationState(!hasErrors);
}, [hasErrors]);
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(TextField_1.default, __assign({}, textFieldProps, { helperText: hasErrors
return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(TextField_1.default, __assign({}, textFieldProps, { helperText: ((_c = textFieldProps === null || textFieldProps === void 0 ? void 0 : textFieldProps.helperText) !== null && _c !== void 0 ? _c : hasErrors)
? outOfRange
? "min: ".concat(formatNumber(min / 100, __assign({}, (0, PriceInput_helper_1.toLocaleStringFractionOptions)(showDecimals ? 2 : 0))), " max: ").concat(formatNumber(max / 100, __assign({}, (0, PriceInput_helper_1.toLocaleStringFractionOptions)(showDecimals ? 2 : 0))))
: formatMessage({ id: 'priceField.invalid' })
: textFieldProps.helperText, value: localValue, selectOnFocus: selectOnFocus, error: hasErrors, required: required, onFocus: _onFocus, onBlur: _onBlur, onChange: _onChange, hideClearButton: disabled, InputProps: (_b = {},
: '', value: localValue, selectOnFocus: selectOnFocus, error: hasErrors, required: required, onFocus: _onFocus, onBlur: _onBlur, onChange: _onChange, hideClearButton: disabled, InputProps: (_b = {},
_b[position] = (0, jsx_runtime_1.jsx)(material_1.InputAdornment, __assign({ position: at }, { children: (0, jsx_runtime_1.jsx)(material_1.Typography, __assign({ color: disabled ? Definition_1.default.palette.text.disabled : 'inherit' }, { children: Format_1.Currency.getCurrencySign(currency) })) })),
_b), disabled: disabled })) });
};
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@elumeo/jfs-core",
"version": "11.2.4",
"version": "11.2.5",
"description": "Foundation for all JFS Apps",
"main": "Main.js",
"directories": {
Expand Down
14 changes: 8 additions & 6 deletions src/Component/PriceInput/PriceInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const PriceField: React.FC<Props> = ({
const localizedValue = getLocaleString(locale, divideBy100(parsedValue, showDecimals), true, showDecimals)
setLocalValue(localizedValue);
} else {
if(autoCorrection) {
if (autoCorrection) {
setValue(valueInCent);
setLocalValue(!divideBy100(valueInCent, showDecimals)
? null
Expand All @@ -123,11 +123,13 @@ const PriceField: React.FC<Props> = ({
return <>
<TextFieldClearButton
{...textFieldProps as TextFieldProps}
helperText={hasErrors
? outOfRange
? `min: ${formatNumber(min / 100, { ...toLocaleStringFractionOptions(showDecimals ? 2 : 0) })} max: ${formatNumber(max / 100, { ...toLocaleStringFractionOptions(showDecimals ? 2 : 0) })}`
: formatMessage({ id: 'priceField.invalid' })
: textFieldProps.helperText}
helperText={
textFieldProps?.helperText ?? hasErrors
? outOfRange
? `min: ${formatNumber(min / 100, { ...toLocaleStringFractionOptions(showDecimals ? 2 : 0) })} max: ${formatNumber(max / 100, { ...toLocaleStringFractionOptions(showDecimals ? 2 : 0) })}`
: formatMessage({ id: 'priceField.invalid' })
: undefined
}
value={localValue}
selectOnFocus={selectOnFocus}
error={hasErrors}
Expand Down