@trackunit/custom-field-components 0.0.445 → 0.0.448

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.js CHANGED
@@ -3449,7 +3449,7 @@ const getPhoneNumberValidationRules = (definition) => {
3449
3449
  * @returns { JSX.Element } A JSX.Element or null if the field definition is undefined
3450
3450
  */
3451
3451
  const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldId) => {
3452
- 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;
3452
+ 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, _3, _4, _5;
3453
3453
  const [isEditing, setIsEditing] = React.useState(false);
3454
3454
  const [numberValue, setNumberValue] = React.useState(() => {
3455
3455
  if ((field === null || field === void 0 ? void 0 : field.definition) && field.definition.type === irisAppRuntimeCoreApi.CustomFieldType.NUMBER) {
@@ -3536,6 +3536,23 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
3536
3536
  }
3537
3537
  return (jsxRuntime.jsx(DateCustomField, { dataTestId: `${typedDefinition.key}`, id: key || "date-field", defaultValue: defaultValue, readOnly: !typedDefinition.uiEditable, register: validation.register, label: typedDefinition.title || "", validationRules: rules, helpText: description, errorMessage: errorMessage, setValue: validation.setValue, title: field.definition.title || "" }, key));
3538
3538
  }
3539
+ case irisAppRuntimeCoreApi.CustomFieldType.JSON: {
3540
+ return jsxRuntime.jsx("div", {});
3541
+ }
3542
+ case irisAppRuntimeCoreApi.CustomFieldType.MONETARY: {
3543
+ const rules = getNumberValidationRules(field.definition);
3544
+ const numberProps = {
3545
+ placeholder: (_3 = field.definition.title) !== null && _3 !== void 0 ? _3 : "",
3546
+ addonAfter: field.definition.currency,
3547
+ };
3548
+ const value = numberValue === undefined || numberValue === null || numberValue === ""
3549
+ ? ""
3550
+ : parseFloat(Number(numberValue).toPrecision(4));
3551
+ return (jsxRuntime.jsx(reactFormComponents.FormGroup, { htmlFor: isEditing ? key || "number-field" : `${key}-number-field`, label: title, isInvalid: errorMessage ? true : false, helpText: errorMessage || description, dataTestId: `${field.definition.key}-FormGroup`, disabled: !field.definition.uiEditable, children: isEditing ? (jsxRuntime.jsx(reactFormComponents.NumberInput, Object.assign({ id: key || "number-field", dataTestId: field.definition.key ? field.definition.key : `monetaryField`, defaultValue: value, readOnly: !field.definition.uiEditable, step: "any", min: (_4 = field.definition.minimumNumber) !== null && _4 !== void 0 ? _4 : undefined, max: (_5 = field.definition.maximumNumber) !== null && _5 !== void 0 ? _5 : undefined }, validation.register(key, rules), { onBlur: () => setIsEditing(!isEditing), onChange: e => {
3552
+ setNumberValue(e.target.value === "" ? null : e.target.value);
3553
+ validation.register(key, rules).onChange(e);
3554
+ } }, numberProps))) : (jsxRuntime.jsx(reactFormComponents.BaseInput, Object.assign({ type: "text", id: `${key}-monetary-field`, dataTestId: `${field.definition.key}`, defaultValue: value, readOnly: true, actions: jsxRuntime.jsx("div", { className: "tu-action-container", children: jsxRuntime.jsx(reactComponents.IconButton, { className: "tu-action-button", dataTestId: `${field.definition.key}-editIconButtonId`, size: "small", color: "tertiary", icon: jsxRuntime.jsx(reactComponents.Icon, { size: "small", name: "PencilIcon" }), onClick: () => setIsEditing(!isEditing) }) }) }, numberProps))) }));
3555
+ }
3539
3556
  default:
3540
3557
  throw new Error(`Type not supported: ${type}`);
3541
3558
  }
package/index.esm.js CHANGED
@@ -3426,7 +3426,7 @@ const getPhoneNumberValidationRules = (definition) => {
3426
3426
  * @returns { JSX.Element } A JSX.Element or null if the field definition is undefined
3427
3427
  */
3428
3428
  const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldId) => {
3429
- 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;
3429
+ 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, _3, _4, _5;
3430
3430
  const [isEditing, setIsEditing] = useState(false);
3431
3431
  const [numberValue, setNumberValue] = useState(() => {
3432
3432
  if ((field === null || field === void 0 ? void 0 : field.definition) && field.definition.type === CustomFieldType.NUMBER) {
@@ -3513,6 +3513,23 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
3513
3513
  }
3514
3514
  return (jsx(DateCustomField, { dataTestId: `${typedDefinition.key}`, id: key || "date-field", defaultValue: defaultValue, readOnly: !typedDefinition.uiEditable, register: validation.register, label: typedDefinition.title || "", validationRules: rules, helpText: description, errorMessage: errorMessage, setValue: validation.setValue, title: field.definition.title || "" }, key));
3515
3515
  }
3516
+ case CustomFieldType.JSON: {
3517
+ return jsx("div", {});
3518
+ }
3519
+ case CustomFieldType.MONETARY: {
3520
+ const rules = getNumberValidationRules(field.definition);
3521
+ const numberProps = {
3522
+ placeholder: (_3 = field.definition.title) !== null && _3 !== void 0 ? _3 : "",
3523
+ addonAfter: field.definition.currency,
3524
+ };
3525
+ const value = numberValue === undefined || numberValue === null || numberValue === ""
3526
+ ? ""
3527
+ : parseFloat(Number(numberValue).toPrecision(4));
3528
+ return (jsx(FormGroup, { htmlFor: isEditing ? key || "number-field" : `${key}-number-field`, label: title, isInvalid: errorMessage ? true : false, helpText: errorMessage || description, dataTestId: `${field.definition.key}-FormGroup`, disabled: !field.definition.uiEditable, children: isEditing ? (jsx(NumberInput, Object.assign({ id: key || "number-field", dataTestId: field.definition.key ? field.definition.key : `monetaryField`, defaultValue: value, readOnly: !field.definition.uiEditable, step: "any", min: (_4 = field.definition.minimumNumber) !== null && _4 !== void 0 ? _4 : undefined, max: (_5 = field.definition.maximumNumber) !== null && _5 !== void 0 ? _5 : undefined }, validation.register(key, rules), { onBlur: () => setIsEditing(!isEditing), onChange: e => {
3529
+ setNumberValue(e.target.value === "" ? null : e.target.value);
3530
+ validation.register(key, rules).onChange(e);
3531
+ } }, numberProps))) : (jsx(BaseInput, Object.assign({ type: "text", id: `${key}-monetary-field`, dataTestId: `${field.definition.key}`, defaultValue: value, readOnly: true, actions: jsx("div", { className: "tu-action-container", children: jsx(IconButton, { className: "tu-action-button", dataTestId: `${field.definition.key}-editIconButtonId`, size: "small", color: "tertiary", icon: jsx(Icon, { size: "small", name: "PencilIcon" }), onClick: () => setIsEditing(!isEditing) }) }) }, numberProps))) }));
3532
+ }
3516
3533
  default:
3517
3534
  throw new Error(`Type not supported: ${type}`);
3518
3535
  }
package/package.json CHANGED
@@ -1,17 +1,16 @@
1
1
  {
2
2
  "name": "@trackunit/custom-field-components",
3
- "version": "0.0.445",
3
+ "version": "0.0.448",
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.64",
11
- "@trackunit/iris-app-runtime-core-api": "0.3.57",
10
+ "@trackunit/iris-app-runtime-core-api": "0.3.58",
12
11
  "@trackunit/react-components": "0.1.148",
13
- "@trackunit/react-core-contexts-test": "0.1.93",
14
- "@trackunit/react-form-components": "0.0.119",
12
+ "@trackunit/react-core-contexts-test": "0.1.94",
13
+ "@trackunit/react-form-components": "0.0.121",
15
14
  "libphonenumber-js": "1.10.36",
16
15
  "react": "18.2.0",
17
16
  "react-hook-form": "7.40.0",
@@ -1,10 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { AbstractValueAndDefinition } from "@trackunit/iris-app-runtime-core";
3
2
  import { ValueAndDefinition } from "@trackunit/iris-app-runtime-core-api";
4
3
  import { FieldValues, FormState, UseFormRegister, UseFormSetValue } from "react-hook-form";
5
4
  import { UnitPreference } from "./UnitPreference";
6
5
  interface ICustomFieldProps {
7
- field: AbstractValueAndDefinition;
6
+ field: ValueAndDefinition;
8
7
  register: UseFormRegister<FieldValues>;
9
8
  formState: FormState<FieldValues>;
10
9
  setValue: UseFormSetValue<FieldValues>;
@@ -1,4 +1,4 @@
1
- import { BooleanFieldDefinition, DateFieldDefinition, DropDownFieldDefinition, EmailFieldDefinition, NumberFieldDefinition, PhoneNumberFieldDefinition, StringFieldDefinition, WebAddressFieldDefinition } from "@trackunit/iris-app-runtime-core-api";
1
+ import { BooleanFieldDefinition, DateFieldDefinition, DropDownFieldDefinition, EmailFieldDefinition, MonetaryFieldDefinition, NumberFieldDefinition, PhoneNumberFieldDefinition, StringFieldDefinition, WebAddressFieldDefinition } from "@trackunit/iris-app-runtime-core-api";
2
2
  import { RegisterOptions } from "react-hook-form";
3
3
  /**
4
4
  * Validation rules for a field
@@ -17,7 +17,7 @@ export declare const getWebAddressValidationRules: (definition: WebAddressFieldD
17
17
  * @param { NumberFieldDefinition } definition the field definition
18
18
  * @returns { ValidationRules} the validation rules
19
19
  */
20
- export declare const getNumberValidationRules: (definition: NumberFieldDefinition) => ValidationRules;
20
+ export declare const getNumberValidationRules: (definition: NumberFieldDefinition | MonetaryFieldDefinition) => ValidationRules;
21
21
  /**
22
22
  * Get validation rules for a string field.
23
23
  *