From 5c0ff30f9166c5f4e67862424276dd45e78fcb5f Mon Sep 17 00:00:00 2001 From: Shivam Gupta Date: Wed, 20 Mar 2024 19:21:11 +0530 Subject: [PATCH] fix(code): Code cleaning in kamelet-visual-entity.ts --- .../ui/src/models/camel/kamelet-resource.ts | 10 +++++----- .../flows/kamelet-visual-entity.test.ts | 20 +++++++++---------- .../flows/kamelet-visual-entity.ts | 15 ++++++-------- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/packages/ui/src/models/camel/kamelet-resource.ts b/packages/ui/src/models/camel/kamelet-resource.ts index 4e0db2881..b2eee4f5c 100644 --- a/packages/ui/src/models/camel/kamelet-resource.ts +++ b/packages/ui/src/models/camel/kamelet-resource.ts @@ -26,8 +26,8 @@ export class KameletResource extends CamelKResource implements RouteTemplateBean } this.flow = new KameletVisualEntity(this.resource as IKameletDefinition); - if (this.flow.spec.template.beans) { - this.beans = new RouteTemplateBeansEntity(this.flow.spec.template as RouteTemplateBeansParentType); + if (this.flow.kamelet.spec.template.beans) { + this.beans = new RouteTemplateBeansEntity(this.flow.kamelet.spec.template as RouteTemplateBeansParentType); } } @@ -82,13 +82,13 @@ export class KameletResource extends CamelKResource implements RouteTemplateBean } createRouteTemplateBeansEntity(): RouteTemplateBeansEntity { - this.flow.spec.template.beans = []; - this.beans = new RouteTemplateBeansEntity(this.flow.spec.template as RouteTemplateBeansParentType); + this.flow.kamelet.spec.template.beans = []; + this.beans = new RouteTemplateBeansEntity(this.flow.kamelet.spec.template as RouteTemplateBeansParentType); return this.beans; } deleteRouteTemplateBeansEntity(): void { - this.flow.spec.template.beans = undefined; + this.flow.kamelet.spec.template.beans = undefined; this.beans = undefined; } } diff --git a/packages/ui/src/models/visualization/flows/kamelet-visual-entity.test.ts b/packages/ui/src/models/visualization/flows/kamelet-visual-entity.test.ts index 3f8c5f4f8..01fef9772 100644 --- a/packages/ui/src/models/visualization/flows/kamelet-visual-entity.test.ts +++ b/packages/ui/src/models/visualization/flows/kamelet-visual-entity.test.ts @@ -63,23 +63,23 @@ describe('KameletVisualEntity', () => { }); it('should set the id to the name if provided', () => { - const kamelet = new KameletVisualEntity(kameletDef); - expect(kamelet.id).toEqual('My Kamelet'); - expect(kamelet.metadata.name).toEqual('My Kamelet'); + const kameletVisualEntity = new KameletVisualEntity(kameletDef); + expect(kameletVisualEntity.id).toEqual('My Kamelet'); + expect(kameletVisualEntity.kamelet.metadata.name).toEqual('My Kamelet'); }); it('should set a random id if the kamelet name is not provided', () => { kameletDef.metadata.name = undefined as unknown as IKameletMetadata['name']; - const kamelet = new KameletVisualEntity(kameletDef); - expect(kamelet.id).toEqual('kamelet-1234'); - expect(kamelet.metadata.name).toEqual('kamelet-1234'); + const kameletVisualEntity = new KameletVisualEntity(kameletDef); + expect(kameletVisualEntity.id).toEqual('kamelet-1234'); + expect(kameletVisualEntity.kamelet.metadata.name).toEqual('kamelet-1234'); }); it('should set the id', () => { - const kamelet = new KameletVisualEntity(kameletDef); - kamelet.setId('new-id'); - expect(kamelet.id).toEqual('new-id'); - expect(kamelet.metadata.name).toEqual('new-id'); + const kameletVisualEntity = new KameletVisualEntity(kameletDef); + kameletVisualEntity.setId('new-id'); + expect(kameletVisualEntity.id).toEqual('new-id'); + expect(kameletVisualEntity.kamelet.metadata.name).toEqual('new-id'); }); describe('getComponentSchema when querying the ROOT_PATH', () => { diff --git a/packages/ui/src/models/visualization/flows/kamelet-visual-entity.ts b/packages/ui/src/models/visualization/flows/kamelet-visual-entity.ts index 26367d776..52501d025 100644 --- a/packages/ui/src/models/visualization/flows/kamelet-visual-entity.ts +++ b/packages/ui/src/models/visualization/flows/kamelet-visual-entity.ts @@ -2,7 +2,7 @@ import { getCamelRandomId } from '../../../camel-utils/camel-random-id'; import { ROOT_PATH, getCustomSchemaFromKamelet, updateKameletFromCustomSchema } from '../../../utils'; import { EntityType } from '../../camel/entities'; import { CatalogKind } from '../../catalog-kind'; -import { IKameletDefinition, IKameletMetadata, IKameletSpec } from '../../kamelets-catalog'; +import { IKameletDefinition } from '../../kamelets-catalog'; import { KaotoSchemaDefinition } from '../../kaoto-schema'; import { VisualComponentSchema } from '../base-visual-entity'; import { AbstractCamelVisualEntity } from './abstract-camel-visual-entity'; @@ -11,25 +11,22 @@ import { CamelCatalogService } from './camel-catalog.service'; export class KameletVisualEntity extends AbstractCamelVisualEntity { id: string; readonly type = EntityType.Kamelet; - spec: IKameletSpec; - metadata: IKameletMetadata; constructor(public kamelet: IKameletDefinition) { super({ id: kamelet.metadata?.name, from: kamelet?.spec.template.from }); this.id = (kamelet?.metadata?.name as string) ?? getCamelRandomId('kamelet'); - this.metadata = kamelet?.metadata ?? { name: this.id }; - this.metadata.name = kamelet?.metadata.name ?? this.id; - this.spec = kamelet.spec; + this.kamelet.metadata = kamelet?.metadata ?? { name: this.id }; + this.kamelet.metadata.name = kamelet?.metadata.name ?? this.id; } /** Internal API methods */ setId(routeId: string): void { this.id = routeId; - this.metadata.name = this.id; + this.kamelet.metadata.name = this.id; } getId(): string { - return this.metadata.name; + return this.kamelet.metadata.name; } getComponentSchema(path?: string | undefined): VisualComponentSchema | undefined { @@ -67,6 +64,6 @@ export class KameletVisualEntity extends AbstractCamelVisualEntity { } protected getRootUri(): string | undefined { - return this.spec.template.from?.uri; + return this.kamelet.spec.template.from?.uri; } }