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

Update JSON Forms #241

Merged
merged 46 commits into from
Sep 3, 2024
Merged

Update JSON Forms #241

merged 46 commits into from
Sep 3, 2024

Conversation

sakshibobade21
Copy link
Contributor

@sakshibobade21 sakshibobade21 commented Aug 9, 2024

Proposed changes

This PR addresses Issue:

  1. Updates json forms to work with the schemas with oneOf attribute
  2. Adds the radio buttons to choose from the available schemas
  3. Conditionally showing the "Vsam Dataset" field only if "name" does not exists on the vsam object
  4. The "name" field in the vsam object updates the attribute components.caching-service.storage.vsam.name
  5. Updated the dataset pattern to allow 38 characters ate max. Basically I replaced the previous dataset pattern to the one over here: https://github.com/zowe/zowe-install-packaging/blob/v2.x/staging/schemas/server-common.json#L31 so that we have consistency
  6. Code Organization and Cleanup

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Change in a documentation
  • Refactor the code
  • Chore, repository cleanup, updates the dependencies.
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

PR Checklist

Please delete options that are not relevant.

  • If the changes in this PR are meant for the next release / mainline, this PR targets a "staging" branch.
  • My code follows the style guidelines of this project (see: Contributing guideline)
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • New and existing unit tests pass locally with my changes
  • video or image is included if visual changes are made
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works, or describe a test method below

Testing

Further comments

@sakshibobade21 sakshibobade21 changed the title [WIP] Update JSON Forms Update JSON Forms Aug 21, 2024
const serverCommon = JSON.parse(readPaxYamlAndSchema.details.serverCommon);
updateSchemaReferences(readPaxYamlAndSchema.details, yamlSchema);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why are we duplicating changes made in #240 here?

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 PR is built on the top of #240

@@ -181,7 +175,7 @@ class Installation {
ConfigurationStore.setSchema(FALLBACK_SCHEMA);
return {status: false, details: {message: 'no schemas found from pax'}}
}
return {status: parsedSchema && parsedYaml, details: {message: "Successfully retrieved example-zowe.yaml and schemas", mergedYaml: yamlObj}}
return {status: parsedSchema && parsedYaml, details: {message: "Successfully retrieved example-zowe.yaml and schemas", mergedYaml: yamlObj, yamlSchema: yamlSchema}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Schema is already saved to the ConfigurationStore, lines 162, 169 and 175.
Then we take yamlSchema that will exist only in successful case (as you only set it in the try block on line 157 and so it will be empty in other cases instead of FALLBACK_SCHEMA)
And then you return it to the UI (Unpax.tsx:180) where use for rendering and override the ConfigurationStore scheme if it exists, which makes not much sense to me, or am i missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good catch. Thanks. I fixed it.

if (!schema || !formData) {
return "";
// To handle the "if", "else", and "then" in the schema
const conditionalSchema = (schema: any, formData: any, prop: any): boolean=> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What reference were you using for this definition? I am looking at https://json-schema.org/understanding-json-schema/reference/conditionals#ifthenelse and it states that then or else can be omitted, also then and else sections can have properties with pattern, not only required field

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 section was initially added to handle if-else conditions in the certificate schema for previous versions of Zowe. At that time, we were only verifying whether the conditional attributes were met.

These sections can also contain properties, and while all the properties were displayed, our primary focus was on checking if the condition matched.

config={{showUnfocusedDescription: true}}
onChange={({ data, errors }) => { onChange(data) }}
/>
{ schema.oneOf &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

General question, can't JSONForms work with "oneOf" out of the box?
I didn't research much but from here it seems that is should be supported using tabs?

Copy link
Contributor Author

@sakshibobade21 sakshibobade21 Aug 30, 2024

Choose a reason for hiding this comment

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

It could work, but we had a slightly different approach in mind:

  1. We preferred radio buttons instead of tabs.
  2. The JSON form data is stored in YAML, so we needed the YAML to comply with only one schema at a time. For this, we created a function called filterFormData.
  3. We also required AJV to validate the data against the correct schema selected from the oneOf schemas.
  4. Additionally, we don't use the JsonForms renderer as-is. We customize it as needed in the makeUISchema function. To make this work, we had to take this approach

Copy link
Collaborator

@skurnevich skurnevich left a comment

Choose a reason for hiding this comment

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

Ok, but please review the comment to InitApfAuth.tsx before merge

@@ -231,21 +230,7 @@ const InitApfAuth = () => {
}, {});
}

if(validate) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you remove this validation here? There is unused code block a few lines above, newData is never being used, so i wonder if it is not a mistake?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I removed this part of the code because it is unnecessary. The APF authorization stage includes read-only fields populated during the previous "Dataset Initialization" stage, where validations for these fields have already been performed. Re-validating them here is redundant.

I also considered removing the formChangeHandler function, as it's no longer required. However, I chose not to do so in this PR to keep the focus solely on the schema updates. I plan to address it in future code optimization PRs.

@skurnevich skurnevich merged commit e8960c5 into v2.x/staging Sep 3, 2024
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

2 participants