cogsbox-state 0.5.463 → 0.5.465
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/dist/CogsState.d.ts +10 -30
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +1417 -1461
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Functions.d.ts.map +1 -1
- package/dist/Functions.jsx +23 -16
- package/dist/Functions.jsx.map +1 -1
- package/dist/index.js +26 -26
- package/dist/store.d.ts +39 -47
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +259 -295
- package/dist/store.js.map +1 -1
- package/dist/utility.d.ts +0 -1
- package/dist/utility.d.ts.map +1 -1
- package/dist/utility.js +121 -158
- package/dist/utility.js.map +1 -1
- package/package.json +5 -4
- package/src/CogsState.tsx +1047 -1428
- package/src/Functions.tsx +27 -7
- package/src/store.ts +489 -593
- package/src/utility.ts +0 -65
package/src/Functions.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FormOptsType } from './CogsState';
|
|
2
|
-
|
|
3
2
|
import React from 'react';
|
|
4
|
-
import { getGlobalStore } from './store';
|
|
3
|
+
import { getGlobalStore, ValidationError } from './store';
|
|
4
|
+
import { get } from 'http';
|
|
5
5
|
|
|
6
6
|
export type ValidationWrapperProps = {
|
|
7
7
|
formOpts?: FormOptsType;
|
|
@@ -9,21 +9,36 @@ export type ValidationWrapperProps = {
|
|
|
9
9
|
stateKey: string;
|
|
10
10
|
children: React.ReactNode;
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
export function ValidationWrapper({
|
|
13
14
|
formOpts,
|
|
14
15
|
path,
|
|
15
16
|
stateKey,
|
|
16
17
|
children,
|
|
17
18
|
}: ValidationWrapperProps) {
|
|
18
|
-
const { getInitialOptions, getShadowMetadata } =
|
|
19
|
+
const { getInitialOptions, getShadowMetadata, getShadowValue } =
|
|
20
|
+
getGlobalStore.getState();
|
|
19
21
|
const thisStateOpts = getInitialOptions(stateKey!);
|
|
20
22
|
|
|
21
|
-
// GET VALIDATION FROM SHADOW METADATA
|
|
22
23
|
const shadowMeta = getShadowMetadata(stateKey!, path);
|
|
23
24
|
const validationState = shadowMeta?.validation;
|
|
24
|
-
const status = validationState?.status || 'PRISTINE';
|
|
25
25
|
|
|
26
|
-
const
|
|
26
|
+
const status = validationState?.status || 'NOT_VALIDATED';
|
|
27
|
+
|
|
28
|
+
const errors = (validationState?.errors || []).map((err) => ({
|
|
29
|
+
...err,
|
|
30
|
+
path: path,
|
|
31
|
+
})) as ValidationError[];
|
|
32
|
+
const errorMessages = errors
|
|
33
|
+
.filter((err) => err.severity === 'error')
|
|
34
|
+
.map((err) => err.message);
|
|
35
|
+
const warningMessages = errors
|
|
36
|
+
.filter((err) => err.severity === 'warning')
|
|
37
|
+
.map((err) => err.message);
|
|
38
|
+
|
|
39
|
+
// Use first error, or first warning if no errors
|
|
40
|
+
const message = errorMessages[0] || warningMessages[0];
|
|
41
|
+
|
|
27
42
|
return (
|
|
28
43
|
<>
|
|
29
44
|
{thisStateOpts?.formElements?.validation &&
|
|
@@ -32,11 +47,16 @@ export function ValidationWrapper({
|
|
|
32
47
|
children: (
|
|
33
48
|
<React.Fragment key={path.toString()}>{children}</React.Fragment>
|
|
34
49
|
),
|
|
35
|
-
status, //
|
|
50
|
+
status, // Now passes the new ValidationStatus type
|
|
36
51
|
message: formOpts?.validation?.hideMessage
|
|
37
52
|
? ''
|
|
38
53
|
: formOpts?.validation?.message || message || '',
|
|
54
|
+
|
|
55
|
+
hasErrors: errorMessages.length > 0,
|
|
56
|
+
hasWarnings: warningMessages.length > 0,
|
|
57
|
+
allErrors: errors,
|
|
39
58
|
path: path,
|
|
59
|
+
getData: () => getShadowValue(stateKey!, path),
|
|
40
60
|
})
|
|
41
61
|
) : (
|
|
42
62
|
<React.Fragment key={path.toString()}>{children}</React.Fragment>
|