-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, EIPs with children are rendered as containers, as opposed to in the past, where they were rendered as nodes. The goal for this ticket is to be able to customize how each EIP is rendered. This is an intermediate step between having a single class holding the entire route vs having individual classes per EIP, each holding the underlying code section they represent. fix: #1329
- Loading branch information
Showing
28 changed files
with
593 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
packages/ui/src/models/visualization/flows/nodes/mappers/base-node-mapper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { DoCatch, ProcessorDefinition, When1 } from '@kaoto/camel-catalog/types'; | ||
import { getValue } from '../../../../../utils'; | ||
import { NodeIconResolver, NodeIconType } from '../../../../../utils/node-icon-resolver'; | ||
import { IVisualizationNode } from '../../../base-visual-entity'; | ||
import { createVisualizationNode } from '../../../visualization-node'; | ||
import { CamelComponentSchemaService } from '../../support/camel-component-schema.service'; | ||
import { | ||
CamelProcessorStepsProperties, | ||
CamelRouteVisualEntityData, | ||
ICamelElementLookupResult, | ||
} from '../../support/camel-component-types'; | ||
import { INodeMapper } from '../node-mapper'; | ||
|
||
export class BaseNodeMapper implements INodeMapper { | ||
constructor(private readonly rootNodeMapper: INodeMapper) {} | ||
|
||
getVizNodeFromProcessor( | ||
path: string, | ||
componentLookup: ICamelElementLookupResult, | ||
entityDefinition: unknown, | ||
): IVisualizationNode { | ||
const nodeIconType = componentLookup.componentName ? NodeIconType.Component : NodeIconType.EIP; | ||
const data: CamelRouteVisualEntityData = { | ||
path, | ||
icon: NodeIconResolver.getIcon(CamelComponentSchemaService.getIconName(componentLookup), nodeIconType), | ||
processorName: componentLookup.processorName, | ||
componentName: componentLookup.componentName, | ||
}; | ||
|
||
const vizNode = createVisualizationNode(componentLookup.componentName ?? componentLookup.processorName, data); | ||
|
||
const childrenStepsProperties = CamelComponentSchemaService.getProcessorStepsProperties( | ||
componentLookup.processorName, | ||
); | ||
|
||
if (childrenStepsProperties.length > 0) { | ||
vizNode.data.isGroup = true; | ||
} | ||
|
||
childrenStepsProperties.forEach((stepsProperty) => { | ||
const childrenVizNodes = this.getVizNodesFromChildren(path, stepsProperty, entityDefinition); | ||
|
||
childrenVizNodes.forEach((childVizNode) => { | ||
vizNode.addChild(childVizNode); | ||
}); | ||
}); | ||
|
||
return vizNode; | ||
} | ||
|
||
protected getVizNodesFromChildren( | ||
path: string, | ||
stepsProperty: CamelProcessorStepsProperties, | ||
entityDefinition: unknown, | ||
): IVisualizationNode[] { | ||
const subpath = `${path}.${stepsProperty.name}`; | ||
|
||
switch (stepsProperty.type) { | ||
case 'branch': | ||
return this.getChildrenFromBranch(subpath, entityDefinition); | ||
|
||
case 'single-clause': | ||
return this.getChildrenFromSingleClause(subpath, entityDefinition); | ||
|
||
case 'array-clause': | ||
return this.getChildrenFromArrayClause(subpath, entityDefinition); | ||
|
||
default: | ||
return []; | ||
} | ||
} | ||
|
||
protected getChildrenFromBranch(path: string, entityDefinition: unknown): IVisualizationNode[] { | ||
const stepsList = getValue(entityDefinition, path, []) as ProcessorDefinition[]; | ||
|
||
return stepsList.reduce((accStepsNodes, step, index) => { | ||
const singlePropertyName = Object.keys(step)[0]; | ||
const childPath = `${path}.${index}.${singlePropertyName}`; | ||
const childComponentLookup = CamelComponentSchemaService.getCamelComponentLookup( | ||
childPath, | ||
getValue(step, singlePropertyName), | ||
); | ||
|
||
const vizNode = this.rootNodeMapper.getVizNodeFromProcessor(childPath, childComponentLookup, entityDefinition); | ||
|
||
const previousVizNode = accStepsNodes[accStepsNodes.length - 1]; | ||
if (previousVizNode !== undefined) { | ||
previousVizNode.setNextNode(vizNode); | ||
vizNode.setPreviousNode(previousVizNode); | ||
} | ||
|
||
accStepsNodes.push(vizNode); | ||
return accStepsNodes; | ||
}, [] as IVisualizationNode[]); | ||
} | ||
|
||
protected getChildrenFromSingleClause(path: string, entityDefinition: unknown): IVisualizationNode[] { | ||
const childComponentLookup = CamelComponentSchemaService.getCamelComponentLookup(path, entityDefinition); | ||
|
||
/** If the single-clause property is not defined, we don't create a IVisualizationNode for it */ | ||
if (getValue(entityDefinition, path) === undefined) return []; | ||
|
||
return [this.rootNodeMapper.getVizNodeFromProcessor(path, childComponentLookup, entityDefinition)]; | ||
} | ||
|
||
protected getChildrenFromArrayClause(path: string, entityDefinition: unknown): IVisualizationNode[] { | ||
const expressionList = getValue(entityDefinition, path, []) as When1[] | DoCatch[]; | ||
|
||
return expressionList.map((_step, index) => { | ||
const childPath = `${path}.${index}`; | ||
const processorName = path.split('.').pop() as keyof ProcessorDefinition; | ||
const childComponentLookup = { processorName }; // when, doCatch | ||
|
||
return this.rootNodeMapper.getVizNodeFromProcessor(childPath, childComponentLookup, entityDefinition); | ||
}); | ||
} | ||
} |
Oops, something went wrong.