@trackunit/custom-field-components 0.0.112 → 0.0.117
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/getValidationRules.d.ts +1 -1
- package/index.js +47 -33
- package/mocks.d.ts +3 -1
- package/package.json +4 -4
package/getValidationRules.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { BooleanFieldDefinition, DateFieldDefinition, DropDownFieldDefinition, EmailFieldDefinition, NumberFieldDefinition, PhoneNumberFieldDefinition, StringFieldDefinition, WebAddressFieldDefinition } from "@trackunit/iris-app-runtime-core-api";
|
|
2
2
|
import { RegisterOptions } from "react-hook-form";
|
|
3
3
|
export declare type ValidationRules = RegisterOptions;
|
|
4
|
+
export declare const getWebAddressValidationRules: (definition: WebAddressFieldDefinition) => ValidationRules;
|
|
4
5
|
export declare const getNumberValidationRules: (definition: NumberFieldDefinition) => ValidationRules;
|
|
5
6
|
export declare const getStringValidationRules: (definition: StringFieldDefinition) => ValidationRules;
|
|
6
7
|
export declare const getBooleanValidationRules: (definition: BooleanFieldDefinition) => ValidationRules;
|
|
7
8
|
export declare const getDropdownValidationRules: (definition: DropDownFieldDefinition) => ValidationRules;
|
|
8
9
|
export declare const getDateValidationRules: (definition: DateFieldDefinition) => ValidationRules;
|
|
9
10
|
export declare const getEmailValidationRules: (definition: EmailFieldDefinition) => ValidationRules;
|
|
10
|
-
export declare const getWebAddressValidationRules: (definition: WebAddressFieldDefinition) => ValidationRules;
|
|
11
11
|
export declare const getPhoneNumberValidationRules: (definition: PhoneNumberFieldDefinition) => ValidationRules;
|
package/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx } from 'react/jsx-runtime';
|
|
2
2
|
import { CustomFieldType } from '@trackunit/iris-app-runtime-core-api';
|
|
3
|
-
import { FormGroup, Checkbox, DateField, Select, BaseInput, TextField } from '@trackunit/react-components';
|
|
3
|
+
import { FormGroup, Checkbox, DateField, Select, BaseInput, TextField, ActionButton } from '@trackunit/react-components';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { useCallback, useEffect } from 'react';
|
|
6
6
|
import { isValidPhoneNumber } from 'libphonenumber-js';
|
|
@@ -1809,8 +1809,9 @@ const BooleanCustomField = _a => {
|
|
|
1809
1809
|
React.useEffect(() => {
|
|
1810
1810
|
register && register(id, Object.assign(Object.assign({}, validationRules), {
|
|
1811
1811
|
value: internalValue.toString()
|
|
1812
|
-
}));
|
|
1813
|
-
}, [register
|
|
1812
|
+
})); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1813
|
+
}, []); // register only once
|
|
1814
|
+
|
|
1814
1815
|
return jsx(FormGroup, Object.assign({
|
|
1815
1816
|
label: label,
|
|
1816
1817
|
tip: tip,
|
|
@@ -2361,6 +2362,16 @@ $({ target: 'RegExp', proto: true, forced: /./.exec !== exec }, {
|
|
|
2361
2362
|
exec: exec
|
|
2362
2363
|
});
|
|
2363
2364
|
|
|
2365
|
+
const getWebAddressValidationRules = definition => {
|
|
2366
|
+
const defaultRules = {};
|
|
2367
|
+
const pattern = {
|
|
2368
|
+
pattern: {
|
|
2369
|
+
value: RegExp("^(((https?|ftps?)://)(%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:|:blank:]])?$"),
|
|
2370
|
+
message: `Must match url pattern`
|
|
2371
|
+
}
|
|
2372
|
+
};
|
|
2373
|
+
return definition.uiEditable ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
|
|
2374
|
+
};
|
|
2364
2375
|
const getNumberValidationRules = definition => {
|
|
2365
2376
|
const defaultRules = {
|
|
2366
2377
|
valueAsNumber: true
|
|
@@ -2428,16 +2439,6 @@ const getEmailValidationRules = definition => {
|
|
|
2428
2439
|
};
|
|
2429
2440
|
return definition.uiEditable ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
|
|
2430
2441
|
};
|
|
2431
|
-
const getWebAddressValidationRules = definition => {
|
|
2432
|
-
const defaultRules = {};
|
|
2433
|
-
const pattern = {
|
|
2434
|
-
pattern: {
|
|
2435
|
-
value: RegExp("^(((https?|ftps?)://)(%[0-9A-Fa-f]{2}|[-()_.!~*';/?:@&=+$,A-Za-z0-9])+)([).!';/?:,][[:blank:|:blank:]])?$"),
|
|
2436
|
-
message: `Must match url pattern`
|
|
2437
|
-
}
|
|
2438
|
-
};
|
|
2439
|
-
return definition.uiEditable ? Object.assign(Object.assign({}, pattern), defaultRules) : defaultRules;
|
|
2440
|
-
};
|
|
2441
2442
|
const getPhoneNumberValidationRules = definition => {
|
|
2442
2443
|
const defaultRules = {};
|
|
2443
2444
|
const pattern = {
|
|
@@ -2447,7 +2448,7 @@ const getPhoneNumberValidationRules = definition => {
|
|
|
2447
2448
|
};
|
|
2448
2449
|
|
|
2449
2450
|
const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldId) => {
|
|
2450
|
-
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;
|
|
2451
|
+
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;
|
|
2451
2452
|
|
|
2452
2453
|
if ((field === null || field === void 0 ? void 0 : field.definition) === undefined || ((_a = field === null || field === void 0 ? void 0 : field.definition) === null || _a === void 0 ? void 0 : _a.type) === undefined) {
|
|
2453
2454
|
return null;
|
|
@@ -2463,32 +2464,41 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
2463
2464
|
} = field.definition;
|
|
2464
2465
|
|
|
2465
2466
|
switch (type) {
|
|
2466
|
-
case CustomFieldType.
|
|
2467
|
+
case CustomFieldType.WEB_ADDRESS:
|
|
2467
2468
|
{
|
|
2468
2469
|
const typedDefinition = field.definition;
|
|
2469
2470
|
const typedValue = field.value;
|
|
2470
|
-
const rules =
|
|
2471
|
+
const rules = getWebAddressValidationRules(typedDefinition);
|
|
2471
2472
|
return jsx(TextField, Object.assign({
|
|
2472
2473
|
id: key,
|
|
2473
2474
|
label: title,
|
|
2474
2475
|
placeholder: (_c = typedDefinition.title) !== null && _c !== void 0 ? _c : "",
|
|
2475
2476
|
defaultValue: (_e = (_d = typedValue.stringValue) !== null && _d !== void 0 ? _d : typedDefinition.defaultStringValue) !== null && _e !== void 0 ? _e : "",
|
|
2477
|
+
dataTestId: "webAddressField",
|
|
2478
|
+
actions: !typedDefinition.uiEditable && (typedValue.stringValue || typedDefinition.defaultStringValue) && jsx(ActionButton, {
|
|
2479
|
+
value: (_f = typedValue.stringValue) !== null && _f !== void 0 ? _f : typedDefinition.defaultStringValue,
|
|
2480
|
+
type: "WEB_ADDRESS"
|
|
2481
|
+
}),
|
|
2476
2482
|
readOnly: !typedDefinition.uiEditable,
|
|
2477
2483
|
helpText: description || undefined,
|
|
2478
2484
|
errorMessage: errorMessage
|
|
2479
2485
|
}, validation.register(key, rules)));
|
|
2480
2486
|
}
|
|
2481
2487
|
|
|
2482
|
-
case CustomFieldType.
|
|
2488
|
+
case CustomFieldType.EMAIL:
|
|
2483
2489
|
{
|
|
2484
2490
|
const typedDefinition = field.definition;
|
|
2485
2491
|
const typedValue = field.value;
|
|
2486
|
-
const rules =
|
|
2492
|
+
const rules = getEmailValidationRules(typedDefinition);
|
|
2487
2493
|
return jsx(TextField, Object.assign({
|
|
2488
2494
|
id: key,
|
|
2489
2495
|
label: title,
|
|
2490
|
-
placeholder: (
|
|
2491
|
-
defaultValue: (
|
|
2496
|
+
placeholder: (_g = typedDefinition.title) !== null && _g !== void 0 ? _g : "",
|
|
2497
|
+
defaultValue: (_j = (_h = typedValue.stringValue) !== null && _h !== void 0 ? _h : typedDefinition.defaultStringValue) !== null && _j !== void 0 ? _j : "",
|
|
2498
|
+
actions: !typedDefinition.uiEditable && (typedValue.stringValue || typedDefinition.defaultStringValue) && jsx(ActionButton, {
|
|
2499
|
+
value: (_k = typedValue.stringValue) !== null && _k !== void 0 ? _k : typedDefinition.defaultStringValue,
|
|
2500
|
+
type: "EMAIL"
|
|
2501
|
+
}),
|
|
2492
2502
|
readOnly: !typedDefinition.uiEditable,
|
|
2493
2503
|
helpText: description || undefined,
|
|
2494
2504
|
errorMessage: errorMessage
|
|
@@ -2503,8 +2513,12 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
2503
2513
|
return jsx(TextField, Object.assign({
|
|
2504
2514
|
label: title,
|
|
2505
2515
|
id: key,
|
|
2506
|
-
placeholder: (
|
|
2507
|
-
defaultValue: (
|
|
2516
|
+
placeholder: (_l = typedDefinition.title) !== null && _l !== void 0 ? _l : "",
|
|
2517
|
+
defaultValue: (_o = (_m = typedValue.stringValue) !== null && _m !== void 0 ? _m : typedDefinition.defaultStringValue) !== null && _o !== void 0 ? _o : "",
|
|
2518
|
+
actions: !typedDefinition.uiEditable && (typedValue.stringValue || typedDefinition.defaultStringValue) && jsx(ActionButton, {
|
|
2519
|
+
value: (_p = typedValue.stringValue) !== null && _p !== void 0 ? _p : typedDefinition.defaultStringValue,
|
|
2520
|
+
type: "PHONE_NUMBER"
|
|
2521
|
+
}),
|
|
2508
2522
|
readOnly: !typedDefinition.uiEditable,
|
|
2509
2523
|
helpText: description || undefined,
|
|
2510
2524
|
errorMessage: errorMessage === "" ? "Must be a phone number" : undefined
|
|
@@ -2519,8 +2533,8 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
2519
2533
|
return jsx(TextField, Object.assign({
|
|
2520
2534
|
label: title,
|
|
2521
2535
|
id: key || "string-field",
|
|
2522
|
-
placeholder: (
|
|
2523
|
-
defaultValue: (
|
|
2536
|
+
placeholder: (_q = typedDefinition.title) !== null && _q !== void 0 ? _q : "",
|
|
2537
|
+
defaultValue: (_s = (_r = typedValue.stringValue) !== null && _r !== void 0 ? _r : typedDefinition.defaultStringValue) !== null && _s !== void 0 ? _s : "",
|
|
2524
2538
|
readOnly: !typedDefinition.uiEditable,
|
|
2525
2539
|
helpText: description || undefined,
|
|
2526
2540
|
errorMessage: errorMessage,
|
|
@@ -2544,13 +2558,13 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
2544
2558
|
type: "number",
|
|
2545
2559
|
id: key || "number-field",
|
|
2546
2560
|
dataTestId: "numberField",
|
|
2547
|
-
placeholder: (
|
|
2548
|
-
defaultValue: (
|
|
2561
|
+
placeholder: (_t = typedDefinition.title) !== null && _t !== void 0 ? _t : "",
|
|
2562
|
+
defaultValue: (_v = (_u = typedValue.numberValue) !== null && _u !== void 0 ? _u : typedDefinition.defaultNumberValue) !== null && _v !== void 0 ? _v : "",
|
|
2549
2563
|
addonAfter: unit,
|
|
2550
2564
|
readOnly: !typedDefinition.uiEditable,
|
|
2551
2565
|
step: typedDefinition.isInteger ? 1 : "any",
|
|
2552
|
-
min: (
|
|
2553
|
-
max: (
|
|
2566
|
+
min: (_w = typedDefinition.minimumNumber) !== null && _w !== void 0 ? _w : undefined,
|
|
2567
|
+
max: (_x = typedDefinition.maximumNumber) !== null && _x !== void 0 ? _x : undefined
|
|
2554
2568
|
}, validation.register(key, rules)))
|
|
2555
2569
|
}));
|
|
2556
2570
|
}
|
|
@@ -2561,9 +2575,9 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
2561
2575
|
const typedValue = field.value;
|
|
2562
2576
|
const rules = getBooleanValidationRules();
|
|
2563
2577
|
return jsx(BooleanCustomField, {
|
|
2564
|
-
label: (
|
|
2578
|
+
label: (_y = typedDefinition.title) !== null && _y !== void 0 ? _y : "",
|
|
2565
2579
|
id: key || "boolean-field",
|
|
2566
|
-
defaultValue: (
|
|
2580
|
+
defaultValue: (_0 = (_z = typedValue.booleanValue) !== null && _z !== void 0 ? _z : typedDefinition.defaultBooleanValue) !== null && _0 !== void 0 ? _0 : undefined,
|
|
2567
2581
|
readOnly: !typedDefinition.uiEditable,
|
|
2568
2582
|
register: validation.register,
|
|
2569
2583
|
validationRules: rules,
|
|
@@ -2582,10 +2596,10 @@ const useCustomFieldResolver = (field, validation, unitPreference = "SI", fieldI
|
|
|
2582
2596
|
return jsx(DropdownCustomField, {
|
|
2583
2597
|
label: typedDefinition.title || "",
|
|
2584
2598
|
id: key || "dropdown-field",
|
|
2585
|
-
defaultValue: (
|
|
2599
|
+
defaultValue: (_2 = (_1 = typedValue.stringArrayValue) !== null && _1 !== void 0 ? _1 : typedDefinition.defaultStringArrayValue) !== null && _2 !== void 0 ? _2 : undefined,
|
|
2586
2600
|
disabled: !typedDefinition.uiEditable,
|
|
2587
|
-
allValues: (
|
|
2588
|
-
multiSelect: (
|
|
2601
|
+
allValues: (_3 = typedDefinition.allValues) !== null && _3 !== void 0 ? _3 : undefined,
|
|
2602
|
+
multiSelect: (_4 = typedDefinition.multiSelect) !== null && _4 !== void 0 ? _4 : false,
|
|
2589
2603
|
register: validation.register,
|
|
2590
2604
|
validationRules: rules,
|
|
2591
2605
|
helpText: description || undefined,
|
package/mocks.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BooleanFieldDefinition, DateFieldDefinition, DropDownFieldDefinition, NumberFieldDefinition, StringFieldDefinition, ValueAndDefinition } from "@trackunit/iris-app-runtime-core-api";
|
|
1
|
+
import { BooleanFieldDefinition, DateFieldDefinition, DropDownFieldDefinition, NumberFieldDefinition, StringFieldDefinition, ValueAndDefinition, WebAddressFieldDefinition } from "@trackunit/iris-app-runtime-core-api";
|
|
2
2
|
import { FieldValues, FormState, UseFormRegister, UseFormSetValue } from "react-hook-form";
|
|
3
3
|
export declare const getValidationRules: () => Promise<{
|
|
4
4
|
register: UseFormRegister<FieldValues>;
|
|
@@ -11,6 +11,8 @@ export declare const numberFieldDefinition: NumberFieldDefinition;
|
|
|
11
11
|
export declare const numberField: ValueAndDefinition;
|
|
12
12
|
export declare const dateFieldDefinition: DateFieldDefinition;
|
|
13
13
|
export declare const dateField: ValueAndDefinition;
|
|
14
|
+
export declare const webAddressFieldDefinition: WebAddressFieldDefinition;
|
|
15
|
+
export declare const webAddressField: ValueAndDefinition;
|
|
14
16
|
export declare const booleanFieldDefinition: BooleanFieldDefinition;
|
|
15
17
|
export declare const booleanField: ValueAndDefinition;
|
|
16
18
|
export declare const dropDownFieldDefinition: DropDownFieldDefinition;
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/custom-field-components",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.117",
|
|
4
4
|
"repository": "https://github.com/Trackunit/manager",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@trackunit/react-core-contexts-test": "0.0.
|
|
8
|
-
"@trackunit/react-components": "0.0.
|
|
7
|
+
"@trackunit/react-core-contexts-test": "0.0.34",
|
|
8
|
+
"@trackunit/react-components": "0.0.130",
|
|
9
9
|
"react": "17.0.1",
|
|
10
10
|
"react-hook-form": "^7.29.0",
|
|
11
|
-
"@trackunit/iris-app-runtime-core": "0.0.
|
|
11
|
+
"@trackunit/iris-app-runtime-core": "0.0.64",
|
|
12
12
|
"@trackunit/iris-app-runtime-core-api": "0.0.61",
|
|
13
13
|
"react-select": "^5.4.0",
|
|
14
14
|
"libphonenumber-js": "^1.10.7"
|