Fix import VFC with attributes
Fix import VFC with default attribute value
Fix Update, create and delete attribute action
Make attribute definition tosca compliant
Issue-ID: SDC-3381
Signed-off-by: aribeiro <anderson.ribeiro@est.tech>
Change-Id: Ibbd36b105b8c86d1e750f3b6d55752d63fe6530e
diff --git a/catalog-ui/src/app/models/attributes.ts b/catalog-ui/src/app/models/attributes.ts
index 80af540..a51358c 100644
--- a/catalog-ui/src/app/models/attributes.ts
+++ b/catalog-ui/src/app/models/attributes.ts
@@ -41,13 +41,12 @@
//server data
uniqueId:string;
name:string;
- defaultValue:string;
+ _default:string;
description:string;
type:string;
schema:SchemaAttributeGroupModel;
status:string;
value:string;
- hidden:boolean;
parentUniqueId:string;
//custom data
resourceInstanceUniqueId:string;
@@ -60,13 +59,12 @@
//server data
uniqueId:string;
name:string;
- defaultValue:string;
+ _default:string;
description:string;
type:string;
schema:SchemaAttributeGroupModel;
status:string;
value:string;
- hidden:boolean;
parentUniqueId:string;
//custom data
resourceInstanceUniqueId:string;
@@ -77,20 +75,18 @@
if (attribute) {
this.uniqueId = attribute.uniqueId;
this.name = attribute.name;
- this.defaultValue = attribute.defaultValue;
+ this._default = attribute._default;
this.description = attribute.description;
this.type = attribute.type;
this.status = attribute.status;
this.schema = attribute.schema;
this.value = attribute.value;
- this.hidden = attribute.hidden;
this.parentUniqueId = attribute.parentUniqueId;
this.resourceInstanceUniqueId = attribute.resourceInstanceUniqueId;
this.readonly = attribute.readonly;
this.valueUniqueUid = attribute.valueUniqueUid;
} else {
- this.defaultValue = '';
- this.hidden = false;
+ this._default = '';
}
if (!this.schema || !this.schema.property) {
@@ -104,13 +100,13 @@
}
public convertToServerObject():string {
- if (this.defaultValue && this.type === 'map') {
- this.defaultValue = '{' + this.defaultValue + '}';
+ if (this._default && this.type === 'map') {
+ this._default = '{' + this._default + '}';
}
- if (this.defaultValue && this.type === 'list') {
- this.defaultValue = '[' + this.defaultValue + ']';
+ if (this._default && this.type === 'list') {
+ this._default = '[' + this._default + ']';
}
- this.defaultValue = this.defaultValue != "" && this.defaultValue != "[]" && this.defaultValue != "{}" ? this.defaultValue : null;
+ this._default = this._default != "" && this._default != "[]" && this._default != "{}" ? this._default : null;
return JSON.stringify(this);
};
@@ -118,10 +114,10 @@
public convertValueToView() {
//unwrapping value {} or [] if type is complex
- if (this.defaultValue && (this.type === 'map' || this.type === 'list') &&
- ['[', '{'].indexOf(this.defaultValue.charAt(0)) > -1 &&
- [']', '}'].indexOf(this.defaultValue.slice(-1)) > -1) {
- this.defaultValue = this.defaultValue.slice(1, -1);
+ if (this._default && (this.type === 'map' || this.type === 'list') &&
+ ['[', '{'].indexOf(this._default.charAt(0)) > -1 &&
+ [']', '}'].indexOf(this._default.slice(-1)) > -1) {
+ this._default = this._default.slice(1, -1);
}
//also for value - for the modal in canvas
diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html
index bd30a46..094045e 100644
--- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html
+++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.html
@@ -48,19 +48,19 @@
<!-- ATTRIBUTE DEFAULT VALUE TEXT - OPTIONAL -->
<div *ngIf="attributeToEdit.type != 'boolean'">
<sdc-input
- #defaultValue
+ #_default
[required]="false"
label="Default Value"
- [(value)]="attributeToEdit.defaultValue"
+ [(value)]="attributeToEdit._default"
[disabled]="false"
- name="defaultValue"
+ name="_default"
testId="defaultValue"
[maxLength]="255"
(valueChange)="defaultValueChanged()">
</sdc-input>
- <sdc-validation [validateElement]="defaultValue" (validityChanged)="onValidityChange($event, 'defaultValue')">
- <sdc-regex-validator *ngIf="this.attributeToEdit.defaultValue && this.attributeToEdit.defaultValue.length > 0" message="{{ this.defaultValueErrorMessage }}"
+ <sdc-validation [validateElement]="_default" (validityChanged)="onValidityChange($event, 'default')">
+ <sdc-regex-validator *ngIf="this.attributeToEdit._default && this.attributeToEdit._default.length > 0" message="{{ this.defaultValueErrorMessage }}"
[pattern]="defaultValuePattern"></sdc-regex-validator>
<sdc-custom-validator *ngIf="this.attributeToEdit.type == 'map' && this.attributeToEdit.schema.property.type" message="{{ 'PROPERTY_EDIT_MAP_UNIQUE_KEYS' | translate }}"
[callback]="isMapUnique" [disabled]="false"></sdc-custom-validator>
@@ -71,7 +71,7 @@
<div *ngIf="attributeToEdit.type == 'boolean'">
<sdc-dropdown [disabled]="false" label="Default Value"
[required]="false"
- [selectedOption]="toDropDownOption(this.attributeToEdit.defaultValue)" placeHolder="Choose Default Value"
+ [selectedOption]="toDropDownOption(this.attributeToEdit._default)" placeHolder="Choose Default Value"
[options]="booleanValues" (changed)="onBooleanDefaultValueSelected($event)">
</sdc-dropdown>
@@ -88,17 +88,7 @@
</sdc-validation>
</sdc-dropdown>
</div>
-
- <!-- ATTRIBUTE HIDDEN - OPTIONAL -->
- <sdc-checkbox
- label="Hidden"
- [checked]="attributeToEdit.hidden"
- [disabled]="false"
- testId="hidden"
- (checkedChange)="this.onHiddenCheckboxClicked($event)"
- >
- </sdc-checkbox>
</div>
</div>
-</form>
\ No newline at end of file
+</form>
diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts
index c703869..b0a7651 100644
--- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts
+++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attribute-modal.component.ts
@@ -15,7 +15,7 @@
})
export class AttributeModalComponent implements OnInit {
- @ViewChild('defaultValue') validatedInput: InputComponent;
+ @ViewChild('_default') validatedInput: InputComponent;
public readonly types = AttributeOptions.types; // integer, string, boolean etc.
@@ -44,13 +44,9 @@
this.revalidateDefaultValue();
}
- onHiddenCheckboxClicked(event: boolean) {
- this.attributeToEdit.hidden = event;
- }
-
onTypeSelected(selectedElement: IDropDownOption) {
if (this.attributeToEdit.type !== selectedElement.value && selectedElement.value === 'boolean') {
- this.attributeToEdit.defaultValue = ''; // Clean old value in case we choose change type to boolean
+ this.attributeToEdit._default = ''; // Clean old value in case we choose change type to boolean
}
this.attributeToEdit.type = selectedElement.value;
this.revalidateDefaultValue();
@@ -58,7 +54,7 @@
onBooleanDefaultValueSelected(selectedElement: IDropDownOption) {
if (this.attributeToEdit.type === 'boolean') {
- this.attributeToEdit.defaultValue = selectedElement.value;
+ this.attributeToEdit._default = selectedElement.value;
}
}
@@ -92,8 +88,8 @@
}
public isMapUnique = () => {
- if (this.attributeToEdit && this.attributeToEdit.type === 'map' && this.attributeToEdit.defaultValue) {
- return ValidationUtils.validateUniqueKeys(this.attributeToEdit.defaultValue);
+ if (this.attributeToEdit && this.attributeToEdit.type === 'map' && this.attributeToEdit._default) {
+ return ValidationUtils.validateUniqueKeys(this.attributeToEdit._default);
}
return true;
}
@@ -102,7 +98,7 @@
this.setDefaultValuePattern(this.attributeToEdit.type);
setTimeout(() => {
if (this.validatedInput) {
- this.validatedInput.onKeyPress(this.attributeToEdit.defaultValue);
+ this.validatedInput.onKeyPress(this.attributeToEdit._default);
} }, 250);
}
diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts
index 99aa140..2eed231 100644
--- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts
+++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes-modal.component.spec.ts
@@ -56,28 +56,18 @@
})
);
- it('test that when hidden is clicked, hidden attribute is set', async () => {
- fixture.componentInstance.attributeToEdit = new AttributeModel();
- const hidden = fixture.componentInstance.attributeToEdit.hidden;
- fixture.componentInstance.ngOnInit();
-
- expect(hidden).toBe(false);
- fixture.componentInstance.onHiddenCheckboxClicked(true);
- expect(fixture.componentInstance.attributeToEdit.hidden).toBe(true);
- });
-
it('test that when type is set to boolean default value is cleared', async () => {
const component = fixture.componentInstance;
component.attributeToEdit = new AttributeModel();
component.ngOnInit();
component.onTypeSelected({ value : 'string', label : 'string'});
- component.attributeToEdit.defaultValue = 'some_value';
+ component.attributeToEdit._default = 'some_value';
component.onTypeSelected({ value : 'boolean', label : 'boolean'});
- expect(component.attributeToEdit.defaultValue).toBe('');
+ expect(component.attributeToEdit._default).toBe('');
component.onBooleanDefaultValueSelected({ value : 'true', label : 'true'});
- expect(component.attributeToEdit.defaultValue).toBe('true');
+ expect(component.attributeToEdit._default).toBe('true');
});
it('test that when certain type is selected, the correct regex pattern is chosen', async () => {
@@ -120,9 +110,9 @@
expect(component.isMapUnique()).toBe(true); // map is not selected so return true by default
component.onTypeSelected({ value : 'map', label : 'map'});
component.onEntrySchemaTypeSelected({ value : 'boolean', label : 'boolean' });
- component.attributeToEdit.defaultValue = '"1":true,"2":false';
+ component.attributeToEdit._default = '"1":true,"2":false';
expect(component.isMapUnique()).toBe(true);
- component.attributeToEdit.defaultValue = '"1":true,"1":false';
+ component.attributeToEdit._default = '"1":true,"1":false';
expect(component.isMapUnique()).toBe(false);
});
});
diff --git a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html
index 00a7a5c..6d50bbe 100644
--- a/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html
+++ b/catalog-ui/src/app/ng2/pages/workspace/attributes/attributes.component.html
@@ -66,7 +66,7 @@
<ngx-datatable-column [resizeable]="false" name="Default Value" [flexGrow]="3">
<ng-template ngx-datatable-cell-template let-row="row">
- {{row.defaultValue}}
+ {{row._default}}
</ng-template>
</ngx-datatable-column>
@@ -90,4 +90,4 @@
</ngx-datatable-column>
</ngx-datatable>
-</div>
\ No newline at end of file
+</div>