@remoteoss/json-schema-form 0.8.1-dev.20240208092217 → 0.8.1-dev.20240209164254
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/index.cjs +8 -5
- package/dist/index.js +8 -5
- package/dist/standalone.js +8 -5
- package/package.json +1 -1
- package/src/tests/conditions.test.js +0 -56
- package/src/tests/const.test.js +15 -3
- package/src/tests/jsonLogic.fixtures.js +29 -0
- package/src/tests/jsonLogic.test.js +11 -1
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.20240209164254
|
|
5
|
+
Generated: Fri, 09 Feb 2024 16:43:11 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -130,8 +130,10 @@ function checkIfConditionMatchesProperties(node, formValues, formFields, logic)
|
|
|
130
130
|
const field = getField(name, formFields);
|
|
131
131
|
return validateFieldSchema(
|
|
132
132
|
{
|
|
133
|
-
|
|
133
|
+
options: field.options,
|
|
134
|
+
// @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
|
|
134
135
|
...currentProperty,
|
|
136
|
+
inputType: field.inputType,
|
|
135
137
|
required: true
|
|
136
138
|
},
|
|
137
139
|
value
|
|
@@ -1381,7 +1383,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1381
1383
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1382
1384
|
const description = presentation?.description || node.description;
|
|
1383
1385
|
const statementDescription = presentation.statement?.description;
|
|
1384
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1386
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1385
1387
|
return (0, import_omitBy.default)(
|
|
1386
1388
|
{
|
|
1387
1389
|
const: node.const,
|
|
@@ -1477,9 +1479,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1477
1479
|
};
|
|
1478
1480
|
};
|
|
1479
1481
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1482
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1480
1483
|
return {
|
|
1481
1484
|
...computedAttributes ?? {},
|
|
1482
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1485
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1483
1486
|
};
|
|
1484
1487
|
}
|
|
1485
1488
|
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.20240209164254
|
|
5
|
+
Generated: Fri, 09 Feb 2024 16:43:11 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -94,8 +94,10 @@ function checkIfConditionMatchesProperties(node, formValues, formFields, logic)
|
|
|
94
94
|
const field = getField(name, formFields);
|
|
95
95
|
return validateFieldSchema(
|
|
96
96
|
{
|
|
97
|
-
|
|
97
|
+
options: field.options,
|
|
98
|
+
// @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
|
|
98
99
|
...currentProperty,
|
|
100
|
+
inputType: field.inputType,
|
|
99
101
|
required: true
|
|
100
102
|
},
|
|
101
103
|
value
|
|
@@ -1345,7 +1347,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
1345
1347
|
const node = omit(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
1346
1348
|
const description = presentation?.description || node.description;
|
|
1347
1349
|
const statementDescription = presentation.statement?.description;
|
|
1348
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
1350
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
1349
1351
|
return omitBy(
|
|
1350
1352
|
{
|
|
1351
1353
|
const: node.const,
|
|
@@ -1441,9 +1443,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values) => {
|
|
|
1441
1443
|
};
|
|
1442
1444
|
};
|
|
1443
1445
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
1446
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
1444
1447
|
return {
|
|
1445
1448
|
...computedAttributes ?? {},
|
|
1446
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
1449
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
1447
1450
|
};
|
|
1448
1451
|
}
|
|
1449
1452
|
|
package/dist/standalone.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
2
|
/*!
|
|
3
3
|
Copyright (c) 2024 Remote Technology, Inc.
|
|
4
|
-
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.
|
|
5
|
-
Generated:
|
|
4
|
+
NPM Package: @remoteoss/json-schema-form@0.8.1-dev.20240209164254
|
|
5
|
+
Generated: Fri, 09 Feb 2024 16:43:11 GMT
|
|
6
6
|
|
|
7
7
|
MIT License
|
|
8
8
|
|
|
@@ -11449,8 +11449,10 @@ function checkIfConditionMatchesProperties(node, formValues, formFields, logic)
|
|
|
11449
11449
|
const field = getField(name, formFields);
|
|
11450
11450
|
return validateFieldSchema(
|
|
11451
11451
|
{
|
|
11452
|
-
|
|
11452
|
+
options: field.options,
|
|
11453
|
+
// @TODO/CODE SMELL. We are passing the property (raw field), but buildYupSchema() expected the output field.
|
|
11453
11454
|
...currentProperty,
|
|
11455
|
+
inputType: field.inputType,
|
|
11454
11456
|
required: true
|
|
11455
11457
|
},
|
|
11456
11458
|
value
|
|
@@ -12699,7 +12701,7 @@ function extractParametersFromNode(schemaNode) {
|
|
|
12699
12701
|
const node = (0, import_omit.default)(schemaNode, ["x-jsf-presentation", "presentation"]);
|
|
12700
12702
|
const description = presentation?.description || node.description;
|
|
12701
12703
|
const statementDescription = presentation.statement?.description;
|
|
12702
|
-
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" ? {
|
|
12704
|
+
const value = typeof node.const !== "undefined" && typeof node.default !== "undefined" && node.const === node.default ? { forcedValue: node.const } : {};
|
|
12703
12705
|
return (0, import_omitBy.default)(
|
|
12704
12706
|
{
|
|
12705
12707
|
const: node.const,
|
|
@@ -12795,9 +12797,10 @@ var handleValuesChange = (fields, jsonSchema, config, logic) => (values2) => {
|
|
|
12795
12797
|
};
|
|
12796
12798
|
};
|
|
12797
12799
|
function getDecoratedComputedAttributes(computedAttributes) {
|
|
12800
|
+
const isEqualConstAndDefault = computedAttributes?.const === computedAttributes?.default;
|
|
12798
12801
|
return {
|
|
12799
12802
|
...computedAttributes ?? {},
|
|
12800
|
-
...computedAttributes?.const && computedAttributes?.default ? {
|
|
12803
|
+
...computedAttributes?.const && computedAttributes?.default && isEqualConstAndDefault ? { forcedValue: computedAttributes.const } : {}
|
|
12801
12804
|
};
|
|
12802
12805
|
}
|
|
12803
12806
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@remoteoss/json-schema-form",
|
|
3
|
-
"version": "0.8.1-dev.
|
|
3
|
+
"version": "0.8.1-dev.20240209164254",
|
|
4
4
|
"description": "Headless UI form powered by JSON Schemas",
|
|
5
5
|
"author": "Remote.com <engineering@remote.com> (https://remote.com/)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -423,59 +423,3 @@ describe('Conditional attributes updated', () => {
|
|
|
423
423
|
expect(fields[1].visibilityCondition).toEqual(expect.any(Function));
|
|
424
424
|
});
|
|
425
425
|
});
|
|
426
|
-
|
|
427
|
-
describe('Conditional with a minimum value check', () => {
|
|
428
|
-
it('Should handle a maximum as a property field check', () => {
|
|
429
|
-
const schema = {
|
|
430
|
-
additionalProperties: false,
|
|
431
|
-
allOf: [
|
|
432
|
-
{
|
|
433
|
-
if: {
|
|
434
|
-
properties: {
|
|
435
|
-
salary: {
|
|
436
|
-
maximum: 119999,
|
|
437
|
-
},
|
|
438
|
-
},
|
|
439
|
-
required: ['salary'],
|
|
440
|
-
},
|
|
441
|
-
then: {
|
|
442
|
-
required: ['reason'],
|
|
443
|
-
},
|
|
444
|
-
else: {
|
|
445
|
-
properties: {
|
|
446
|
-
reason: false,
|
|
447
|
-
},
|
|
448
|
-
},
|
|
449
|
-
},
|
|
450
|
-
],
|
|
451
|
-
properties: {
|
|
452
|
-
salary: {
|
|
453
|
-
type: 'number',
|
|
454
|
-
'x-jsf-presentation': {
|
|
455
|
-
inputType: 'money',
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
reason: {
|
|
459
|
-
oneOf: [
|
|
460
|
-
{
|
|
461
|
-
const: 'reason_one',
|
|
462
|
-
},
|
|
463
|
-
{
|
|
464
|
-
const: 'reason_two',
|
|
465
|
-
},
|
|
466
|
-
],
|
|
467
|
-
type: 'string',
|
|
468
|
-
},
|
|
469
|
-
},
|
|
470
|
-
required: ['salary'],
|
|
471
|
-
type: 'object',
|
|
472
|
-
};
|
|
473
|
-
|
|
474
|
-
const { handleValidation } = createHeadlessForm(schema, { strictInputType: false });
|
|
475
|
-
expect(handleValidation({ salary: 120000 }).formErrors).toEqual(undefined);
|
|
476
|
-
expect(handleValidation({ salary: 1000 }).formErrors).toEqual({
|
|
477
|
-
reason: 'Required field',
|
|
478
|
-
});
|
|
479
|
-
expect(handleValidation({ salary: 1000, reason: 'reason_one' }).formErrors).toEqual(undefined);
|
|
480
|
-
});
|
|
481
|
-
});
|
package/src/tests/const.test.js
CHANGED
|
@@ -112,7 +112,7 @@ describe('validations: const', () => {
|
|
|
112
112
|
},
|
|
113
113
|
{ strictInputType: false }
|
|
114
114
|
);
|
|
115
|
-
expect(fields[0]).toMatchObject({
|
|
115
|
+
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
116
116
|
});
|
|
117
117
|
});
|
|
118
118
|
|
|
@@ -130,7 +130,7 @@ describe('const/default with forced values', () => {
|
|
|
130
130
|
expect(handleValidation({ zero_only: 1 }).formErrors).toEqual({
|
|
131
131
|
zero_only: 'The only accepted value is 0.',
|
|
132
132
|
});
|
|
133
|
-
expect(fields[0]).toMatchObject({
|
|
133
|
+
expect(fields[0]).toMatchObject({ forcedValue: 0, const: 0, default: 0 });
|
|
134
134
|
expect(handleValidation({ zero_only: 0 }).formErrors).toBeUndefined();
|
|
135
135
|
// null is also considered valid until we fix @BUG RMT-518
|
|
136
136
|
// Expectation: To fail with error "The only accepted value is 0."
|
|
@@ -151,9 +151,21 @@ describe('const/default with forced values', () => {
|
|
|
151
151
|
ten_only: 'The only accepted value is 10.',
|
|
152
152
|
});
|
|
153
153
|
expect(handleValidation({ ten_only: 10 }).formErrors).toBeUndefined();
|
|
154
|
-
expect(fields[0]).toMatchObject({
|
|
154
|
+
expect(fields[0]).toMatchObject({ forcedValue: 10, const: 10, default: 10 });
|
|
155
155
|
// null is also considered valid until we fix @BUG RMT-518
|
|
156
156
|
// Expectation: To fail with error "The only accepted value is 10."
|
|
157
157
|
expect(handleValidation({ ten_only: null }).formErrors).toBeUndefined();
|
|
158
158
|
});
|
|
159
|
+
|
|
160
|
+
it('do not set a forced value if const and default do not equal', () => {
|
|
161
|
+
const { fields } = createHeadlessForm(
|
|
162
|
+
{
|
|
163
|
+
properties: {
|
|
164
|
+
bad_field_for_number: { type: 'number', const: 10, default: 20 },
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
{ strictInputType: false }
|
|
168
|
+
);
|
|
169
|
+
expect(fields[0]).not.toMatchObject({ forcedValue: expect.any(Number) });
|
|
170
|
+
});
|
|
159
171
|
});
|
|
@@ -227,6 +227,35 @@ export const schemaWithComputedAttributes = {
|
|
|
227
227
|
},
|
|
228
228
|
};
|
|
229
229
|
|
|
230
|
+
export const badSchemaThatWillNotSetAForcedValue = {
|
|
231
|
+
properties: {
|
|
232
|
+
field_a: {
|
|
233
|
+
type: 'number',
|
|
234
|
+
},
|
|
235
|
+
field_b: {
|
|
236
|
+
type: 'number',
|
|
237
|
+
'x-jsf-logic-computedAttrs': {
|
|
238
|
+
const: 'a_times_three',
|
|
239
|
+
default: 'a_times_two',
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
},
|
|
243
|
+
'x-jsf-logic': {
|
|
244
|
+
computedValues: {
|
|
245
|
+
a_times_two: {
|
|
246
|
+
rule: {
|
|
247
|
+
'*': [{ var: 'field_a' }, 2],
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
a_times_three: {
|
|
251
|
+
rule: {
|
|
252
|
+
'*': [{ var: 'field_a' }, 3],
|
|
253
|
+
},
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
|
|
230
259
|
export const schemaWithInlineRuleForComputedAttributeWithoutCopy = {
|
|
231
260
|
properties: {
|
|
232
261
|
field_a: {
|
|
@@ -35,6 +35,7 @@ import {
|
|
|
35
35
|
schemaWithUnknownVariableInComputedValues,
|
|
36
36
|
schemaWithUnknownVariableInValidations,
|
|
37
37
|
schemaWithValidationThatDoesNotExistOnProperty,
|
|
38
|
+
badSchemaThatWillNotSetAForcedValue,
|
|
38
39
|
} from './jsonLogic.fixtures';
|
|
39
40
|
import { mockConsole, restoreConsoleAndEnsureItWasNotCalled } from './testUtils';
|
|
40
41
|
|
|
@@ -335,12 +336,21 @@ describe('jsonLogic: cross-values validations', () => {
|
|
|
335
336
|
'This field is 2 times bigger than field_a with value of 4.'
|
|
336
337
|
);
|
|
337
338
|
expect(fieldB.default).toEqual(4);
|
|
338
|
-
expect(fieldB.
|
|
339
|
+
expect(fieldB.forcedValue).toEqual(4);
|
|
339
340
|
handleValidation({ field_a: 4 });
|
|
340
341
|
expect(fieldB.default).toEqual(8);
|
|
341
342
|
expect(fieldB.label).toEqual('This is 8!');
|
|
342
343
|
});
|
|
343
344
|
|
|
345
|
+
it('A forced value will not be set when const and default are not equal', () => {
|
|
346
|
+
const { fields } = createHeadlessForm(badSchemaThatWillNotSetAForcedValue, {
|
|
347
|
+
strictInputType: false,
|
|
348
|
+
initialValues: { field_a: 2 },
|
|
349
|
+
});
|
|
350
|
+
expect(fields[1]).toMatchObject({ const: 6, default: 4 });
|
|
351
|
+
expect(fields[1]).not.toMatchObject({ forcedValue: expect.any(Number) });
|
|
352
|
+
});
|
|
353
|
+
|
|
344
354
|
it('Derived errorMessages and statements work', () => {
|
|
345
355
|
const { fields, handleValidation } = createHeadlessForm(
|
|
346
356
|
schemaWithComputedAttributesAndErrorMessages,
|