diff --git a/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.html b/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.html index 69ce071..3af99b0 100644 --- a/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.html +++ b/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.html @@ -8,18 +8,24 @@ } -
+
@for (field of fields(); track field.property) { - @let fieldProperty = sanitizePropertyName(field.property); -
+ @let fieldProperty = sanitizePropertyName(field); +
{{ - field.label - }} + >{{ field.label }} @if (field.values?.length) { @for (value of [''].concat(field.values ?? []); track value) { {{ value }} + [valueState]="getValueState(fieldProperty)" + /> } @else { @if (form.controls[fieldProperty].errors?.k8sNameInvalid) { } diff --git a/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.spec.ts b/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.spec.ts index 2ba739c..19a314a 100644 --- a/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.spec.ts +++ b/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.spec.ts @@ -189,20 +189,29 @@ describe('CreateResourceModalComponent', () => { describe('sanitizePropertyName', () => { it('should replace dots with underscores in property name', () => { - const property = 'metadata.name.firstName'; - const result = (component as any).sanitizePropertyName(property); + const field = { property: 'metadata.name.firstName' }; + const result = (component as any).sanitizePropertyName(field); expect(result).toBe('metadata_name_firstName'); }); + it('should take propertyField key into account', () => { + const field = { + property: 'metadata.name.firstName', + propertyField: { key: 'secret' }, + }; + const result = (component as any).sanitizePropertyName(field); + expect(result).toBe('metadata_name_firstName_secret'); + }); + it('should handle property names without dots', () => { - const property = 'name'; - const result = (component as any).sanitizePropertyName(property); + const field = { property: 'name' }; + const result = (component as any).sanitizePropertyName(field); expect(result).toBe('name'); }); it('should throw error when property is an array', () => { - const property = ['name', 'firstName']; - expect(() => (component as any).sanitizePropertyName(property)).toThrow( + const field = { property: ['name', 'firstName'] }; + expect(() => (component as any).sanitizePropertyName(field)).toThrow( 'Wrong property type, array not supported', ); }); diff --git a/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.ts b/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.ts index 7edd86f..784262a 100644 --- a/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.ts +++ b/projects/wc/src/app/components/generic-ui/list-view/create-resource-modal/create-resource-modal.component.ts @@ -23,7 +23,7 @@ import { } from '@angular/forms'; import { FieldDefinition, Resource } from '@platform-mesh/portal-ui-lib/models'; import { ResourceNodeContext } from '@platform-mesh/portal-ui-lib/services'; -import { getValueByPath } from '@platform-mesh/portal-ui-lib/utils'; +import { getResourceValueByJsonPath } from '@platform-mesh/portal-ui-lib/utils'; import { BarComponent, DialogComponent, @@ -125,11 +125,16 @@ export class CreateResourceModalComponent implements OnInit { this.form.controls[formControlName].markAsTouched(); } - sanitizePropertyName(property: string | string[]) { + sanitizePropertyName(field: FieldDefinition) { + const property: string | string[] = field.property; if (property instanceof Array) { throw new Error('Wrong property type, array not supported'); } - return (property as string).replaceAll('.', '_'); + + return ( + (property as string).replaceAll('.', '_') + + (field.propertyField ? `_${field.propertyField?.key}` : '') + ); } isEditMode() { @@ -148,10 +153,10 @@ export class CreateResourceModalComponent implements OnInit { return this.fields().reduce( (obj, fieldDefinition) => { const validators = this.getValidator(fieldDefinition); - const fieldName = this.sanitizePropertyName(fieldDefinition.property); + const fieldName = this.sanitizePropertyName(fieldDefinition); const fieldValue = resource && typeof fieldDefinition.property === 'string' - ? getValueByPath(resource, fieldDefinition.property) + ? getResourceValueByJsonPath(resource, fieldDefinition) : ''; obj[fieldName] = new FormControl(fieldValue, validators);