-
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.
feat(Edge): Use Decorator for adding a + icon
- Loading branch information
Showing
8 changed files
with
701 additions
and
163 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
724 changes: 632 additions & 92 deletions
724
packages/ui/src/components/Visualization/Canvas/__snapshots__/Canvas.test.tsx.snap
Large diffs are not rendered by default.
Oops, something went wrong.
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: 0 additions & 20 deletions
20
packages/ui/src/components/Visualization/Custom/Edge/CustomEdge.scss
This file was deleted.
Oops, something went wrong.
62 changes: 33 additions & 29 deletions
62
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 |
---|---|---|
@@ -1,53 +1,57 @@ | ||
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 { | ||
Decorator, | ||
DefaultEdge, | ||
EdgeModel, | ||
EdgeTerminalType, | ||
GraphElement, | ||
isEdge, | ||
observer, | ||
} from '@patternfly/react-topology'; | ||
import { FunctionComponent, useCallback, useContext } from 'react'; | ||
import { IVisualizationNode } from '../../../../models'; | ||
import { CatalogModalContext, EntitiesContext } from '../../../../providers'; | ||
import { addNode } from '../ContextMenu/ItemAddStep'; | ||
import { LayoutType } from '../../Canvas'; | ||
|
||
interface EdgeEndProps { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
element: Edge<EdgeModel, any>; | ||
type DefaultEdgeProps = Parameters<typeof DefaultEdge>[0]; | ||
interface EdgeEndProps extends DefaultEdgeProps { | ||
/** We're not providing Data to edges */ | ||
element: GraphElement<EdgeModel, unknown>; | ||
} | ||
|
||
const EdgeEnd: React.FC<EdgeEndProps> = observer(({ element, ...rest }) => { | ||
export const EdgeEndWithButton: FunctionComponent<EdgeEndProps> = observer(({ element, ...rest }) => { | ||
if (!isEdge(element)) { | ||
throw new Error('EdgeEndWithButton must be used only on Edge elements'); | ||
} | ||
const entitiesContext = useContext(EntitiesContext); | ||
const catalogModalContext = useContext(CatalogModalContext); | ||
const vizNode: IVisualizationNode = element.getSource().getData()?.vizNode; | ||
const isHorizontal = element.getGraph().getLayout() === 'DagreHorizontal'; | ||
const isHorizontal = element.getGraph().getLayout() === LayoutType.DagreHorizontal; | ||
const endPoint = element.getEndPoint(); | ||
let x, y; | ||
|
||
const onAdd = useCallback(() => { | ||
addNode(catalogModalContext, entitiesContext, vizNode); | ||
}, [catalogModalContext, entitiesContext, vizNode]); | ||
|
||
let x = endPoint.x; | ||
let y = endPoint.y; | ||
if (isHorizontal) { | ||
x = endPoint.x; | ||
y = endPoint.y - 12; | ||
x += 12; | ||
} else { | ||
x = endPoint.x - 12; | ||
y = endPoint.y; | ||
y += 4; | ||
} | ||
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> | ||
<Decorator showBackground radius={12} x={x} y={y} icon={<PlusIcon />} onClick={onAdd} /> | ||
</g> | ||
</DefaultEdge> | ||
); | ||
}); | ||
|
||
export const EdgeEndWithButton: typeof DefaultEdge = EdgeEnd as typeof DefaultEdge; |
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