Skip to content

Commit

Permalink
chore(hotfix): Ignore internal attributes from conditional attributes…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
sandrina-p committed Nov 7, 2023
1 parent c32eefa commit ee762c2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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 <engineering@remote.com> (https://remote.com/)",
"license": "MIT",
Expand Down
4 changes: 4 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
58 changes: 58 additions & 0 deletions src/tests/conditions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<A React Component>',
calculateDynamicProperties: () => true,
},
},
}
);

// It's there by default
expect(fields[1].Component).toBe('<A React Component>');
expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function));

// Given "Yes", it stays there too.
handleValidation({ is_full_time: 'yes' });
expect(fields[1].Component).toBe('<A React Component>');
expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function));

// Given "No", it stays there too.
handleValidation({ is_full_time: 'no' });
expect(fields[1].Component).toBe('<A React Component>');
expect(fields[1].calculateDynamicProperties).toEqual(expect.any(Function));
});
});

0 comments on commit ee762c2

Please sign in to comment.