Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Fix bug where actions are not passed to components
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Foo <foos@vmware.com>
  • Loading branch information
Sam Foo committed May 26, 2021
1 parent 46527c5 commit 642de0a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/2458-GuessWhoSamFoo
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed bug where actions were not passed to components
39 changes: 39 additions & 0 deletions web/src/app/modules/shared/models/form-helper.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { FormHelper } from './form-helper';

describe('FormHelper', () => {
let formHelper: FormHelper;

beforeEach(() => {
formHelper = new FormHelper();
});

it('converts number', () => {
expect(
formHelper.transformValue({
configuration: null,
value: 3,
name: '',
type: 'number',
error: null,
label: null,
placeholder: null,
validators: null,
})
).toEqual(3);
});

it('converts text', () => {
expect(
formHelper.transformValue({
configuration: null,
value: 'hello',
name: '',
type: 'text',
error: null,
label: null,
placeholder: null,
validators: null,
})
).toEqual('hello');
});
});
8 changes: 6 additions & 2 deletions web/src/app/modules/shared/models/form-helper.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {
FormArray,
FormBuilder,
FormControl,
FormGroup,
ValidatorFn,
Validators,
} from '@angular/forms';
import { ActionField, ActionForm } from './content';

export interface Choice {
label: string;
Expand All @@ -26,7 +29,7 @@ const validationNeedParams = {

// Class responsible to create a Form Group and add Validations Functions to form control
export class FormHelper {
createFromGroup(form, formBuilder) {
createFromGroup(form: ActionForm, formBuilder: FormBuilder): FormGroup {
if (!form) {
return;
}
Expand All @@ -52,14 +55,15 @@ export class FormHelper {
return formBuilder.group(controls);
}

transformValue(field): any {
transformValue(field: ActionField): any {
if (field.type === 'number') {
if (field.value === '') {
return null;
}
const value = +field.value;
return Number.isNaN(value) ? 0 : value;
}
return field.value;
}

// Receive a hash with the validation name and the expected
Expand Down

0 comments on commit 642de0a

Please sign in to comment.