Skip to content

Commit

Permalink
Topology creates edge between consumer-producer
Browse files Browse the repository at this point in the history
  • Loading branch information
mgubaidullin committed Oct 21, 2023
1 parent 0a76a4d commit 6078a23
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,16 @@ function getIcon(data: any) {
const CustomNode: React.FC<any> = observer(({ element, ...rest }) => {

const data = element.getData();
const badge:string = data.badge?.substring(0,1).toUpperCase();

return (
<DefaultNode
badge={badge}
showStatusDecorator
className="common-node"
element={element} {...rest}
scaleLabel={false}
element={element}
{...rest}
>
{getIcon(data)}
</DefaultNode>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import {
TopologyRestNode,
TopologyRouteNode
} from "karavan-core/lib/model/TopologyDefinition";
import CustomGroup from "./CustomGroup";
import CustomEdge from "./CustomEdge";
import {IntegrationFile} from "./TopologyStore";
import CustomGroup from "./CustomGroup";

const NODE_DIAMETER = 60;

Expand All @@ -62,7 +62,7 @@ export function getIncomingNodes(tins: TopologyIncomingNode[]): NodeModel[] {
status: NodeStatus.default,
data: {
isAlternate: false,
badge: tin.type,
badge: tin.connectorType,
icon: 'element',
type: 'step',
step: tin.from,
Expand Down Expand Up @@ -110,7 +110,7 @@ export function getOutgoingNodes(tons: TopologyOutgoingNode[]): NodeModel[] {
icon: 'element',
type: 'step',
step: tin.step,
badge: tin.type,
badge: tin.connectorType,
fileName: tin.fileName
}
}
Expand Down Expand Up @@ -146,6 +146,26 @@ export function getOutgoingEdges(tons: TopologyOutgoingNode[]): EdgeModel[] {
});
}

export function getExternalEdges(tons: TopologyOutgoingNode[], tins: TopologyIncomingNode[]): EdgeModel[] {
const result: EdgeModel[]= [];
tons.filter(ton => ton.type === 'external').forEach((ton, index) => {
const uniqueUri = ton.uniqueUri;
if (uniqueUri) {
const target = TopologyUtils.getNodeIdByUniqueUri(tins, uniqueUri);
const node: EdgeModel = {
id: 'external-' + ton.id + '-' + index,
type: 'edge',
source: ton.id,
target: target,
edgeStyle: EdgeStyle.dotted,
animationSpeed: EdgeAnimationSpeed.slow
}
if (target) result.push(node);
}
});
return result;
}

export function getRestNodes(tins: TopologyRestNode[]): NodeModel[] {
return tins.map(tin => {
return {
Expand Down Expand Up @@ -217,8 +237,8 @@ export function getModel(files: IntegrationFile[]): Model {
const nodes: NodeModel[] = [];
const groups: NodeModel[] = troutes.map(r => {
const children = [r.id]
children.push(... tins.filter(i => i.routeId === r.routeId && i.type === 'external').map(i => i.id));
children.push(... tons.filter(i => i.routeId === r.routeId && i.type === 'external').map(i => i.id));
children.push(...tins.filter(i => i.routeId === r.routeId && i.type === 'external').map(i => i.id));
children.push(...tons.filter(i => i.routeId === r.routeId && i.type === 'external').map(i => i.id));
return {
id: 'group-' + r.routeId,
children: children,
Expand All @@ -242,6 +262,7 @@ export function getModel(files: IntegrationFile[]): Model {
edges.push(...getOutgoingEdges(tons));
edges.push(...getRestEdges(trestns, tins));
edges.push(...getInternalEdges(tons, tins));
edges.push(...getExternalEdges(tons,tins));

return {nodes: nodes, edges: edges, graph: {id: 'g1', type: 'graph', layout: 'Dagre'}};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function TopologyTab (props: Props) {
}

const controller = React.useMemo(() => {
console.log(props.files)
const model = getModel(props.files);
const newController = new Visualization();
newController.registerLayoutFactory((_, graph) => new DagreLayout(graph));
Expand Down

0 comments on commit 6078a23

Please sign in to comment.