-
Notifications
You must be signed in to change notification settings - Fork 27
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
Conversation
invenio_administration/assets/semantic-ui/js/invenio_administration/src/formik/AdminForm.js
Show resolved
Hide resolved
There was a problem hiding this 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") { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
Line 175 in 636066f
fieldSchema.metadata?.type === "json" |
if (
(fieldSchema.type === "string" && rows) ||
fieldSchema.metadata?.type === "json"
) {
return (
<TextArea
key={fieldProps.fieldPath}
fieldPath={fieldProps.fieldPath}
rows={rows}
{...fieldProps}
/>
);
}
console.error(`Error parsing JSON for field ${key}:`, e); | ||
actions.setFieldError(key, "Invalid JSON format"); | ||
throw e; |
There was a problem hiding this comment.
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.
❤️ Thank you for your contribution!
Description
Closes inveniosoftware/invenio-jobs#23
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: