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

form: added support for json fields #215

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

0einstein0
Copy link
Member

❤️ Thank you for your contribution!

Description

Closes inveniosoftware/invenio-jobs#23

  • Right now using TextAreaField for the json object so need to transform it accordingly before rendering in the form and submitting
  • Will introduce a separate component for json specifically in future

Checklist

Ticks in all boxes and 🟢 on all GitHub actions status checks are required to merge:

Frontend

Reminder

By using GitHub, you have already agreed to the GitHub’s Terms of Service including that:

  1. You license your contribution under the same terms as the current repository’s license.
  2. You agree that you have the right to license your contribution under the current repository’s license.

Copy link
Member

@slint slint left a comment

Choose a reason for hiding this comment

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

LGTM, some minor comments (and one to be shelved).

@@ -134,7 +135,7 @@ const mapFormFields = (obj, parentField, isCreate, formFieldsConfig, dropDumpOnl
);
}

if (fieldSchema.type === "object") {
if (fieldSchema.type === "object" && fieldSchema.metadata?.type !== "json") {
Copy link
Member

Choose a reason for hiding this comment

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

minor: wouldn't it be better to explicitly have a clause for the "json" type? Or are there cases where this type is "inferred" somewhere and we have to exclude it explicitly here?

Copy link
Member Author

Choose a reason for hiding this comment

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

I set it as json in the metadata.type in the schema otherwise it is interpreted as an object, hence why I had to add this check here. Could have made a separate for just json but it is just rendering a TextField for now like strings so I put it there for now as we are planning on adding support for json/code later I assume

    if (
      (fieldSchema.type === "string" && rows) ||
      fieldSchema.metadata?.type === "json"
    ) {
      return (
        <TextArea
          key={fieldProps.fieldPath}
          fieldPath={fieldProps.fieldPath}
          rows={rows}
          {...fieldProps}
        />
      );
    }

Comment on lines +59 to +61
console.error(`Error parsing JSON for field ${key}:`, e);
actions.setFieldError(key, "Invalid JSON format");
throw e;
Copy link
Member

Choose a reason for hiding this comment

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

minor/shelve: I feel that the whole conversion/validation logic is spread throughout the module, instead of specific components/classes being responsible for it. Not sure if it should be addressed in this PR, but definitely something to look into in the future.

On a separate note, it's likely that in the future we'll look into integrating a dedicated code-editor style of form field for JSON (or YAML), where I would expect the form control to be responsible for all this logic.

@slint slint merged commit 3eddb64 into inveniosoftware:main Jun 20, 2024
16 checks passed
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.

Job-UI: Create,Edit and Schedule
3 participants