@trackunit/custom-field-components 1.0.22 → 1.0.27

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
@@ -5,31 +5,12 @@ var i18nLibraryTranslation = require('@trackunit/i18n-library-translation');
5
5
  var irisAppRuntimeCore = require('@trackunit/iris-app-runtime-core');
6
6
  var reactFormComponents = require('@trackunit/react-form-components');
7
7
  var sharedUtils = require('@trackunit/shared-utils');
8
- var React = require('react');
8
+ var react = require('react');
9
9
  var reactHookForm = require('react-hook-form');
10
10
  var reactComponents = require('@trackunit/react-components');
11
11
  var reactCoreHooks = require('@trackunit/react-core-hooks');
12
12
  var reactModal = require('@trackunit/react-modal');
13
13
 
14
- function _interopNamespaceDefault(e) {
15
- var n = Object.create(null);
16
- if (e) {
17
- Object.keys(e).forEach(function (k) {
18
- if (k !== 'default') {
19
- var d = Object.getOwnPropertyDescriptor(e, k);
20
- Object.defineProperty(n, k, d.get ? d : {
21
- enumerable: true,
22
- get: function () { return e[k]; }
23
- });
24
- }
25
- });
26
- }
27
- n.default = e;
28
- return Object.freeze(n);
29
- }
30
-
31
- var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
32
-
33
14
  var defaultTranslations = {
34
15
  "customfield.stringlistfield.add": "Add",
35
16
  "customfield.stringlistfield.addField.Heading": "Add {{label}}",
@@ -157,11 +138,11 @@ const BooleanCustomField = ({ defaultValue, dataTestId = "booleanField", onChang
157
138
  const initialValue = value !== undefined ? value : defaultValue ? defaultValue : false;
158
139
  const renderAsInvalid = isInvalid || Boolean(errorMessage);
159
140
  const htmlForId = id ? id : "boolean-custom-field-" + sharedUtils.uuidv4();
160
- const [internalValue, setInternalValue] = React__namespace.useState(initialValue);
161
- React__namespace.useEffect(() => {
141
+ const [internalValue, setInternalValue] = react.useState(initialValue);
142
+ react.useEffect(() => {
162
143
  setInternalValue((value === undefined ? defaultValue : value) || false);
163
144
  }, [value, setInternalValue, defaultValue]);
164
- const onChangeHandler = React__namespace.useCallback((event) => {
145
+ const onChangeHandler = react.useCallback((event) => {
165
146
  onChange && onChange(event);
166
147
  const isChecked = event.target.checked || false;
167
148
  if (setValue) {
@@ -169,7 +150,7 @@ const BooleanCustomField = ({ defaultValue, dataTestId = "booleanField", onChang
169
150
  }
170
151
  setInternalValue(isChecked);
171
152
  }, [setInternalValue, onChange, id, setValue]);
172
- React__namespace.useEffect(() => {
153
+ react.useEffect(() => {
173
154
  register && register(id, { ...validationRules, value: internalValue.toString() });
174
155
  // eslint-disable-next-line react-hooks/exhaustive-deps
175
156
  }, []); // register only once
@@ -184,18 +165,18 @@ const BooleanCustomField = ({ defaultValue, dataTestId = "booleanField", onChang
184
165
  */
185
166
  const DateCustomField = (props) => {
186
167
  const { setValue, defaultValue, register, id, validationRules, ...rest } = props;
187
- const onChangeHandler = React.useCallback((e) => {
168
+ const onChangeHandler = react.useCallback((e) => {
188
169
  setValue &&
189
170
  setValue(id, e.target.valueAsDate?.toISOString(), {
190
171
  shouldDirty: true,
191
172
  shouldValidate: true,
192
173
  });
193
174
  }, [setValue, id]);
194
- React.useEffect(() => {
175
+ react.useEffect(() => {
195
176
  const value = defaultValue && new Date(defaultValue);
196
177
  register && register(id, { ...validationRules, value });
197
178
  }, [register, validationRules, defaultValue, id]);
198
- return (React.createElement(reactFormComponents.DateField, { ...rest, defaultValue: defaultValue, helpAddon: props.helpAddon || null, helpText: props.errorMessage || props.helpText, id: id, key: id, label: props.title, onChange: onChangeHandler }));
179
+ return (react.createElement(reactFormComponents.DateField, { ...rest, defaultValue: defaultValue, helpAddon: props.helpAddon || null, helpText: props.errorMessage || props.helpText, id: id, key: id, label: props.title, onChange: onChangeHandler }));
199
180
  };
200
181
 
201
182
  const convertToValueFormat = (value) => {
@@ -210,8 +191,8 @@ const convertToValueFormat = (value) => {
210
191
  const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, disabled = false, allValues, multiSelect = false, register, validationRules, setValue, label, tip, errorMessage, helpText, isInvalid, helpAddon, }) => {
211
192
  const renderAsInvalid = isInvalid || Boolean(errorMessage);
212
193
  const htmlForId = id ? id : "dropdown-custom-field-" + sharedUtils.uuidv4();
213
- const [selectedValue, setSelectedValue] = React__namespace.useState(defaultValue ? defaultValue.map(convertToValueFormat) : []);
214
- const onChangeHandler = React__namespace.useCallback((selected) => {
194
+ const [selectedValue, setSelectedValue] = react.useState(defaultValue ? defaultValue.map(convertToValueFormat) : []);
195
+ const onChangeHandler = react.useCallback((selected) => {
215
196
  if (selected) {
216
197
  const values = Array.isArray(selected) ? selected : [selected];
217
198
  if (selectedValue.length === 1 && values.length === 1 && values[0]?.value === selectedValue[0]?.value) {
@@ -228,10 +209,10 @@ const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, d
228
209
  setValue && setValue(id, []);
229
210
  }
230
211
  }, [id, selectedValue, setValue]);
231
- const options = React__namespace.useMemo(() => {
212
+ const options = react.useMemo(() => {
232
213
  return allValues ? allValues.map(convertToValueFormat) : [];
233
214
  }, [allValues]);
234
- React__namespace.useEffect(() => {
215
+ react.useEffect(() => {
235
216
  register && register(id, { ...validationRules, value: selectedValue });
236
217
  }, [register, validationRules, selectedValue, id]);
237
218
  return (jsxRuntime.jsx(reactFormComponents.FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon || null, helpText: errorMessage || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsxRuntime.jsx(reactFormComponents.Select, { "aria-labelledby": htmlForId + "-label", dataTestId: dataTestId, disabled: disabled, hasError: renderAsInvalid, inputId: htmlForId, isClearable: true, isMulti: multiSelect, onChange: onChangeHandler, options: options, value: selectedValue }) }));
@@ -242,7 +223,7 @@ const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, d
242
223
  */
243
224
  const AddStringListField = ({ id, label, isEditing, setIsEditing, onAdd }) => {
244
225
  const { Modal } = reactModal.useModal();
245
- const [inputValue, setInputValue] = React.useState("");
226
+ const [inputValue, setInputValue] = react.useState("");
246
227
  const { t } = useTranslation();
247
228
  const handleAdd = () => {
248
229
  if (inputValue.trim()) {
@@ -262,7 +243,7 @@ const AddStringListField = ({ id, label, isEditing, setIsEditing, onAdd }) => {
262
243
  * A custom field that displays a list of strings.
263
244
  */
264
245
  const StringListField = ({ defaultValue = [], label, description, disabled, validationRules, id, control, register, dataTestId, ...props }) => {
265
- const [isEditing, setIsEditing] = React.useState(false);
246
+ const [isEditing, setIsEditing] = react.useState(false);
266
247
  const { confirm } = reactCoreHooks.useConfirmationDialog();
267
248
  const { t } = useTranslation();
268
249
  return (jsxRuntime.jsx(reactHookForm.Controller, { control: control, defaultValue: defaultValue, name: id, render: ({ field }) => {
@@ -489,7 +470,7 @@ const getEmailValidationRules = (definition) => {
489
470
  */
490
471
  const useUnitTranslation = () => {
491
472
  const { t } = useTranslation();
492
- const unitTranslation = React.useCallback((unit) => {
473
+ const unitTranslation = react.useCallback((unit) => {
493
474
  if (!unit) {
494
475
  return null;
495
476
  }
@@ -510,7 +491,7 @@ const useUnitTranslation = () => {
510
491
  const useCustomFieldResolver = ({ field, definition, register, setValue, formState, formValue, unitPreference = "SI", language, fieldId, isEditable = true, control, }) => {
511
492
  const validation = { register, setValue, formState };
512
493
  const { unitTranslation } = useUnitTranslation();
513
- const [numberValue, setNumberValue] = React.useState(() => {
494
+ const [numberValue, setNumberValue] = react.useState(() => {
514
495
  if (field?.definition && field.__typename === "NumberFieldValueAndDefinition") {
515
496
  const fieldValue = field.numberValue;
516
497
  const unit = unitPreference === "US_CUSTOMARY" && field.definition.unitUs
package/index.esm.js CHANGED
@@ -3,8 +3,7 @@ import { registerTranslations, useNamespaceTranslation } from '@trackunit/i18n-l
3
3
  import { getCustomFieldValueForDisplayInUI } from '@trackunit/iris-app-runtime-core';
4
4
  import { FormGroup, Checkbox, DateField, Select, TextInput, useGetPhoneValidationRules, NumberField, TextField, PhoneField, ActionButton } from '@trackunit/react-form-components';
5
5
  import { uuidv4, exhaustiveCheck } from '@trackunit/shared-utils';
6
- import * as React from 'react';
7
- import { useCallback, useEffect, createElement, useState } from 'react';
6
+ import { useState, useEffect, useCallback, createElement, useMemo } from 'react';
8
7
  import { Controller, useWatch } from 'react-hook-form';
9
8
  import { CardHeader, CardBody, CardFooter, Button, Card, Tooltip, Text, IconButton, Icon } from '@trackunit/react-components';
10
9
  import { useConfirmationDialog } from '@trackunit/react-core-hooks';
@@ -137,11 +136,11 @@ const BooleanCustomField = ({ defaultValue, dataTestId = "booleanField", onChang
137
136
  const initialValue = value !== undefined ? value : defaultValue ? defaultValue : false;
138
137
  const renderAsInvalid = isInvalid || Boolean(errorMessage);
139
138
  const htmlForId = id ? id : "boolean-custom-field-" + uuidv4();
140
- const [internalValue, setInternalValue] = React.useState(initialValue);
141
- React.useEffect(() => {
139
+ const [internalValue, setInternalValue] = useState(initialValue);
140
+ useEffect(() => {
142
141
  setInternalValue((value === undefined ? defaultValue : value) || false);
143
142
  }, [value, setInternalValue, defaultValue]);
144
- const onChangeHandler = React.useCallback((event) => {
143
+ const onChangeHandler = useCallback((event) => {
145
144
  onChange && onChange(event);
146
145
  const isChecked = event.target.checked || false;
147
146
  if (setValue) {
@@ -149,7 +148,7 @@ const BooleanCustomField = ({ defaultValue, dataTestId = "booleanField", onChang
149
148
  }
150
149
  setInternalValue(isChecked);
151
150
  }, [setInternalValue, onChange, id, setValue]);
152
- React.useEffect(() => {
151
+ useEffect(() => {
153
152
  register && register(id, { ...validationRules, value: internalValue.toString() });
154
153
  // eslint-disable-next-line react-hooks/exhaustive-deps
155
154
  }, []); // register only once
@@ -190,8 +189,8 @@ const convertToValueFormat = (value) => {
190
189
  const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, disabled = false, allValues, multiSelect = false, register, validationRules, setValue, label, tip, errorMessage, helpText, isInvalid, helpAddon, }) => {
191
190
  const renderAsInvalid = isInvalid || Boolean(errorMessage);
192
191
  const htmlForId = id ? id : "dropdown-custom-field-" + uuidv4();
193
- const [selectedValue, setSelectedValue] = React.useState(defaultValue ? defaultValue.map(convertToValueFormat) : []);
194
- const onChangeHandler = React.useCallback((selected) => {
192
+ const [selectedValue, setSelectedValue] = useState(defaultValue ? defaultValue.map(convertToValueFormat) : []);
193
+ const onChangeHandler = useCallback((selected) => {
195
194
  if (selected) {
196
195
  const values = Array.isArray(selected) ? selected : [selected];
197
196
  if (selectedValue.length === 1 && values.length === 1 && values[0]?.value === selectedValue[0]?.value) {
@@ -208,10 +207,10 @@ const DropdownCustomField = ({ defaultValue, dataTestId, onChange, onBlur, id, d
208
207
  setValue && setValue(id, []);
209
208
  }
210
209
  }, [id, selectedValue, setValue]);
211
- const options = React.useMemo(() => {
210
+ const options = useMemo(() => {
212
211
  return allValues ? allValues.map(convertToValueFormat) : [];
213
212
  }, [allValues]);
214
- React.useEffect(() => {
213
+ useEffect(() => {
215
214
  register && register(id, { ...validationRules, value: selectedValue });
216
215
  }, [register, validationRules, selectedValue, id]);
217
216
  return (jsx(FormGroup, { dataTestId: dataTestId ? `${dataTestId}-FormGroup` : undefined, helpAddon: helpAddon || null, helpText: errorMessage || helpText, htmlFor: htmlForId, isInvalid: renderAsInvalid, label: label, tip: tip, children: jsx(Select, { "aria-labelledby": htmlForId + "-label", dataTestId: dataTestId, disabled: disabled, hasError: renderAsInvalid, inputId: htmlForId, isClearable: true, isMulti: multiSelect, onChange: onChangeHandler, options: options, value: selectedValue }) }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/custom-field-components",
3
- "version": "1.0.22",
3
+ "version": "1.0.27",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "engines": {
@@ -12,15 +12,15 @@
12
12
  "react-select": "^5.8.0",
13
13
  "@testing-library/react": "15.0.6",
14
14
  "jest-fetch-mock": "^3.0.3",
15
- "@trackunit/react-form-components": "^1.0.20",
16
- "@trackunit/shared-utils": "^1.0.3",
17
- "@trackunit/custom-field-api": "^1.0.10",
18
- "@trackunit/iris-app-runtime-core": "^1.0.5",
19
- "@trackunit/react-components": "^1.1.2",
20
- "@trackunit/react-modal": "^1.0.20",
21
- "@trackunit/react-core-hooks": "^1.0.5",
22
- "@trackunit/i18n-library-translation": "^1.0.8",
23
- "@trackunit/iris-app-runtime-core-api": "^1.0.5"
15
+ "@trackunit/react-form-components": "1.0.25",
16
+ "@trackunit/shared-utils": "1.2.1",
17
+ "@trackunit/custom-field-api": "1.0.15",
18
+ "@trackunit/iris-app-runtime-core": "1.0.9",
19
+ "@trackunit/react-components": "1.1.7",
20
+ "@trackunit/react-modal": "1.0.25",
21
+ "@trackunit/react-core-hooks": "1.0.9",
22
+ "@trackunit/i18n-library-translation": "1.0.13",
23
+ "@trackunit/iris-app-runtime-core-api": "1.0.9"
24
24
  },
25
25
  "module": "./index.esm.js",
26
26
  "main": "./index.cjs.js",
@@ -1,5 +1,5 @@
1
1
  import { CheckboxProps } from "@trackunit/react-form-components";
2
- import * as React from "react";
2
+ import { SyntheticEvent } from "react";
3
3
  import { FieldValues, UseFormRegister, UseFormSetValue } from "react-hook-form";
4
4
  import { ValidationRules } from "./getValidationRules";
5
5
  import { FormGroupExposedProps } from "./types";
@@ -39,7 +39,7 @@ export interface BooleanCustomFieldProps extends Omit<CheckboxProps, "value" | "
39
39
  *
40
40
  * @memberof BooleanCustomFieldProps
41
41
  */
42
- onChange?: (event: React.SyntheticEvent<HTMLInputElement>) => void;
42
+ onChange?: (event: SyntheticEvent<HTMLInputElement>) => void;
43
43
  /**
44
44
  * A flag that can be used to disable the input, default value is false
45
45
  *
@@ -1,4 +1,4 @@
1
- import * as React from "react";
1
+ import { ChangeEvent, FocusEvent } from "react";
2
2
  import { FieldValues, RegisterOptions, UseFormRegister, UseFormSetValue } from "react-hook-form";
3
3
  import { FormGroupExposedProps } from "./types";
4
4
  export interface DropdownCustomFieldProps extends FormGroupExposedProps {
@@ -82,8 +82,8 @@ export interface DropdownCustomFieldProps extends FormGroupExposedProps {
82
82
  */
83
83
  isInvalid?: boolean;
84
84
  }
85
- type OnChange = (event?: React.ChangeEvent<HTMLInputElement>) => void;
86
- type OnBlur = (event: React.FocusEvent<HTMLDivElement>) => void;
85
+ type OnChange = (event?: ChangeEvent<HTMLInputElement>) => void;
86
+ type OnBlur = (event: FocusEvent<HTMLDivElement>) => void;
87
87
  /**
88
88
  * A custom field that can be used to render a dropdown
89
89
  *