Skip to content
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

If/Then/Else - Code Review changes from #2506 and tests from #2466 #2700

Merged
merged 11 commits into from
Feb 18, 2022

Conversation

nickgros
Copy link
Contributor

@nickgros nickgros commented Feb 10, 2022

Reasons for making this change

I added changes from code review to the PR in #2506 and added integration tests from my PR in #2466

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@nickgros nickgros mentioned this pull request Feb 10, 2022
7 tasks
if (conditionalSchema) {
return retrieveSchema(
mergeSchemas(
retrieveSchema(conditionalSchema, rootSchema, formData),
Copy link
Member

Choose a reason for hiding this comment

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

{
if: ...,
then: {minLength: 5},
minLength: 10
}

Expected behavior: inner property (minLength: 5) should override outer property (minLength: 10). We should add a test case for this

And potentially swap these two arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test case correctly captures the issue 🎉

export function resolveSchema(schema, rootSchema = {}, formData = {}) {
if (schema.hasOwnProperty("$ref")) {
return resolveReference(schema, rootSchema, formData);
} else if (schema.hasOwnProperty("dependencies")) {
const resolvedSchema = resolveDependencies(schema, rootSchema, formData);
return retrieveSchema(resolvedSchema, rootSchema, formData);
} else if (schema.hasOwnProperty("if")) {
Copy link
Member

Choose a reason for hiding this comment

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

See if we can move this to retrieveSchema instead and everything still works.

return retrieveSchema(resolvedSchemaLessConditional, rootSchema, formData);
}
};

export function resolveSchema(schema, rootSchema = {}, formData = {}) {
Copy link
Member

Choose a reason for hiding this comment

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

Document this

// Resolves references and dependencies and references within branches of allOf
// Called internally by retrieveSchema

expect(node.querySelector("input[label=postal_code]")).not.eql(null);
});

it("should should render control when data has not been filled in", () => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
it("should should render control when data has not been filled in", () => {
it("should render control when data has not been filled in", () => {

formData,
});

// This feels backwards but is basically because undefined equates to true when field is validated
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// This feels backwards but is basically because undefined equates to true when field is validated
// An empty formData will make the conditional evaluate to true because no properties are required in the if statement

@nickgros
Copy link
Contributor Author

Pulled in @Juansasa's recent changes and added other changes from code review. Thanks for all of the great work @Juansasa!

@ksbrar
Copy link

ksbrar commented Feb 20, 2022

Estimate on when this will be released? @epicfaace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants