@remoteoss/json-schema-form 0.11.8-beta.0 → 0.11.9-beta.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ #### 0.11.9-beta.0 (2024-12-17)
2
+
3
+ ##### Bug Fixes
4
+
5
+ * Add support for boolean values in the if condition ([#100](https://github.com/remoteoss/json-schema-form/pull/100)) ([b3dca67d](https://github.com/remoteoss/json-schema-form/commit/b3dca67da14a7e4f5339a14a1e2f14ac014d2b92))
6
+
1
7
  #### 0.11.8-beta.0 (2024-11-20)
2
8
 
3
9
  ##### Bug Fixes
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.11.8-beta.0
5
- Generated: Wed, 20 Nov 2024 13:34:29 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-beta.0
5
+ Generated: Tue, 17 Dec 2024 08:59:12 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -98,6 +98,9 @@ function hasProperty(object2, propertyName) {
98
98
 
99
99
  // src/checkIfConditionMatches.js
100
100
  function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
101
+ if (typeof node.if === "boolean") {
102
+ return node.if;
103
+ }
101
104
  return Object.keys(node.if.properties ?? {}).every((name) => {
102
105
  const currentProperty = node.if.properties[name];
103
106
  const value = formValues[name];
@@ -1313,7 +1316,7 @@ function processNode({
1313
1316
  parentID
1314
1317
  });
1315
1318
  });
1316
- if (node.if) {
1319
+ if (node.if !== void 0) {
1317
1320
  const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
1318
1321
  if (matchesCondition && node.then) {
1319
1322
  const { required: branchRequired } = processNode({
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.11.8-beta.0
5
- Generated: Wed, 20 Nov 2024 13:34:29 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-beta.0
5
+ Generated: Tue, 17 Dec 2024 08:59:12 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -61,6 +61,9 @@ function hasProperty(object2, propertyName) {
61
61
 
62
62
  // src/checkIfConditionMatches.js
63
63
  function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
64
+ if (typeof node.if === "boolean") {
65
+ return node.if;
66
+ }
64
67
  return Object.keys(node.if.properties ?? {}).every((name) => {
65
68
  const currentProperty = node.if.properties[name];
66
69
  const value = formValues[name];
@@ -1276,7 +1279,7 @@ function processNode({
1276
1279
  parentID
1277
1280
  });
1278
1281
  });
1279
- if (node.if) {
1282
+ if (node.if !== void 0) {
1280
1283
  const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
1281
1284
  if (matchesCondition && node.then) {
1282
1285
  const { required: branchRequired } = processNode({
@@ -1,8 +1,8 @@
1
1
 
2
2
  /*!
3
3
  Copyright (c) 2024 Remote Technology, Inc.
4
- NPM Package: @remoteoss/json-schema-form@0.11.8-beta.0
5
- Generated: Wed, 20 Nov 2024 13:34:29 GMT
4
+ NPM Package: @remoteoss/json-schema-form@0.11.9-beta.0
5
+ Generated: Tue, 17 Dec 2024 08:59:12 GMT
6
6
 
7
7
  MIT License
8
8
 
@@ -11578,6 +11578,9 @@ function hasProperty(object2, propertyName) {
11578
11578
 
11579
11579
  // src/checkIfConditionMatches.js
11580
11580
  function checkIfConditionMatchesProperties(node, formValues, formFields, logic) {
11581
+ if (typeof node.if === "boolean") {
11582
+ return node.if;
11583
+ }
11581
11584
  return Object.keys(node.if.properties ?? {}).every((name) => {
11582
11585
  const currentProperty = node.if.properties[name];
11583
11586
  const value = formValues[name];
@@ -12792,7 +12795,7 @@ function processNode({
12792
12795
  parentID
12793
12796
  });
12794
12797
  });
12795
- if (node.if) {
12798
+ if (node.if !== void 0) {
12796
12799
  const matchesCondition = checkIfConditionMatchesProperties(node, formValues, formFields, logic);
12797
12800
  if (matchesCondition && node.then) {
12798
12801
  const { required: branchRequired } = processNode({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remoteoss/json-schema-form",
3
- "version": "0.11.8-beta.0",
3
+ "version": "0.11.9-beta.0",
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",
@@ -1,5 +1,13 @@
1
1
  import { checkIfConditionMatchesProperties } from '../checkIfConditionMatches';
2
2
 
3
+ it('True if is always going to be true', () => {
4
+ expect(checkIfConditionMatchesProperties({ if: true })).toBe(true);
5
+ });
6
+
7
+ it('False if is always going to be false', () => {
8
+ expect(checkIfConditionMatchesProperties({ if: false })).toBe(false);
9
+ });
10
+
3
11
  it('Empty if is always going to be true', () => {
4
12
  expect(checkIfConditionMatchesProperties({ if: { properties: {} } })).toBe(true);
5
13
  });
@@ -479,3 +479,71 @@ describe('Conditional with a minimum value check', () => {
479
479
  expect(handleValidation({ salary: 1000, reason: 'reason_one' }).formErrors).toEqual(undefined);
480
480
  });
481
481
  });
482
+
483
+ describe('Conditional with literal booleans', () => {
484
+ it('handles true case', () => {
485
+ const schema = {
486
+ properties: {
487
+ is_full_time: {
488
+ type: 'boolean',
489
+ },
490
+ salary: {
491
+ type: 'number',
492
+ },
493
+ },
494
+ required: [],
495
+ if: true,
496
+ then: {
497
+ required: ['is_full_time'],
498
+ },
499
+ else: {
500
+ required: ['salary'],
501
+ },
502
+ };
503
+ const { fields, handleValidation } = createHeadlessForm(schema, { strictInputType: false });
504
+
505
+ handleValidation({});
506
+
507
+ expect(fields[0]).toMatchObject({
508
+ name: 'is_full_time',
509
+ required: true,
510
+ });
511
+ expect(fields[1]).toMatchObject({
512
+ name: 'salary',
513
+ required: false,
514
+ });
515
+ });
516
+
517
+ it('handles false case', () => {
518
+ const schema = {
519
+ properties: {
520
+ is_full_time: {
521
+ type: 'boolean',
522
+ },
523
+ salary: {
524
+ type: 'number',
525
+ },
526
+ },
527
+ required: [],
528
+ if: false,
529
+ then: {
530
+ required: ['is_full_time'],
531
+ },
532
+ else: {
533
+ required: ['salary'],
534
+ },
535
+ };
536
+ const { fields, handleValidation } = createHeadlessForm(schema, { strictInputType: false });
537
+
538
+ handleValidation({});
539
+
540
+ expect(fields[0]).toMatchObject({
541
+ name: 'is_full_time',
542
+ required: false,
543
+ });
544
+ expect(fields[1]).toMatchObject({
545
+ name: 'salary',
546
+ required: true,
547
+ });
548
+ });
549
+ });