-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2680 from jenny-s51/v2-pipeline-artifact-nodes
Feat(pipelines): Adds support for artifact nodes and vertical layout
- Loading branch information
Showing
13 changed files
with
290 additions
and
45 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as React from 'react'; | ||
import { | ||
DEFAULT_SPACER_NODE_TYPE, | ||
GraphElement, | ||
Edge, | ||
EdgeTerminalType, | ||
observer, | ||
TaskEdge, | ||
} from '@patternfly/react-topology'; | ||
|
||
interface PipelineTaskEdgeProps { | ||
element: GraphElement; | ||
} | ||
|
||
const PipelineTaskEdge: React.FC<PipelineTaskEdgeProps> = ({ element, ...props }) => { | ||
const edge = element as Edge; | ||
return ( | ||
<TaskEdge | ||
element={edge} | ||
endTerminalType={ | ||
edge.getTarget().getType() !== DEFAULT_SPACER_NODE_TYPE | ||
? EdgeTerminalType.directional | ||
: undefined | ||
} | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
export default observer(PipelineTaskEdge); |
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
163 changes: 163 additions & 0 deletions
163
frontend/src/concepts/topology/customNodes/ArtifactTaskNode.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,163 @@ | ||
import React, { LegacyRef } from 'react'; | ||
import { | ||
TaskNode, | ||
DEFAULT_WHEN_OFFSET, | ||
Node, | ||
WhenDecorator, | ||
NodeModel, | ||
WithSelectionProps, | ||
observer, | ||
useAnchor, | ||
AnchorEnd, | ||
getRunStatusModifier, | ||
ScaleDetailsLevel, | ||
useHover, | ||
TaskNodeSourceAnchor, | ||
TaskNodeTargetAnchor, | ||
GraphElement, | ||
} from '@patternfly/react-topology'; | ||
import { ListIcon, MonitoringIcon } from '@patternfly/react-icons'; | ||
import { TaskNodeProps } from '@patternfly/react-topology/dist/esm/pipelines/components/nodes/TaskNode'; | ||
import { css } from '@patternfly/react-styles'; | ||
import { StandardTaskNodeData } from '~/concepts/topology/types'; | ||
|
||
const ICON_PADDING = 8; | ||
|
||
type IconTaskNodeProps = { | ||
element: Node<NodeModel, StandardTaskNodeData>; | ||
} & WithSelectionProps; | ||
|
||
const IconTaskNode: React.FC<IconTaskNodeProps> = observer(({ element, selected, onSelect }) => { | ||
const data = element.getData(); | ||
const status = data?.status; | ||
const bounds = element.getBounds(); | ||
const iconSize = bounds.height - ICON_PADDING * 2; | ||
|
||
const runStatusModifier = status && getRunStatusModifier(status); | ||
|
||
useAnchor( | ||
React.useCallback( | ||
(node: Node) => new TaskNodeSourceAnchor(node, ScaleDetailsLevel.high, 0, true), | ||
[], | ||
), | ||
AnchorEnd.source, | ||
); | ||
useAnchor( | ||
React.useCallback( | ||
(node: Node) => new TaskNodeTargetAnchor(node, 0, ScaleDetailsLevel.high, 0, true), | ||
[], | ||
), | ||
AnchorEnd.target, | ||
); | ||
|
||
return ( | ||
<g | ||
className={css( | ||
'pf-topology-pipelines__pill', | ||
runStatusModifier, | ||
selected && 'pf-m-selected', | ||
onSelect && 'pf-m-selectable', | ||
)} | ||
onClick={onSelect} | ||
> | ||
<rect | ||
className="pf-topology-pipelines__pill-background" | ||
x={0} | ||
y={0} | ||
width={bounds.width} | ||
height={bounds.height} | ||
rx={bounds.height / 2} | ||
/> | ||
<g | ||
transform={`translate(${(bounds.width - iconSize) / 2}, ${ICON_PADDING})`} | ||
color={ | ||
selected | ||
? 'var(--pf-v5-global--icon--Color--dark--light)' | ||
: 'var(--pf-v5-global--icon--Color--light)' | ||
} | ||
> | ||
{data?.artifactType === 'system.Metrics' ? ( | ||
<MonitoringIcon width={iconSize} height={iconSize} /> | ||
) : ( | ||
<ListIcon width={iconSize} height={iconSize} /> | ||
)} | ||
</g> | ||
</g> | ||
); | ||
}); | ||
|
||
type ArtifactTaskNodeInnerProps = WithSelectionProps & { | ||
element: Node<NodeModel, StandardTaskNodeData>; | ||
} & Omit<TaskNodeProps, 'element'> & { element: Node }; | ||
|
||
const ArtifactTaskNodeInner: React.FC<ArtifactTaskNodeInnerProps> = observer( | ||
({ element, selected, onSelect, ...rest }) => { | ||
const bounds = element.getBounds(); | ||
const [isHover, hoverRef] = useHover(); | ||
const detailsLevel = element.getGraph().getDetailsLevel(); | ||
const data = element.getData(); | ||
const scale = element.getGraph().getScale(); | ||
const iconSize = 24; | ||
const whenDecorator = data?.whenStatus ? ( | ||
<WhenDecorator element={element} status={data.whenStatus} leftOffset={DEFAULT_WHEN_OFFSET} /> | ||
) : null; | ||
const upScale = 1 / scale; | ||
|
||
return ( | ||
<g | ||
className={css('pf-topology__pipelines__task-node')} | ||
ref={hoverRef as LegacyRef<SVGGElement>} | ||
> | ||
{isHover || detailsLevel !== ScaleDetailsLevel.high ? ( | ||
<g> | ||
<TaskNode | ||
nameLabelClass="artifact-node-label" | ||
hideDetailsAtMedium | ||
truncateLength={30} | ||
element={element} | ||
hover | ||
selected={selected} | ||
onSelect={onSelect} | ||
status={data?.status} | ||
scaleNode={isHover} | ||
{...rest} | ||
> | ||
{whenDecorator} | ||
</TaskNode> | ||
{!isHover && detailsLevel !== ScaleDetailsLevel.high ? ( | ||
<g | ||
transform={`translate(0, ${ | ||
(bounds.height - iconSize * upScale) / 2 | ||
}) scale(${upScale})`} | ||
> | ||
<g transform="translate(4, 4)"> | ||
<g | ||
color={ | ||
selected | ||
? 'var(--pf-v5-global--icon--Color--dark--light)' | ||
: 'var(--pf-v5-global--icon--Color--light)' | ||
} | ||
> | ||
{data?.artifactType === 'system.Metrics' ? <MonitoringIcon /> : <ListIcon />} | ||
</g> | ||
</g> | ||
</g> | ||
) : null} | ||
</g> | ||
) : ( | ||
<IconTaskNode selected={selected} onSelect={onSelect} element={element} /> | ||
)} | ||
</g> | ||
); | ||
}, | ||
); | ||
|
||
type ArtifactTaskNodeProps = { | ||
element: GraphElement; | ||
} & WithSelectionProps; | ||
|
||
const ArtifactTaskNode: React.FC<ArtifactTaskNodeProps> = ({ element, ...rest }) => ( | ||
<ArtifactTaskNodeInner element={element as Node} {...rest} /> | ||
); | ||
|
||
export default ArtifactTaskNode; |
53 changes: 41 additions & 12 deletions
53
frontend/src/concepts/topology/customNodes/StandardTaskNode.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
Oops, something went wrong.