@trackunit/custom-field-components 0.0.423-alpha-038f8e0f69.0 → 0.0.423
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/index.cjs +11 -10
- package/index.js +11 -10
- package/package.json +7 -7
package/index.cjs
CHANGED
|
@@ -3450,13 +3450,12 @@ const getPhoneNumberValidationRules = (definition) => {
|
|
|
3450
3450
|
* @returns { JSX.Element } A JSX.Element or null if the field definition is undefined
|
|
3451
3451
|
*/
|
|
3452
3452
|
const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldId) => {
|
|
3453
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2
|
|
3453
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
3454
3454
|
const [isEditing, setIsEditing] = React.useState(false);
|
|
3455
3455
|
const [numberValue, setNumberValue] = React.useState(() => {
|
|
3456
|
-
var _a;
|
|
3457
3456
|
if ((field === null || field === void 0 ? void 0 : field.definition) && field.definition.type === irisAppRuntimeCoreApi.CustomFieldType.NUMBER) {
|
|
3458
3457
|
const typedValue = field.value;
|
|
3459
|
-
return
|
|
3458
|
+
return typedValue.numberValue;
|
|
3460
3459
|
}
|
|
3461
3460
|
else {
|
|
3462
3461
|
return "";
|
|
@@ -3499,29 +3498,31 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
3499
3498
|
}
|
|
3500
3499
|
case irisAppRuntimeCoreApi.CustomFieldType.NUMBER: {
|
|
3501
3500
|
const typedDefinition = field.definition;
|
|
3502
|
-
const typedValue = field.value;
|
|
3503
3501
|
const rules = getNumberValidationRules(typedDefinition);
|
|
3504
|
-
const unit = unitPreference === "US_CUSTOMARY" ? typedDefinition.unitUs : typedDefinition.unitSi;
|
|
3502
|
+
const unit = unitPreference === "US_CUSTOMARY" && typedDefinition.unitUs ? typedDefinition.unitUs : typedDefinition.unitSi;
|
|
3505
3503
|
const numberProps = {
|
|
3506
3504
|
placeholder: (_t = typedDefinition.title) !== null && _t !== void 0 ? _t : "",
|
|
3507
3505
|
addonAfter: unit,
|
|
3508
3506
|
};
|
|
3509
|
-
|
|
3510
|
-
|
|
3507
|
+
const value = numberValue === undefined || numberValue === null || numberValue === ""
|
|
3508
|
+
? ""
|
|
3509
|
+
: parseFloat(Number(numberValue).toPrecision(4));
|
|
3510
|
+
return (jsxRuntime.jsx(reactFormComponents.FormGroup, { htmlFor: isEditing ? key || "number-field" : `${key}-number-field`, label: title, isInvalid: errorMessage ? true : false, helpText: errorMessage || description, dataTestId: `${typedDefinition.key}-FormGroup`, disabled: !typedDefinition.uiEditable, children: isEditing ? (jsxRuntime.jsx(reactFormComponents.NumberInput, Object.assign({ id: key || "number-field", dataTestId: typedDefinition.key ? typedDefinition.key : `numberField`, defaultValue: value, readOnly: !typedDefinition.uiEditable, step: typedDefinition.isInteger ? 1 : "any", min: (_u = typedDefinition.minimumNumber) !== null && _u !== void 0 ? _u : undefined, max: (_v = typedDefinition.maximumNumber) !== null && _v !== void 0 ? _v : undefined }, validation.register(key, rules), { onBlur: () => setIsEditing(!isEditing), onChange: e => {
|
|
3511
|
+
setNumberValue(e.target.value === "" ? null : e.target.value);
|
|
3511
3512
|
validation.register(key, rules).onChange(e);
|
|
3512
|
-
} }, numberProps))) : (jsxRuntime.jsx(reactFormComponents.BaseInput, Object.assign({ type: "text", id: `${key}-number-field`, dataTestId: `${typedDefinition.key}`, defaultValue:
|
|
3513
|
+
} }, numberProps))) : (jsxRuntime.jsx(reactFormComponents.BaseInput, Object.assign({ type: "text", id: `${key}-number-field`, dataTestId: `${typedDefinition.key}`, defaultValue: value, readOnly: true, actions: jsxRuntime.jsx(ActionContainer, { children: jsxRuntime.jsx(StyledIconButton, { dataTestId: `${typedDefinition.key}-editIconButtonId`, size: "small", color: "tertiary", icon: jsxRuntime.jsx(reactComponents.Icon, { size: "small", name: "PencilIcon" }), onClick: () => setIsEditing(!isEditing) }) }) }, numberProps))) }));
|
|
3513
3514
|
}
|
|
3514
3515
|
case irisAppRuntimeCoreApi.CustomFieldType.BOOLEAN: {
|
|
3515
3516
|
const typedDefinition = field.definition;
|
|
3516
3517
|
const typedValue = field.value;
|
|
3517
3518
|
const rules = getBooleanValidationRules();
|
|
3518
|
-
return (jsxRuntime.jsx(BooleanCustomField, { label: (
|
|
3519
|
+
return (jsxRuntime.jsx(BooleanCustomField, { label: (_w = typedDefinition.title) !== null && _w !== void 0 ? _w : "", id: key || "boolean-field", defaultValue: (_y = (_x = typedValue.booleanValue) !== null && _x !== void 0 ? _x : typedDefinition.defaultBooleanValue) !== null && _y !== void 0 ? _y : undefined, readOnly: !typedDefinition.uiEditable, register: validation.register, validationRules: rules, helpText: description, setValue: validation.setValue, errorMessage: errorMessage, dataTestId: `${typedDefinition.key}` }, key));
|
|
3519
3520
|
}
|
|
3520
3521
|
case irisAppRuntimeCoreApi.CustomFieldType.DROPDOWN: {
|
|
3521
3522
|
const typedDefinition = field.definition;
|
|
3522
3523
|
const typedValue = field.value;
|
|
3523
3524
|
const rules = getDropdownValidationRules();
|
|
3524
|
-
return (jsxRuntime.jsx(DropdownCustomField, { label: typedDefinition.title || "", id: key || "dropdown-field", defaultValue: (
|
|
3525
|
+
return (jsxRuntime.jsx(DropdownCustomField, { label: typedDefinition.title || "", id: key || "dropdown-field", defaultValue: (_0 = (_z = typedValue.stringArrayValue) !== null && _z !== void 0 ? _z : typedDefinition.defaultStringArrayValue) !== null && _0 !== void 0 ? _0 : undefined, disabled: !typedDefinition.uiEditable, allValues: (_1 = typedDefinition.allValues) !== null && _1 !== void 0 ? _1 : undefined, multiSelect: (_2 = typedDefinition.multiSelect) !== null && _2 !== void 0 ? _2 : false, register: validation.register, validationRules: rules, helpText: description, setValue: validation.setValue, errorMessage: errorMessage, dataTestId: `${typedDefinition.key}` }, key));
|
|
3525
3526
|
}
|
|
3526
3527
|
case irisAppRuntimeCoreApi.CustomFieldType.DATE: {
|
|
3527
3528
|
const typedDefinition = field.definition;
|
package/index.js
CHANGED
|
@@ -3427,13 +3427,12 @@ const getPhoneNumberValidationRules = (definition) => {
|
|
|
3427
3427
|
* @returns { JSX.Element } A JSX.Element or null if the field definition is undefined
|
|
3428
3428
|
*/
|
|
3429
3429
|
const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldId) => {
|
|
3430
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2
|
|
3430
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
|
|
3431
3431
|
const [isEditing, setIsEditing] = useState(false);
|
|
3432
3432
|
const [numberValue, setNumberValue] = useState(() => {
|
|
3433
|
-
var _a;
|
|
3434
3433
|
if ((field === null || field === void 0 ? void 0 : field.definition) && field.definition.type === CustomFieldType.NUMBER) {
|
|
3435
3434
|
const typedValue = field.value;
|
|
3436
|
-
return
|
|
3435
|
+
return typedValue.numberValue;
|
|
3437
3436
|
}
|
|
3438
3437
|
else {
|
|
3439
3438
|
return "";
|
|
@@ -3476,29 +3475,31 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
3476
3475
|
}
|
|
3477
3476
|
case CustomFieldType.NUMBER: {
|
|
3478
3477
|
const typedDefinition = field.definition;
|
|
3479
|
-
const typedValue = field.value;
|
|
3480
3478
|
const rules = getNumberValidationRules(typedDefinition);
|
|
3481
|
-
const unit = unitPreference === "US_CUSTOMARY" ? typedDefinition.unitUs : typedDefinition.unitSi;
|
|
3479
|
+
const unit = unitPreference === "US_CUSTOMARY" && typedDefinition.unitUs ? typedDefinition.unitUs : typedDefinition.unitSi;
|
|
3482
3480
|
const numberProps = {
|
|
3483
3481
|
placeholder: (_t = typedDefinition.title) !== null && _t !== void 0 ? _t : "",
|
|
3484
3482
|
addonAfter: unit,
|
|
3485
3483
|
};
|
|
3486
|
-
|
|
3487
|
-
|
|
3484
|
+
const value = numberValue === undefined || numberValue === null || numberValue === ""
|
|
3485
|
+
? ""
|
|
3486
|
+
: parseFloat(Number(numberValue).toPrecision(4));
|
|
3487
|
+
return (jsx(FormGroup, { htmlFor: isEditing ? key || "number-field" : `${key}-number-field`, label: title, isInvalid: errorMessage ? true : false, helpText: errorMessage || description, dataTestId: `${typedDefinition.key}-FormGroup`, disabled: !typedDefinition.uiEditable, children: isEditing ? (jsx(NumberInput, Object.assign({ id: key || "number-field", dataTestId: typedDefinition.key ? typedDefinition.key : `numberField`, defaultValue: value, readOnly: !typedDefinition.uiEditable, step: typedDefinition.isInteger ? 1 : "any", min: (_u = typedDefinition.minimumNumber) !== null && _u !== void 0 ? _u : undefined, max: (_v = typedDefinition.maximumNumber) !== null && _v !== void 0 ? _v : undefined }, validation.register(key, rules), { onBlur: () => setIsEditing(!isEditing), onChange: e => {
|
|
3488
|
+
setNumberValue(e.target.value === "" ? null : e.target.value);
|
|
3488
3489
|
validation.register(key, rules).onChange(e);
|
|
3489
|
-
} }, numberProps))) : (jsx(BaseInput, Object.assign({ type: "text", id: `${key}-number-field`, dataTestId: `${typedDefinition.key}`, defaultValue:
|
|
3490
|
+
} }, numberProps))) : (jsx(BaseInput, Object.assign({ type: "text", id: `${key}-number-field`, dataTestId: `${typedDefinition.key}`, defaultValue: value, readOnly: true, actions: jsx(ActionContainer, { children: jsx(StyledIconButton, { dataTestId: `${typedDefinition.key}-editIconButtonId`, size: "small", color: "tertiary", icon: jsx(Icon, { size: "small", name: "PencilIcon" }), onClick: () => setIsEditing(!isEditing) }) }) }, numberProps))) }));
|
|
3490
3491
|
}
|
|
3491
3492
|
case CustomFieldType.BOOLEAN: {
|
|
3492
3493
|
const typedDefinition = field.definition;
|
|
3493
3494
|
const typedValue = field.value;
|
|
3494
3495
|
const rules = getBooleanValidationRules();
|
|
3495
|
-
return (jsx(BooleanCustomField, { label: (
|
|
3496
|
+
return (jsx(BooleanCustomField, { label: (_w = typedDefinition.title) !== null && _w !== void 0 ? _w : "", id: key || "boolean-field", defaultValue: (_y = (_x = typedValue.booleanValue) !== null && _x !== void 0 ? _x : typedDefinition.defaultBooleanValue) !== null && _y !== void 0 ? _y : undefined, readOnly: !typedDefinition.uiEditable, register: validation.register, validationRules: rules, helpText: description, setValue: validation.setValue, errorMessage: errorMessage, dataTestId: `${typedDefinition.key}` }, key));
|
|
3496
3497
|
}
|
|
3497
3498
|
case CustomFieldType.DROPDOWN: {
|
|
3498
3499
|
const typedDefinition = field.definition;
|
|
3499
3500
|
const typedValue = field.value;
|
|
3500
3501
|
const rules = getDropdownValidationRules();
|
|
3501
|
-
return (jsx(DropdownCustomField, { label: typedDefinition.title || "", id: key || "dropdown-field", defaultValue: (
|
|
3502
|
+
return (jsx(DropdownCustomField, { label: typedDefinition.title || "", id: key || "dropdown-field", defaultValue: (_0 = (_z = typedValue.stringArrayValue) !== null && _z !== void 0 ? _z : typedDefinition.defaultStringArrayValue) !== null && _0 !== void 0 ? _0 : undefined, disabled: !typedDefinition.uiEditable, allValues: (_1 = typedDefinition.allValues) !== null && _1 !== void 0 ? _1 : undefined, multiSelect: (_2 = typedDefinition.multiSelect) !== null && _2 !== void 0 ? _2 : false, register: validation.register, validationRules: rules, helpText: description, setValue: validation.setValue, errorMessage: errorMessage, dataTestId: `${typedDefinition.key}` }, key));
|
|
3502
3503
|
}
|
|
3503
3504
|
case CustomFieldType.DATE: {
|
|
3504
3505
|
const typedDefinition = field.definition;
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/custom-field-components",
|
|
3
|
-
"version": "0.0.423
|
|
3
|
+
"version": "0.0.423",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"engines": {
|
|
7
7
|
"node": ">=18.x"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@trackunit/iris-app-runtime-core": "0.3.62
|
|
11
|
-
"@trackunit/iris-app-runtime-core-api": "0.3.
|
|
12
|
-
"@trackunit/react-components": "0.1.
|
|
13
|
-
"@trackunit/react-core-contexts-test": "0.1.89
|
|
14
|
-
"@trackunit/react-form-components": "0.0.
|
|
15
|
-
"@trackunit/tailwind-styled-components": "0.0.
|
|
10
|
+
"@trackunit/iris-app-runtime-core": "0.3.62",
|
|
11
|
+
"@trackunit/iris-app-runtime-core-api": "0.3.55",
|
|
12
|
+
"@trackunit/react-components": "0.1.135",
|
|
13
|
+
"@trackunit/react-core-contexts-test": "0.1.89",
|
|
14
|
+
"@trackunit/react-form-components": "0.0.98",
|
|
15
|
+
"@trackunit/tailwind-styled-components": "0.0.60",
|
|
16
16
|
"libphonenumber-js": "1.10.36",
|
|
17
17
|
"react": "18.2.0",
|
|
18
18
|
"react-hook-form": "7.40.0",
|