diff --git a/package-lock.json b/package-lock.json index 252ddf88c..907255b07 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 59044a76a..733883406 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 1a86783ac..395d6f0a3 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 9114e5e89..308620d44 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)); + }); });