Skip to content
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

fix(Resources): onException should be created at the top #1585

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions packages/ui/src/models/camel/camel-route-resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { CamelComponentFilterService } from '../visualization/flows/support/came
import { BeansEntity } from '../visualization/metadata/beansEntity';
import { createCamelResource } from './camel-resource';
import { CamelRouteResource } from './camel-route-resource';
import { EntityType } from './entities';
import { SourceSchemaType } from './source-schema-type';

describe('CamelRouteResource', () => {
Expand Down Expand Up @@ -57,6 +58,33 @@ describe('CamelRouteResource', () => {
expect(resource.getVisualEntities()).toHaveLength(1);
expect(resource.getVisualEntities()[0].id).toEqual(id);
});

it('should add new entities at the end of the list and return its ID', () => {
const resource = new CamelRouteResource();
resource.addNewEntity();
const id = resource.addNewEntity(EntityType.Route);

expect(resource.getVisualEntities()).toHaveLength(2);
expect(resource.getVisualEntities()[1].id).toEqual(id);
});

it('should add OnException entity at the beginning of the list and return its ID', () => {
const resource = new CamelRouteResource();
resource.addNewEntity();
const id = resource.addNewEntity(EntityType.OnException);

expect(resource.getVisualEntities()).toHaveLength(2);
expect(resource.getVisualEntities()[0].id).toEqual(id);
});

it('should add ErrorHandler entity at the beginning of the list and return its ID', () => {
const resource = new CamelRouteResource();
resource.addNewEntity();
const id = resource.addNewEntity(EntityType.ErrorHandler);

expect(resource.getVisualEntities()).toHaveLength(2);
expect(resource.getVisualEntities()[0].id).toEqual(id);
});
});

it('should return the right type', () => {
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/src/models/camel/camel-route-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export class CamelRouteResource implements CamelResource, BeansAwareResource {
{ type: EntityType.RestConfiguration, group: 'Rest', Entity: CamelRestConfigurationVisualEntity },
];
static readonly PARAMETERS_ORDER = ['id', 'description', 'uri', 'parameters', 'steps'];
private static readonly ERROR_RELATED_ENTITIES = [EntityType.OnException, EntityType.ErrorHandler];
readonly sortFn = createCamelPropertiesSorter(CamelRouteResource.PARAMETERS_ORDER) as (
a: unknown,
b: unknown,
Expand Down Expand Up @@ -93,7 +94,13 @@ export class CamelRouteResource implements CamelResource, BeansAwareResource {
const supportedEntity = CamelRouteResource.SUPPORTED_ENTITIES.find(({ type }) => type === entityType);
if (supportedEntity) {
const entity = new supportedEntity.Entity();
this.entities.push(entity);

/** Error related entities should be added at the beginning of the list */
if (CamelRouteResource.ERROR_RELATED_ENTITIES.includes(entityType)) {
this.entities.unshift(entity);
} else {
this.entities.push(entity);
}
return entity.id;
}
}
Expand Down
Loading