@trackunit/custom-field-components 2.8.4 → 2.8.5

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
@@ -2,11 +2,10 @@
2
2
 
3
3
  var jsxRuntime = require('react/jsx-runtime');
4
4
  var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
5
- var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
6
5
  var reactFormComponents = require('@trackunit/react-form-components');
7
6
  var sharedUtils = require('@trackunit/shared-utils');
8
- var react = require('react');
9
7
  var reactHookForm = require('react-hook-form');
8
+ var react = require('react');
10
9
  var reactComponents = require('@trackunit/react-components');
11
10
  var reactCoreHooks = require('@trackunit/react-core-hooks');
12
11
  var reactModal = require('@trackunit/react-modal');
@@ -541,26 +540,14 @@ const useUnitTranslation = () => {
541
540
  * and functions for form registration and state management.
542
541
  * @returns {ReactElement | null} - The JSX Element for the custom field or null if the field definition is not provided.
543
542
  */
544
- const useCustomFieldResolver = ({ field, definition, register, setValue, formState, formValue, unitPreference = "SI", language, fieldId, isEditable = true, control, }) => {
543
+ const useCustomFieldResolver = ({ field, definition, register, setValue, formState, formValue, unitPreference = "SI", fieldId, isEditable = true, control, }) => {
545
544
  const [t] = useTranslation();
546
545
  const validation = { register, setValue, formState };
547
546
  const { unitTranslation } = useUnitTranslation();
548
- const [numberValue, setNumberValue] = react.useState(() => {
549
- if (field?.definition && field.__typename === "NumberFieldValueAndDefinition") {
550
- const fieldValue = field.numberValue;
551
- const unit = unitPreference === "US_CUSTOMARY" && field.definition.unitUs
552
- ? field.definition.unitUs
553
- : field.definition.unitSi;
554
- return irisAppRuntimeCore.getCustomFieldValueForDisplayInUI(fieldValue, unit, unitPreference, language);
555
- }
556
- else {
557
- return "";
558
- }
559
- });
560
547
  const { getPhoneNumberValidationRules } = reactFormComponents.useGetPhoneValidationRules();
561
548
  const def = field?.definition ?? definition;
562
549
  const uniqueIdentifier = fieldId ?? def?.id ?? "";
563
- const value = useValue(uniqueIdentifier, numberValue, control, def, field);
550
+ const value = useValue(uniqueIdentifier, control, def, field);
564
551
  const key = def?.key ?? uniqueIdentifier;
565
552
  const fieldError = uniqueIdentifier ? validation.formState.errors[uniqueIdentifier] : undefined;
566
553
  const errorMessage = fieldError ? `${fieldError.message}` : undefined;
@@ -635,16 +622,16 @@ const useCustomFieldResolver = ({ field, definition, register, setValue, formSta
635
622
  placeholder: title ?? "",
636
623
  addonAfter: def.currency,
637
624
  };
638
- return (jsxRuntime.jsx(reactFormComponents.NumberField, { "data-testid": key ? key : `monetaryField`, defaultValue: value, disabled: !isEditableCombined, helpText: errorMessage || description, id: uniqueIdentifier, isInvalid: errorMessage ? true : false, label: title, max: def.maximumNumber ?? undefined, min: def.minimumNumber ?? undefined, readOnly: !isEditableCombined, step: "any", ...validation.register(uniqueIdentifier, rules), onChange: e => {
639
- setNumberValue(e.target.value === "" ? null : e.target.value);
640
- void validation.register(uniqueIdentifier, rules).onChange(e);
641
- }, ...numberProps }));
625
+ return (jsxRuntime.jsx(reactFormComponents.NumberField, { "data-testid": key ? key : `monetaryField`, disabled: !isEditableCombined, errorMessage: errorMessage, helpText: description, id: uniqueIdentifier, label: title, max: def.maximumNumber ?? undefined, min: def.minimumNumber ?? undefined, readOnly: !isEditableCombined, step: "any", ...validation.register(uniqueIdentifier, {
626
+ ...rules,
627
+ value,
628
+ }), ...numberProps }));
642
629
  }
643
630
  default:
644
631
  return sharedUtils.exhaustiveCheck(def);
645
632
  }
646
633
  };
647
- const useValue = (uniqueIdentifier, numberValue, control, def, field) => {
634
+ const useValue = (uniqueIdentifier, control, def, field) => {
648
635
  // workaround that ensures the value in the phone number field is updated if the formState changes.
649
636
  // Would probably be better to use PhoneFieldWithController, but doing that makes the form dirty on initial load.
650
637
  const initialValue = field?.__typename === "PhoneNumberFieldValueAndDefinition" ? field.phoneNumberValue : null;
@@ -686,9 +673,7 @@ const useValue = (uniqueIdentifier, numberValue, control, def, field) => {
686
673
  return field?.__typename === "StringListFieldValueAndDefinition" ? field.stringArrayValue : null;
687
674
  }
688
675
  case "MonetaryFieldDefinition": {
689
- return numberValue === undefined || numberValue === null || numberValue === ""
690
- ? ""
691
- : parseFloat(Number(numberValue).toPrecision(4));
676
+ return field?.__typename === "MonetaryFieldValueAndDefinition" ? field.monetaryValue : null;
692
677
  }
693
678
  default:
694
679
  return sharedUtils.exhaustiveCheck(def);
package/index.esm.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-library-translation';
3
- import { getCustomFieldValueForDisplayInUI } from '@trackunit/iris-app-runtime-core';
4
3
  import { FormGroup, Checkbox, toISODateStringUTC, DateField, MultiSelectField, SelectField, TextBaseInput, useGetPhoneValidationRules, NumberField, TextField, PhoneField, ActionButton } from '@trackunit/react-form-components';
5
4
  import { uuidv4, exhaustiveCheck } from '@trackunit/shared-utils';
6
- import { useState, useEffect, useCallback, createElement, useMemo } from 'react';
7
5
  import { Controller, useWatch } from 'react-hook-form';
6
+ import { useState, useEffect, useCallback, createElement, useMemo } from 'react';
8
7
  import { Card, CardHeader, Tooltip, CardBody, Text, CardFooter, Button, IconButton, Icon } from '@trackunit/react-components';
9
8
  import { useConfirmationDialog } from '@trackunit/react-core-hooks';
10
9
  import { useModal, Modal, ModalHeader, ModalBody, ModalFooter } from '@trackunit/react-modal';
@@ -539,26 +538,14 @@ const useUnitTranslation = () => {
539
538
  * and functions for form registration and state management.
540
539
  * @returns {ReactElement | null} - The JSX Element for the custom field or null if the field definition is not provided.
541
540
  */
542
- const useCustomFieldResolver = ({ field, definition, register, setValue, formState, formValue, unitPreference = "SI", language, fieldId, isEditable = true, control, }) => {
541
+ const useCustomFieldResolver = ({ field, definition, register, setValue, formState, formValue, unitPreference = "SI", fieldId, isEditable = true, control, }) => {
543
542
  const [t] = useTranslation();
544
543
  const validation = { register, setValue, formState };
545
544
  const { unitTranslation } = useUnitTranslation();
546
- const [numberValue, setNumberValue] = useState(() => {
547
- if (field?.definition && field.__typename === "NumberFieldValueAndDefinition") {
548
- const fieldValue = field.numberValue;
549
- const unit = unitPreference === "US_CUSTOMARY" && field.definition.unitUs
550
- ? field.definition.unitUs
551
- : field.definition.unitSi;
552
- return getCustomFieldValueForDisplayInUI(fieldValue, unit, unitPreference, language);
553
- }
554
- else {
555
- return "";
556
- }
557
- });
558
545
  const { getPhoneNumberValidationRules } = useGetPhoneValidationRules();
559
546
  const def = field?.definition ?? definition;
560
547
  const uniqueIdentifier = fieldId ?? def?.id ?? "";
561
- const value = useValue(uniqueIdentifier, numberValue, control, def, field);
548
+ const value = useValue(uniqueIdentifier, control, def, field);
562
549
  const key = def?.key ?? uniqueIdentifier;
563
550
  const fieldError = uniqueIdentifier ? validation.formState.errors[uniqueIdentifier] : undefined;
564
551
  const errorMessage = fieldError ? `${fieldError.message}` : undefined;
@@ -633,16 +620,16 @@ const useCustomFieldResolver = ({ field, definition, register, setValue, formSta
633
620
  placeholder: title ?? "",
634
621
  addonAfter: def.currency,
635
622
  };
636
- return (jsx(NumberField, { "data-testid": key ? key : `monetaryField`, defaultValue: value, disabled: !isEditableCombined, helpText: errorMessage || description, id: uniqueIdentifier, isInvalid: errorMessage ? true : false, label: title, max: def.maximumNumber ?? undefined, min: def.minimumNumber ?? undefined, readOnly: !isEditableCombined, step: "any", ...validation.register(uniqueIdentifier, rules), onChange: e => {
637
- setNumberValue(e.target.value === "" ? null : e.target.value);
638
- void validation.register(uniqueIdentifier, rules).onChange(e);
639
- }, ...numberProps }));
623
+ return (jsx(NumberField, { "data-testid": key ? key : `monetaryField`, disabled: !isEditableCombined, errorMessage: errorMessage, helpText: description, id: uniqueIdentifier, label: title, max: def.maximumNumber ?? undefined, min: def.minimumNumber ?? undefined, readOnly: !isEditableCombined, step: "any", ...validation.register(uniqueIdentifier, {
624
+ ...rules,
625
+ value,
626
+ }), ...numberProps }));
640
627
  }
641
628
  default:
642
629
  return exhaustiveCheck(def);
643
630
  }
644
631
  };
645
- const useValue = (uniqueIdentifier, numberValue, control, def, field) => {
632
+ const useValue = (uniqueIdentifier, control, def, field) => {
646
633
  // workaround that ensures the value in the phone number field is updated if the formState changes.
647
634
  // Would probably be better to use PhoneFieldWithController, but doing that makes the form dirty on initial load.
648
635
  const initialValue = field?.__typename === "PhoneNumberFieldValueAndDefinition" ? field.phoneNumberValue : null;
@@ -684,9 +671,7 @@ const useValue = (uniqueIdentifier, numberValue, control, def, field) => {
684
671
  return field?.__typename === "StringListFieldValueAndDefinition" ? field.stringArrayValue : null;
685
672
  }
686
673
  case "MonetaryFieldDefinition": {
687
- return numberValue === undefined || numberValue === null || numberValue === ""
688
- ? ""
689
- : parseFloat(Number(numberValue).toPrecision(4));
674
+ return field?.__typename === "MonetaryFieldValueAndDefinition" ? field.monetaryValue : null;
690
675
  }
691
676
  default:
692
677
  return exhaustiveCheck(def);
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/custom-field/components/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/custom-field-components",
3
- "version": "2.8.4",
3
+ "version": "2.8.5",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -11,7 +11,6 @@
11
11
  "@trackunit/react-form-components": "2.6.4",
12
12
  "@trackunit/shared-utils": "1.16.17",
13
13
  "@trackunit/custom-field-api": "2.9.4",
14
- "@trackunit/iris-app-runtime-core": "1.18.17",
15
14
  "@trackunit/react-components": "2.9.4",
16
15
  "@trackunit/react-modal": "2.6.4",
17
16
  "@trackunit/react-core-hooks": "1.21.10",
@@ -35,10 +35,6 @@ interface CustomFieldProps {
35
35
  * (Optional) Specifies the unit system to be used (e.g., 'SI' or 'US_CUSTOMARY').
36
36
  */
37
37
  unitPreference?: UnitPreference | null;
38
- /**
39
- * (Optional) The language code to use for displaying field values and validation messages.
40
- */
41
- language?: string;
42
38
  /**
43
39
  * (Optional) Indicates if the field is editable or should be displayed in read-only mode.
44
40
  */
@@ -61,7 +57,7 @@ interface CustomFieldProps {
61
57
  * and functions for form registration and state management.
62
58
  * @returns {ReactElement | null} - The JSX Element for the custom field or null if the field definition is not provided.
63
59
  */
64
- export declare const useCustomFieldResolver: ({ field, definition, register, setValue, formState, formValue, unitPreference, language, fieldId, isEditable, control, }: CustomFieldProps) => ReactElement | null;
60
+ export declare const useCustomFieldResolver: ({ field, definition, register, setValue, formState, formValue, unitPreference, fieldId, isEditable, control, }: CustomFieldProps) => ReactElement | null;
65
61
  /**
66
62
  * CustomField is a React component that takes in the properties of a custom field and renders it.
67
63
  * It utilizes the `useCustomFieldResolver` hook to resolve the field into an input element