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

Consider moving omit extra data functionality to schemaUtils #4081

Open
1 task done
MarekBodingerBA opened this issue Feb 5, 2024 · 1 comment · May be fixed by #4139
Open
1 task done

Consider moving omit extra data functionality to schemaUtils #4081

MarekBodingerBA opened this issue Feb 5, 2024 · 1 comment · May be fixed by #4139
Labels

Comments

@MarekBodingerBA
Copy link
Contributor

MarekBodingerBA commented Feb 5, 2024

Prerequisites

What theme are you using?

core

What is your question?

Hello,

Due to the advanced way in which we use RJSF, we need to programmatically omit extra data. We have implemented our own step functionality on top of RJSF, and we need to filter out extra data without submitting the form when switching between steps, as liveOmit is hitting our performance requirements.

Temporarily, we have created a custom function that mimics the logic from here and here:

function omitData(schema: RJSFSchema, formData: RJSFSchema) {
  // rjsfValidator and defaultFormStateBehavior are shared consts
  const schemaUtils = createSchemaUtils(rjsfValidator, schema, defaultFormStateBehavior)
  const formInstance = new Form({ schema, validator: rjsfValidator })

  const retrievedSchema = schemaUtils.retrieveSchema(schema, formData)
  const pathSchema = schemaUtils.toPathSchema(retrievedSchema, '', formData)
  const fieldNames = formInstance.getFieldNames(pathSchema, formData)

  return formInstance.getUsedFormData(formData, fieldNames)
}

Using new Form in this manner is entirely possible, as neither getFieldNames nor getUsedFormData access this. However, it is clear that this is not the best long-term solution. The extraction could be beneficial for other users and would help to avoid duplicating the same logic if it were centralized. Would schemaUtils be an appropriate place for this? A similar function, getDefaultFormState, already exists there.

I propose the following:

  1. Move getFieldNames and getUsedFormData to a separate context, as they are used exclusively by the omit logic.
  2. Move the omit logic in both locations to schemaUtils.omitExtraData and replace its usage in the Form.
  3. Update the tests and documentation accordingly.

I can work on this if you give me the green light to proceed.

Thanks!

@MarekBodingerBA MarekBodingerBA added needs triage Initial label given, to be assigned correct labels and assigned question labels Feb 5, 2024
@MarekBodingerBA MarekBodingerBA changed the title Consider adding omit extra data functionality to schemaUtils Consider moving omit extra data functionality to schemaUtils Feb 5, 2024
@heath-freenome
Copy link
Member

@MarekBodingerBA We would love to get help on this! Feel free to push up a PR for us to review.

@heath-freenome heath-freenome added help wanted feature Is a feature request and removed needs triage Initial label given, to be assigned correct labels and assigned labels Feb 16, 2024
@MarekBodingerBA MarekBodingerBA linked a pull request Mar 22, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants