-
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.
- Loading branch information
Showing
7 changed files
with
179 additions
and
17 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
45 changes: 30 additions & 15 deletions
45
packages/ui/src/components/Visualization/Custom/ContextMenu/ItemAddStep.tsx
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
20 changes: 20 additions & 0 deletions
20
packages/ui/src/components/Visualization/Custom/Edge/CustomEdge.scss
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,20 @@ | ||
/* stylelint-disable */ | ||
|
||
.custom-edge { | ||
--pf-topology__edge--m-hover--background--Stroke: none; | ||
background: var(--pf-v5-global--palette--white); | ||
&__end { | ||
border-radius: 3px; | ||
border: 1px solid var(--pf-v5-global--palette--black-400); | ||
--pf-topology__node--Color: var(--pf-v5-global--palette--black-500); | ||
width: 24px; | ||
height: 24px; | ||
padding: 3px; | ||
display: flex; | ||
position: relative; | ||
|
||
&:hover { | ||
border-color: var(--pf-v5-global--palette--blue-500); | ||
} | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/ui/src/components/Visualization/Custom/Edge/EdgeEnd.tsx
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,53 @@ | ||
import { DefaultEdge, Edge, EdgeModel, EdgeTerminalType, observer } from '@patternfly/react-topology'; | ||
import { Button, Tooltip } from '@patternfly/react-core'; | ||
import { PlusIcon } from '@patternfly/react-icons'; | ||
import './CustomEdge.scss'; | ||
import { addNode } from '../ContextMenu/ItemAddStep'; | ||
import { CatalogModalContext, EntitiesContext } from '../../../../providers'; | ||
import { useContext } from 'react'; | ||
import { IVisualizationNode } from '../../../../models'; | ||
|
||
interface EdgeEndProps { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
element: Edge<EdgeModel, any>; | ||
} | ||
|
||
const EdgeEnd: React.FC<EdgeEndProps> = observer(({ element, ...rest }) => { | ||
const entitiesContext = useContext(EntitiesContext); | ||
const catalogModalContext = useContext(CatalogModalContext); | ||
const vizNode: IVisualizationNode = element.getSource().getData()?.vizNode; | ||
const isHorizontal = element.getGraph().getLayout() === 'DagreHorizontal'; | ||
const endPoint = element.getEndPoint(); | ||
let x, y; | ||
if (isHorizontal) { | ||
x = endPoint.x; | ||
y = endPoint.y - 12; | ||
} else { | ||
x = endPoint.x - 12; | ||
y = endPoint.y; | ||
} | ||
const onAdd = () => { | ||
addNode(catalogModalContext, entitiesContext, vizNode); | ||
}; | ||
return ( | ||
<DefaultEdge | ||
element={element} | ||
startTerminalType={EdgeTerminalType.none} | ||
endTerminalType={EdgeTerminalType.none} | ||
className="custom-edge" | ||
{...rest} | ||
> | ||
<g data-testid={`custom-edge__${element?.getId()}`}> | ||
<foreignObject x={x} y={y} width="24" height="24" className="custom-edge"> | ||
<Tooltip content="Append"> | ||
<Button variant="plain" className="custom-edge__end" onClick={onAdd}> | ||
<PlusIcon size={40} /> | ||
</Button> | ||
</Tooltip> | ||
</foreignObject> | ||
</g> | ||
</DefaultEdge> | ||
); | ||
}); | ||
|
||
export const EdgeEndWithButton: typeof DefaultEdge = EdgeEnd as typeof DefaultEdge; |
60 changes: 59 additions & 1 deletion
60
packages/ui/src/components/Visualization/Custom/NoBendingEdge.tsx
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 |
---|---|---|
@@ -1,7 +1,65 @@ | ||
import { BaseEdge, Point } from '@patternfly/react-topology'; | ||
import { BaseEdge, getTopCollapsedParent, Point } from '@patternfly/react-topology'; | ||
|
||
export class NoBendpointsEdge extends BaseEdge { | ||
getBendpoints(): Point[] { | ||
return []; | ||
} | ||
getStartPoint(): Point { | ||
if (this.getTarget() === this.getSource()) { | ||
const parent = getTopCollapsedParent(this.getSource()); | ||
const isHorizontal = this.getGraph().getLayout() === 'DagreHorizontal'; | ||
const parentPos = parent.getPosition(); | ||
const parentSize = parent.getDimensions(); | ||
let x, y; | ||
if (isHorizontal) { | ||
if (parent.getType() === 'group') { | ||
x = parentPos.x + parentSize.width / 2.0; | ||
y = parentPos.y; | ||
} else { | ||
x = parentPos.x + parentSize.width; | ||
y = parentPos.y + parentSize.height / 2.0; | ||
} | ||
} else { | ||
if (parent.getType() === 'group') { | ||
x = parentPos.x; | ||
y = parentPos.y + parentSize.height / 2.0; | ||
} else { | ||
x = parentPos.x + parentSize.width / 2.0; | ||
y = parentPos.y + parentSize.height; | ||
} | ||
} | ||
return new Point(x, y); | ||
} else { | ||
return super.getStartPoint(); | ||
} | ||
} | ||
getEndPoint(): Point { | ||
if (this.getTarget() === this.getSource()) { | ||
const parent = getTopCollapsedParent(this.getSource()); | ||
const isHorizontal = this.getGraph().getLayout() === 'DagreHorizontal'; | ||
const parentPos = parent.getPosition(); | ||
const parentSize = parent.getDimensions(); | ||
let x, y; | ||
if (isHorizontal) { | ||
if (parent.getType() === 'group') { | ||
x = parentPos.x + parentSize.width / 2.0 + 15; | ||
y = parentPos.y; | ||
} else { | ||
x = parentPos.x + parentSize.width / 2.0 + 55; | ||
y = parentPos.y + parentSize.height / 2.0; | ||
} | ||
} else { | ||
if (parent.getType() === 'group') { | ||
x = parentPos.x; | ||
y = parentPos.y + parentSize.height / 2.0 + 15; | ||
} else { | ||
x = parentPos.x + parentSize.width / 2.0; | ||
y = parentPos.y + parentSize.height / 2.0 + 85; | ||
} | ||
} | ||
return new Point(x, y); | ||
} else { | ||
return super.getEndPoint(); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './Group/CustomGroup'; | ||
export * from './NoBendingEdge'; | ||
export * from './Node/CustomNode'; | ||
export * from './Edge/EdgeEnd'; |