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

fix: support custom attributes as functions (do not execute them) #86

Merged

Conversation

sandrina-p
Copy link
Collaborator

@sandrina-p sandrina-p commented Jul 29, 2024

This one is hard to explain with words alone. Here's a Loom (public) explaining the real problem, the path to the solution.

Linear ticket


TLDR:

Before a JSON Schema like this would throw an error, but now it works well:

This schema includes a conditional field field_b with a custom attribute x-jsf-presentation.MyComponent which is a function. Before createHeadlessForm() would execute it even though it's not necessary

const { fields, handleValidation } = createHeadlessForm({
  properties: {
    field_a: {
      title: 'A field',
      'x-jsf-presentation': {
        inputType: 'text',
      },
    },
    field_b: {
      title: 'Field B',
      'x-jsf-presentation': {
        inputType: 'text',
        MyComponent: function MyComponent(props) {
          // 🐛 ✅ This now works! Before it would explode trying to run this (when it shouldn't).
          const { label, description } = props;
          return `A fake React component with ${label} and ${description}`;
        },
      },
    },
  },
  allOf: [
    {
      if: {
        properties: {
          field_a: { const: 'yes' },
        },
        required: ['field_a'],
      },
      then: {
        required: ['field_b'],
      },
    },
  ],
});

@sandrina-p sandrina-p self-assigned this Jul 29, 2024
@sandrina-p sandrina-p changed the title Draft fix: support custom attributes as functions (do not execute functions in custom attributes) fix: support custom attributes as functions (do not execute functions in custom attributes) Jul 29, 2024
@sandrina-p sandrina-p requested a review from ollyd July 29, 2024 10:35
@sandrina-p sandrina-p changed the title fix: support custom attributes as functions (do not execute functions in custom attributes) fix: support custom attributes as functions (do not execute them) Jul 29, 2024
@sandrina-p sandrina-p force-pushed the rmt-876-jsf-modify-passing-a-custom-component-breaks-the-code branch from 41b5d1a to 6412160 Compare July 29, 2024 10:41
@sandrina-p sandrina-p force-pushed the rmt-876-jsf-modify-passing-a-custom-component-breaks-the-code branch from a20d913 to bf20af4 Compare July 29, 2024 11:52
@brennj
Copy link
Collaborator

brennj commented Jul 30, 2024

Based on the loom and testing this internally, happy for this to go in!

@sandrina-p sandrina-p merged commit 3674fc8 into main Jul 30, 2024
3 checks passed
@sandrina-p sandrina-p deleted the rmt-876-jsf-modify-passing-a-custom-component-breaks-the-code branch July 30, 2024 11:58
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.

2 participants