Skip to content

feat(renderer): enable condition set as a function #1331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2022

Conversation

JuliePrazakova
Copy link
Collaborator

@JuliePrazakova JuliePrazakova commented Oct 4, 2022

Fixes #1326

Checklist: (please see documentation page for more information)

  • Yarn build passes
  • Yarn lint passes
  • Yarn test passes
  • Test coverage for new code (if applicable)
  • Documentation update (if applicable)
  • Correct commit message
    • format fix|feat({scope}): {description}
    • i.e. fix(pf3): wizard correctly handles next button
    • fix will release a new _._.X version
    • feat will release a new _.X._ version (use when you introduce new features)
      • we want to avoid any breaking changes, please contact us, if there is no way how to avoid them
    • scope: package
    • if you update the documentation or tests, do not use this format
      • i.e. Fix button on documenation example page

@DataDrivenFormsBot
Copy link

DataDrivenFormsBot commented Oct 4, 2022

A new version (feat) will be released: v3.19.0 [DataDrivenFormsBot]

@codecov
Copy link

codecov bot commented Oct 4, 2022

Codecov Report

Merging #1331 (14de368) into master (bc00ae0) will increase coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #1331      +/-   ##
==========================================
+ Coverage   95.09%   95.11%   +0.01%     
==========================================
  Files         209      209              
  Lines        3627     3641      +14     
  Branches     1265     1270       +5     
==========================================
+ Hits         3449     3463      +14     
  Misses        178      178              
Impacted Files Coverage Δ
...ges/react-form-renderer/src/condition/condition.js 98.27% <100.00%> (+0.54%) ⬆️
...fault-schema-validator/default-schema-validator.js 99.15% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@JuliePrazakova JuliePrazakova added the renderer React form renderer PR label Oct 11, 2022
@JuliePrazakova JuliePrazakova marked this pull request as ready for review October 11, 2022 09:29
@JuliePrazakova JuliePrazakova changed the title fix renderer dev server feat(renderer): enable condition set as a function Oct 11, 2022
Copy link
Contributor

@rvsia rvsia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, it looks great!

Checked only the code so far, found some nitpicks.

Could you please also update the documentation to introduce this new feature?

import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';

import useFormApi from '../use-form-api';
import parseCondition from '../parse-condition';

function setterValueCheck(setterValue) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please use arrow function notation here to keep the consistency?

@@ -42,6 +52,14 @@ const Condition = React.memo(
}
}, [dirty]);

const x = useCallback(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x is kinda a mysterious name 😵‍💫

formOptions.change(name, value);
});
},
[formOptions.change]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

formOptions.change will be always the same, so no need to check it

@@ -531,6 +531,150 @@ describe('condition test', () => {
await waitFor(() => expect(screen.getByLabelText('field2')).toHaveValue('set with then'));
});

test('should change fileds value by set funciton', async () => {
Copy link
Contributor

@rvsia rvsia Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use it instead of test, also a typo here

Object.entries(setter).forEach(([name, value]) => {
formOptions.change(name, value);
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to keep an empty dependency array here: [] otherwise the function will be always re-created.

See here

@Hyperkid123 Hyperkid123 reopened this Oct 18, 2022
@Hyperkid123 Hyperkid123 merged commit 0ee0369 into data-driven-forms:master Oct 18, 2022
@rvsia rvsia added the released label Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released renderer React form renderer PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow set condition attribute to be a function
4 participants