-
Notifications
You must be signed in to change notification settings - Fork 135
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
Feature json schema #2664
Feature json schema #2664
Conversation
Hey hamzahamidi! Thanks for submitting this pull request! I'm here to inform the recipients of the pull request that you and the commit authors have already signed the CLA. |
Codecov Report
@@ Coverage Diff @@
## v2-master #2664 +/- ##
==============================================
- Coverage 70.03% 48.79% -21.24%
==============================================
Files 599 604 +5
Lines 25504 25892 +388
Branches 5765 5862 +97
==============================================
- Hits 17862 12635 -5227
- Misses 7642 13257 +5615 |
1d08ff7
to
8ca4612
Compare
Hi @hamzahamidi thanks for submitting this PR. Noticed that it currently uses a personal fork of the json schema form field project and that you've created a PR to get this merged back to origin (dschnelldavis/angular2-json-schema-form#295). Do you have a rough idea of when that might happen? |
@richard-cox Thank you for your review. We tweaked the owner repo for angular2-json-schema-form & we're still waiting for the merge. This PR is still on progress. We added the JSON schema support for create schemas & we plan to do the same thing to update schemas |
c9e101d
to
8283be4
Compare
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
3f9ae8a
to
a448786
Compare
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
@richard-cox This PR is ready for review. We switched the personal fork to angular6-json-schema-form because we faced an issue with enabling AOT in the old one. |
Thanks, we will review this ASAP. |
status on the json-schema-form library
I initially proposed dschnelldavis/angular2-json-schema-form#295. |
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.
We apologise for the amount of time it's taken us to start reviewing this PR. Personally I was hoping that the angular2 forms repo would merge your changes, but appreciate you're doing all you can get your changes merged and that your fork is getting some great traction. It's really good to see it already has multiple contributors and stars. I have a question regarding the angular6-json-schema-form's npm entry though, have all people that have update access to it taken steps to secure their account (such as enabling two-step authentication)?
I've had a quick look through using the schema from https://hamidihamza.com/Angular6-json-schema-form/. There's mostly 'best practise' like comments, nothing major. In addition...
- Adding text to fields in the generated form correctly updates the
JSON parameters
text above, however the reverse does not happen. - When the form is invalid (for example a require field such as
last_name
is missing) the step is still valid (steppernext
button is enabled). - There are some errors shown at the bottom. It feels like these should only be generic issues that are not associated with a specific field, else those errors should appear underneath the fields themselves. For example required field errors appear both beneath the field and in the list at the bottom. For a 'phone number' section a missing number is only shown in the list at the bottom, for example
should have required property 'last_name'
undefined.phone_numbers[0]: should have required property 'number'
- The error list at the bottom needs to be more material design like, though this is something we can look at after this PR has merged.
- The
SpecifyDetailsStep
throws the exception below. These are a real pain and basically indicate a child component is changing the state of a parent component. I captured some notes on it a while back https://github.com/cloudfoundry-incubator/stratos/blob/7180ced053e22ad1915c50543d739bf7928f69ac/docs/developers-guide-env-tech.md#expressionchangedafterithasbeencheckederror-error. If you'd like further help on this just let us know.
specify-details-step.component.html:27 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'mat-form-field-should-float: false'. Current value: 'mat-form-field-should-float: true'.
- There's a new class that's being applied to the
mat-form-field-infix
divs (see below) which breaks the width of fields in the list component (these are fixed width, but are ignored in favour of this new class). This might disappear when/if '@angular/flex-layout' goes?
mat-form-field .mat-form-field-wrapper .mat-form-field-flex .mat-form-field-infix {
width: initial;
}
Overall .. some things to work through but it's looking really good!
@@ -46,6 +46,7 @@ | |||
"@angular/common": "6.0.3", | |||
"@angular/compiler": "6.0.3", | |||
"@angular/core": "6.0.3", | |||
"@angular/flex-layout": "^6.0.0-beta.16", |
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.
It doesn't look like this is used within Stratos, however removing results in the following error
ERROR in ../../angular6-json-schema-form/angular6-json-schema-form.ts(38,53): Error during template compile of 'MaterialDesignFrameworkModule'
Could not resolve @angular/flex-layout relative to /home/richard/dev/github/stratos-ui-orange-cloudfoundry/node_modules/angular6-json-schema-form/angular6-json-schema-form.d.ts..
Should this be a dependency of angular6-json-schema-form
?
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.
Yes the material design module uses @angular/flex-layout. I'm open to better approachs
})); | ||
}; | ||
|
||
export const prettyValidationErrors = (formValidationErrors) => { |
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.
formValidationErrors needs a type, that would open up the easier formValidationErrors.forEach
iteration function. If you're feeling fancy you could even use formValidationErrors.reduce
instead, which would both iterate over formValidationErrors
and output the errorArray
<mat-card-content> | ||
<json-schema-form loadExternalAssets="true" [options]="jsonFormOptions" [schema]="schema" [framework]="selectedFramework" (validationErrors)="validationErrors($event)" (onChanges)="onFormChange($event)"> | ||
</json-schema-form> | ||
<div *ngIf="!!prettyValidationErrors" class="data-bad" [innerHTML]="prettyValidationErrors"></div> |
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.
For class names we use BEM notation (for an intro see http://getbem.com/introduction/). At the moment we have BEM checking turned off in our pipeline, but at some point in the future we'd like to turn it back on again.
@@ -35,6 +36,14 @@ export class BindAppsStepComponent implements OnDestroy, AfterContentInit { | |||
stepperForm: FormGroup; | |||
apps$: Observable<APIResource<IApp>[]>; | |||
guideText = 'Specify the application to bind (Optional)'; | |||
|
|||
selectedFramework = 'material-design'; | |||
schema: any; |
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.
If possible it would be nice to type the fields and function params in this class.
</form> | ||
<div *ngIf="!!schema" class="json-schema"> |
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.
There's a fair bit of duplication between this step and bind app (html, input, error handling, etc). Could the common parts be pulled out into a new component ServiceBindingForm
? This would remove a lot of duplicated html, plumming in the component's code and i think the possibly the need for the scss mixins
onEnter = () => { | ||
onEnter = (selectedService$?) => { | ||
if (selectedService$ instanceof Observable) { | ||
this.selectedServiceSubscription = selectedService$ |
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.
See above comment about using first()
or changing to this.schema$
observable
if (selectedService$ instanceof Observable) { | ||
this.selectedServiceSubscription = selectedService$ | ||
.subscribe(selectedService => { | ||
this.schema = this.filterSchema(selectedService.entity.entity.schemas.service_binding.create.parameters); |
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.
In the two places this is used need to check whether if schemas
has a value (currently gives undefined
exception for services without schemas`
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.
Full exception: Cannot read property 'service_binding' of undefined
<div *ngIf="!!schema" class="json-schema"> | ||
<mat-card class="json-schema-form"> | ||
<mat-card-header> | ||
<mat-card-title><b>Generated Form</b><button mat-button color="accent" (click)="showJsonSchema=!showJsonSchema">Json schema</button> |
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.
The button needs some padding-left, to ensure the 'on hover' button background has space between itself and text. Should also consider whether this button is something we should hide in production. @KlapTrap thoughts?
if (selectedService$ instanceof Observable) { | ||
this.selectedServiceSubscription = selectedService$ | ||
.subscribe(selectedService => { | ||
if (!!this.modeService.isEditServiceInstanceMode()) { |
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.
If we're in edit mode, should the update
section be used?
thanks @richard-cox and @KlapTrap for your review
Yes, this two way data binding would be quite nice UX. The related work can also for improve the update service instance/binding parameters by prepopulating the form with the params previously submitted by the user. These params values are provided by the new OSB 2.14 GET endpoints for fetching a Service Instance and Service Binding which is now exposed by CC API in the related service instance and service binding endpoints. Related stratos issue: #2121 @hamzahamidi started looking into this but could not yet complete this. This seems possible from
Initial study indicates that real-time two way binding might be hard to achieve. An alternative might be to offer users to either edit in plain text or form, possibly by switching tabs (see mock below that may still include a real-time read-only preview) I'll let him provide more details, confirm feasibility and required work.
The errors at the bottom are global validation errors that the library can't easily associate to a single particular field. Common example are violations to attribute dependencies, or missing attributes (i.e. for which associated form entry is not yet displayed, as they are optional). Display of these errors is necessary for users to understand schema constraints violations (as field-attached validation messages would be insufficient). |
Thanks for your input, I like the mock design, would love to see it in action. We don’t mind picking up we’re you left off if you don’t quite get it finished before you’re off, you’ve already saved us a lot of time! |
We had mixed feelings about systematically disabling the next button on validation violations (currently stratos allows params violating their schema), and rather imagined either a way to have users bypass validation violations if needed, through either:
|
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
Signed-off-by: Hamza Hamidi <hamza.hamidi@orange.com>
@gberche-orange Mocked functionality looks good. This might also help with the form validation + |
From a user perspective, it would be useful to also see validation messages when editing raw json, something like the mock below. Maybe the form could be updated and generate the validation message when focus is lost from the json text, and/or when an explicit refresh button is clicked.
Hamza is out of office (with limited connectivity to provide status on the last pushed commits) until next monday aug 27th, (he will be holding his internship dissertation defense on that week, so he'll have limited contribution capacity). |
Closing in favour of updated #3050 |
Description
ADD JSON schema form generator to service binding & instance


Motivation and Context
JSON Schema sent by the broker creator is used to generate forms which are used to generate the json parameters for the service binding & service instance.
This feature uses Angular 6 JSON Schema Form builder which generates forms from JSON schemas using Angular.
The library is compatible with version 4 of the JSON schema standard.
Types of changes
Checklist: