From ee762c2e90834a9ec0d7b88af47cefe1e3a03dd1 Mon Sep 17 00:00:00 2001 From: Sandrina Pereira Date: Tue, 7 Nov 2023 15:40:07 +0100 Subject: [PATCH] chore(hotfix): Ignore internal attributes from conditional attributes removal (#58) * chore(hotfix): Ignore 'Component' from conditional attributes removal * Release 0.7.4-dev.20231107114922 * Add another internal attr calculateDynamicProperties * Release 0.7.4-dev.20231107125305 * Revert back to 0.7.2-beta.0 --- package-lock.json | 4 +-- package.json | 2 +- src/helpers.js | 4 +++ src/tests/conditions.test.js | 58 ++++++++++++++++++++++++++++++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 252ddf88..907255b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@remoteoss/json-schema-form", - "version": "0.7.3-beta.0", + "version": "0.7.2-beta.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@remoteoss/json-schema-form", - "version": "0.7.3-beta.0", + "version": "0.7.2-beta.0", "license": "MIT", "dependencies": { "json-logic-js": "^2.0.2", diff --git a/package.json b/package.json index 59044a76..73388340 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@remoteoss/json-schema-form", - "version": "0.7.3-beta.0", + "version": "0.7.2-beta.0", "description": "Headless UI form powered by JSON Schemas", "author": "Remote.com (https://remote.com/)", "license": "MIT", diff --git a/src/helpers.js b/src/helpers.js index 1a86783a..395d6f0a 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -24,6 +24,10 @@ const dynamicInternalJsfAttrs = [ 'calculateConditionalProperties', // driven from conditionals 'calculateCustomValidationProperties', // To be deprecated in favor of json-logic 'scopedJsonSchema', // The respective JSON Schema + + // HOTFIX/TODO Internal customizations, check test conditions.test.js for more info. + 'Component', + 'calculateDynamicProperties', ]; const dynamicInternalJsfAttrsObj = Object.fromEntries( dynamicInternalJsfAttrs.map((k) => [k, true]) diff --git a/src/tests/conditions.test.js b/src/tests/conditions.test.js index 9114e5e8..308620d4 100644 --- a/src/tests/conditions.test.js +++ b/src/tests/conditions.test.js @@ -358,4 +358,62 @@ describe('Conditional attributes updated', () => { ], }); }); + + it('Keeps custom attribute Component (fieldAttrsFromJsf) (hotfix temporary)', () => { + // This is necessary as hotfix because we (Remote) use it internally. + // Not cool, we'll need a better solution asap. + const { fields, handleValidation } = createHeadlessForm( + { + properties: { + is_full_time: { type: 'string', oneOf: [{ const: 'yes' }, { const: 'no' }] }, + salary_period: { + type: 'string', + title: 'Salary period', + oneOf: [ + { title: 'Weekly', const: 'weekly' }, + { title: 'Monthly', const: 'monthly' }, + ], + }, + }, + allOf: [ + { + if: { + properties: { is_full_time: { const: 'yes' } }, + required: ['is_full_time'], + }, + then: { + properties: { + salary_period: { + description: 'We recommend montlhy.', + }, + }, + }, + }, + ], + }, + { + strictInputType: false, + customProperties: { + salary_period: { + Component: '', + calculateDynamicProperties: () => true, + }, + }, + } + ); + + // It's there by default + expect(fields[1].Component).toBe(''); + expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function)); + + // Given "Yes", it stays there too. + handleValidation({ is_full_time: 'yes' }); + expect(fields[1].Component).toBe(''); + expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function)); + + // Given "No", it stays there too. + handleValidation({ is_full_time: 'no' }); + expect(fields[1].Component).toBe(''); + expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function)); + }); });