Skip to content

Commit

Permalink
feat(RouteConfiguration): Add support for RouteConfiguration entity
Browse files Browse the repository at this point in the history
This commit adds support for RouteConfiguration entity.

fix: #492

Temp: Remove constructor parameter type from AbstractCamelVisualEntity

Temp: Make OnException inherit from AbstractCamelVisualEntity

Temp: Restore getArray util function

Temp: Remove duplicated methods in OnException

Temp: Remove duplicated methods in CamelRouteConfiguration

Temp: Refactor getNodeLabel

Temp: Rework errorHandler node label

Temp: Remove more duplicated methods in OnException

Temp: Add intercept, interceptFrom, interceptSendToEndpoint and onCompletion
  • Loading branch information
lordrip committed Apr 16, 2024
1 parent 981c994 commit af38c37
Show file tree
Hide file tree
Showing 19 changed files with 845 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {
Layer,
isNode,
observer,
withSelection,
withContextMenu,
withSelection,
} from '@patternfly/react-topology';
import { FunctionComponent } from 'react';
import { AddStepMode } from '../../../models/visualization/base-visual-entity';
import { CanvasNode } from '../Canvas/canvas.models';
import { ItemInsertChildNode } from './ItemInsertChildNode';
import { ItemRemoveGroup } from './ItemRemoveGroup';

type IDefaultGroup = Parameters<typeof DefaultGroup>[0];
Expand Down Expand Up @@ -44,5 +46,10 @@ const CustomGroup: FunctionComponent<ICustomGroup> = observer(({ element, ...res
});

export const CustomGroupWithSelection = withContextMenu(() => [
<ItemInsertChildNode
key="context-menu-item-insert-special"
data-testid="context-menu-item-insert-special"
mode={AddStepMode.InsertSpecialChildStep}
/>,
<ItemRemoveGroup key="context-menu-container-remove" data-testid="context-menu-container-remove" />,
])(withSelection()(CustomGroup));
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { ItemAddNode } from './ItemAddNode';
import { ItemInsertChildNode } from './ItemInsertChildNode';
import { ItemRemoveNode } from './ItemRemoveNode';
import { ItemReplaceNode } from './ItemReplaceNode';
import { ItemRemoveGroup } from './ItemRemoveGroup';

interface CustomNodeProps extends WithSelectionProps {
element: Node<CanvasNode, CanvasNode['data']>;
Expand Down Expand Up @@ -78,4 +79,5 @@ export const CustomNodeWithSelection: typeof DefaultNode = withContextMenu(() =>
/>,
<ItemReplaceNode key="context-menu-item-replace" data-testid="context-menu-item-replace" />,
<ItemRemoveNode key="context-menu-item-remove" data-testid="context-menu-item-remove" />,
<ItemRemoveGroup key="context-menu-container-remove" data-testid="context-menu-container-remove" />,
])(withSelection()(CustomNode) as typeof DefaultNode) as typeof DefaultNode;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TrashIcon } from '@patternfly/react-icons';
import { ContextMenuItem, ElementContext, ElementModel, GraphElement } from '@patternfly/react-topology';
import { FunctionComponent, useCallback, useContext } from 'react';
import { FunctionComponent, useCallback, useContext, useMemo } from 'react';
import { IDataTestID } from '../../../models';
import { EntitiesContext } from '../../../providers/entities.provider';
import { CanvasNode } from '../Canvas/canvas.models';
Expand All @@ -10,15 +10,20 @@ export const ItemRemoveGroup: FunctionComponent<IDataTestID> = (props) => {
const element: GraphElement<ElementModel, CanvasNode['data']> = useContext(ElementContext);
const vizNode = element.getData()?.vizNode;
const flowId = vizNode?.getBaseEntity()?.getId();
const shouldRender = useMemo(() => {
const nodeInteractions = vizNode?.getNodeInteraction() ?? { canRemoveFlow: false };

return nodeInteractions.canRemoveFlow;
}, [vizNode]);

const onRemoveGroup = useCallback(() => {
entitiesContext?.camelResource.removeEntity(flowId);
entitiesContext?.updateEntitiesFromCamelResource();
}, [entitiesContext]);
}, [entitiesContext, flowId]);

return (
return shouldRender ? (
<ContextMenuItem onClick={onRemoveGroup} data-testid={props['data-testid']}>
<TrashIcon /> Delete
</ContextMenuItem>
);
) : null;
};
10 changes: 10 additions & 0 deletions packages/ui/src/models/camel/camel-route-resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import { createCamelPropertiesSorter, isDefined } from '../../utils';
import { AddStepMode } from '../visualization/base-visual-entity';
import { CamelRouteVisualEntity, isCamelFrom, isCamelRoute } from '../visualization/flows';
import { CamelErrorHandlerVisualEntity } from '../visualization/flows/camel-error-handler-visual-entity';
import { CamelInterceptFromVisualEntity } from '../visualization/flows/camel-intercept-from-visual-entity';
import { CamelInterceptSendToEndpointVisualEntity } from '../visualization/flows/camel-intercept-send-to-endpoint-visual-entity';
import { CamelInterceptVisualEntity } from '../visualization/flows/camel-intercept-visual-entity';
import { CamelOnCompletionVisualEntity } from '../visualization/flows/camel-on-completion-visual-entity';
import { CamelOnExceptionVisualEntity } from '../visualization/flows/camel-on-exception-visual-entity';
import { CamelRestConfigurationVisualEntity } from '../visualization/flows/camel-rest-configuration-visual-entity';
import { CamelRouteConfigurationVisualEntity } from '../visualization/flows/camel-route-configuration-visual-entity';
import { NonVisualEntity } from '../visualization/flows/non-visual-entity';
import { CamelComponentFilterService } from '../visualization/flows/support/camel-component-filter.service';
import { CamelRouteVisualEntityData } from '../visualization/flows/support/camel-component-types';
Expand All @@ -18,8 +23,13 @@ import { SourceSchemaType } from './source-schema-type';
export class CamelRouteResource implements CamelResource, BeansAwareResource {
static readonly SUPPORTED_ENTITIES = [
CamelOnExceptionVisualEntity,
CamelOnCompletionVisualEntity,
CamelErrorHandlerVisualEntity,
CamelRestConfigurationVisualEntity,
CamelRouteConfigurationVisualEntity,
CamelInterceptVisualEntity,
CamelInterceptFromVisualEntity,
CamelInterceptSendToEndpointVisualEntity,
] as const;
static readonly PARAMETERS_ORDER = ['id', 'description', 'uri', 'parameters', 'steps'];
readonly sortFn = createCamelPropertiesSorter(CamelRouteResource.PARAMETERS_ORDER) as (
Expand Down
1 change: 1 addition & 0 deletions packages/ui/src/models/visualization/base-visual-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ export interface NodeInteraction {
canHaveSpecialChildren: boolean;
canReplaceStep: boolean;
canRemoveStep: boolean;
canRemoveFlow: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable no-case-declarations */
import { ProcessorDefinition, RouteDefinition } from '@kaoto-next/camel-catalog/types';
import { ProcessorDefinition } from '@kaoto-next/camel-catalog/types';
import { SchemaService } from '../../../components/Form/schema.service';
import { ROOT_PATH, getArrayProperty, getValue, isDefined, setValue } from '../../../utils';
import { ROOT_PATH, getArrayProperty, getValue, setValue } from '../../../utils';
import { NodeIconResolver } from '../../../utils/node-icon-resolver';
import { DefinedComponent } from '../../camel-catalog-index';
import { EntityType } from '../../camel/entities';
Expand All @@ -20,12 +20,13 @@ import { CamelProcessorStepsProperties, CamelRouteVisualEntityData } from './sup
import { CamelStepsService } from './support/camel-steps.service';
import { ModelValidationService } from './support/validators/model-validation.service';

export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity {
constructor(public route: RouteDefinition) {}
export abstract class AbstractCamelVisualEntity<T extends object> implements BaseVisualCamelEntity {
constructor(public route: T) {}

abstract id: string;
abstract type: EntityType;
abstract setId(id: string): void;
abstract toJSON(): unknown;
protected abstract getRootUri(): string | undefined;

getId(): string {
Expand Down Expand Up @@ -68,17 +69,11 @@ export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity
return SchemaService.OMIT_FORM_FIELDS;
}

toJSON() {
return { route: this.route };
}

updateModel(path: string | undefined, value: unknown): void {
if (!path) return;
const updatedValue = CamelComponentSchemaService.getUriSerializedDefinition(path, value);

setValue(this.route, path, updatedValue);

if (isDefined(this.route.id)) this.id = this.route.id;
}

/**
Expand Down Expand Up @@ -106,12 +101,7 @@ export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity
(options.data as CamelRouteVisualEntityData).processorName as keyof ProcessorDefinition,
);

/** Replace the root `from` step */
if (options.mode === AddStepMode.ReplaceStep && options.data.path === 'from' && isDefined(this.route.from)) {
const fromValue = CamelComponentDefaultService.getDefaultFromDefinitionValue(options.definedComponent);
Object.assign(this.route.from, fromValue);
return;
} else if (options.mode === AddStepMode.InsertChildStep || options.mode === AddStepMode.InsertSpecialChildStep) {
if (options.mode === AddStepMode.InsertChildStep || options.mode === AddStepMode.InsertSpecialChildStep) {
this.insertChildStep(options, stepsProperties, defaultValue);
return;
}
Expand Down Expand Up @@ -144,15 +134,6 @@ export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity

removeStep(path?: string): void {
if (!path) return;
/**
* If there's only one path segment, it means the target is the `from` property of the route
* therefore we replace it with an empty object
*/
if (path === 'from') {
setValue(this.route, 'from.uri', '');
return;
}

const pathArray = path.split('.');
const last = pathArray[pathArray.length - 1];
const penultimate = pathArray[pathArray.length - 2];
Expand Down Expand Up @@ -207,6 +188,9 @@ export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity
const canHavePreviousStep = CamelComponentSchemaService.canHavePreviousStep(
(data as CamelRouteVisualEntityData).processorName,
);
const canReplaceStep = CamelComponentSchemaService.canReplaceStep(
(data as CamelRouteVisualEntityData).processorName,
);
const canHaveChildren = stepsProperties.find((property) => property.type === 'branch') !== undefined;
const canHaveSpecialChildren = Object.keys(stepsProperties).length > 1;

Expand All @@ -215,8 +199,9 @@ export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity
canHaveNextStep: canHavePreviousStep,
canHaveChildren,
canHaveSpecialChildren,
canReplaceStep: true,
canReplaceStep,
canRemoveStep: true,
canRemoveFlow: data.path === ROOT_PATH,
};
}

Expand Down Expand Up @@ -253,7 +238,7 @@ export abstract class AbstractCamelVisualEntity implements BaseVisualCamelEntity
}

private insertChildStep(
options: Parameters<AbstractCamelVisualEntity['addStep']>[0],
options: Parameters<AbstractCamelVisualEntity<object>['addStep']>[0],
stepsProperties: CamelProcessorStepsProperties[],
defaultValue: ProcessorDefinition = {},
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ErrorHandler, NoErrorHandler } from '@kaoto-next/camel-catalog/types';
import { ErrorHandlerBuilderDeserializer, NoErrorHandler } from '@kaoto-next/camel-catalog/types';
import { useSchemasStore } from '../../../store';
import { errorHandlerSchema } from '../../../stubs/error-handler';
import { CamelErrorHandlerVisualEntity } from './camel-error-handler-visual-entity';
import { EntityType } from '../../camel/entities';
import { CamelErrorHandlerVisualEntity } from './camel-error-handler-visual-entity';

describe('CamelErrorHandlerVisualEntity', () => {
const ERROR_HANDLER_ID_REGEXP = /^errorHandler-[a-zA-Z0-9]{4}$/;
let errorHandlerDef: { errorHandler: ErrorHandler };
let errorHandlerDef: { errorHandler: ErrorHandlerBuilderDeserializer };

beforeAll(() => {
useSchemasStore.getState().setSchema('errorHandler', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ErrorHandler, ProcessorDefinition } from '@kaoto-next/camel-catalog/types';
import { ErrorHandlerBuilderDeserializer, ProcessorDefinition } from '@kaoto-next/camel-catalog/types';
import { getCamelRandomId } from '../../../camel-utils/camel-random-id';
import { SchemaService } from '../../../components/Form/schema.service';
import { useSchemasStore } from '../../../store';
import { isDefined, setValue } from '../../../utils';
import { getValue, isDefined, setValue } from '../../../utils';
import { EntityType } from '../../camel/entities/base-entity';
import {
BaseVisualCamelEntity,
Expand All @@ -17,12 +17,12 @@ export class CamelErrorHandlerVisualEntity implements BaseVisualCamelEntity {
id: string;
readonly type = EntityType.ErrorHandler;

constructor(public errorHandlerDef: { errorHandler: ErrorHandler }) {
constructor(public errorHandlerDef: { errorHandler: ErrorHandlerBuilderDeserializer }) {
const id = getCamelRandomId('errorHandler');
this.id = id;
}

static isApplicable(errorHandlerDef: unknown): errorHandlerDef is { errorHandler: ErrorHandler } {
static isApplicable(errorHandlerDef: unknown): errorHandlerDef is { errorHandler: ErrorHandlerBuilderDeserializer } {
if (!isDefined(errorHandlerDef) || Array.isArray(errorHandlerDef) || typeof errorHandlerDef !== 'object') {
return false;
}
Expand All @@ -43,7 +43,32 @@ export class CamelErrorHandlerVisualEntity implements BaseVisualCamelEntity {
}

getNodeLabel(): string {
return 'errorHandler';
const deadLetterChannelId: string | undefined = getValue(this.errorHandlerDef.errorHandler, 'deadLetterChannel.id');
const defaultErrorHandlerId: string | undefined = getValue(
this.errorHandlerDef.errorHandler,
'defaultErrorHandler.id',
);
const jtaTransactionErrorHandlerId: string | undefined = getValue(
this.errorHandlerDef.errorHandler,
'jtaTransactionErrorHandler.id',
);
const noErrorHandlerId: string | undefined = getValue(this.errorHandlerDef.errorHandler, 'noErrorHandler.id');
const refErrorHandlerId: string | undefined = getValue(this.errorHandlerDef.errorHandler, 'refErrorHandler.id');
const springTransactionErrorHandlerId: string | undefined = getValue(
this.errorHandlerDef.errorHandler,
'springTransactionErrorHandler.id',
);

let errorHandlerId =
deadLetterChannelId ??
defaultErrorHandlerId ??
jtaTransactionErrorHandlerId ??
noErrorHandlerId ??
refErrorHandlerId ??
springTransactionErrorHandlerId;

if (!errorHandlerId?.trim()) errorHandlerId = 'errorHandler';
return errorHandlerId;
}

getTooltipContent(): string {
Expand Down Expand Up @@ -90,6 +115,7 @@ export class CamelErrorHandlerVisualEntity implements BaseVisualCamelEntity {
canHaveSpecialChildren: false,
canRemoveStep: false,
canReplaceStep: false,
canRemoveFlow: true,
};
}

Expand All @@ -109,7 +135,7 @@ export class CamelErrorHandlerVisualEntity implements BaseVisualCamelEntity {
return errorHandlerGroupNode;
}

toJSON(): unknown {
return this.errorHandlerDef;
toJSON(): { errorHandler: ErrorHandlerBuilderDeserializer } {
return { errorHandler: this.errorHandlerDef.errorHandler };
}
}
Loading

0 comments on commit af38c37

Please sign in to comment.