Skip to content

Commit

Permalink
Update pipeline styles towards spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jeff-phillips-18 committed Jun 28, 2022
1 parent d800f78 commit d60db7e
Show file tree
Hide file tree
Showing 11 changed files with 387 additions and 265 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import {
Model,
ModelKind,
withPanZoom,
GraphComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import * as React from 'react';
import { observer } from 'mobx-react';
import { Node, TaskNode, WhenDecorator } from '@patternfly/react-topology';
import { Node, TaskNode, WhenDecorator, WithContextMenuProps, WithSelectionProps } from '@patternfly/react-topology';

interface DemoTaskNodeProps {
type DemoTaskNodeProps = {
element: Node;
}
} & WithContextMenuProps &
WithSelectionProps;

const DemoTaskNode: React.FunctionComponent<DemoTaskNodeProps> = ({ element }) => {
const DemoTaskNode: React.FunctionComponent<DemoTaskNodeProps> = ({
element,
onContextMenu,
contextMenuOpen,
...rest
}) => {
const data = element.getData();

const passedData = React.useMemo(() => {
Expand All @@ -22,7 +28,13 @@ const DemoTaskNode: React.FunctionComponent<DemoTaskNodeProps> = ({ element }) =
const whenDecorator = data.whenStatus ? <WhenDecorator element={element} status={data.whenStatus} /> : null;

return (
<TaskNode element={element} {...passedData}>
<TaskNode
element={element}
onContextMenu={data.showContextMenu ? onContextMenu : undefined}
contextMenuOpen={contextMenuOpen}
{...passedData}
{...rest}
>
{whenDecorator}
</TaskNode>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,40 @@ import {
DEFAULT_SPACER_NODE_TYPE,
DEFAULT_EDGE_TYPE,
DEFAULT_FINALLY_NODE_TYPE,
FinallyNode
FinallyNode,
ContextMenuSeparator,
ContextMenuItem,
withContextMenu,
withSelection
} from '@patternfly/react-topology';
import DemoTaskNode from './DemoTaskNode';
import * as React from 'react';

const contextMenuItem = (label: string, i: number): React.ReactElement => {
if (label === '-') {
return <ContextMenuSeparator key={`separator:${i.toString()}`} />;
}
return (
// eslint-disable-next-line no-alert
<ContextMenuItem key={label} onClick={() => alert(`Selected: ${label}`)}>
{label}
</ContextMenuItem>
);
};

const createContextMenuItems = (...labels: string[]): React.ReactElement[] => labels.map(contextMenuItem);

const defaultMenu = createContextMenuItems('First', 'Second', 'Third', '-', 'Fourth');

const shapesComponentFactory: ComponentFactory = (
kind: ModelKind,
type: string
): ComponentType<{ element: GraphElement }> | undefined => {
switch (type) {
case DEFAULT_TASK_NODE_TYPE:
return DemoTaskNode;
return withContextMenu(() => defaultMenu)(withSelection()(DemoTaskNode));
case DEFAULT_FINALLY_NODE_TYPE:
return FinallyNode;
return withContextMenu(() => defaultMenu)(withSelection()(FinallyNode));
case 'finally-group':
return DefaultTaskGroup;
case DEFAULT_SPACER_NODE_TYPE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import {
export const ROW_HEIGHT = 80;
export const COLUMN_WIDTH = 250;

export const DEFAULT_TASK_WIDTH = 200;
export const DEFAULT_TASK_WIDTH = 180;
export const FINALLY_TASK_WIDTH = DEFAULT_TASK_WIDTH - DEFAULT_WHEN_OFFSET - DEFAULT_WHEN_SIZE;
export const DEFAULT_TASK_HEIGHT = 40;
export const DEFAULT_TASK_HEIGHT = 32;

export const TASK_STATUSES = [
undefined,
RunStatus.Succeeded,
RunStatus.Failed,
RunStatus.Running,
RunStatus['In Progress'],
RunStatus.InProgress,
RunStatus.FailedToStart,
RunStatus.Skipped,
RunStatus.Cancelled,
Expand All @@ -42,6 +42,7 @@ export const createTask = (options: {
marginX?: number;
marginY?: number;
noLocation?: boolean;
showContextMenu?: boolean;
}): PipelineNodeModel => {
const width = options.width || DEFAULT_TASK_WIDTH;
const height = options.height || DEFAULT_TASK_HEIGHT;
Expand Down Expand Up @@ -79,7 +80,8 @@ export const createStatusTasks = (
row: Math.ceil((index + 1) / statusPerRow) - 1,
column: index % statusPerRow,
selected,
noLocation
noLocation,
showContextMenu: true
})
);

Expand Down
255 changes: 146 additions & 109 deletions packages/react-styles/src/css/components/Topology/topology-pipelines.css

Large diffs are not rendered by default.

111 changes: 5 additions & 106 deletions packages/react-topology/src/pipelines/components/nodes/FinallyNode.tsx
Original file line number Diff line number Diff line change
@@ -1,109 +1,8 @@
import * as React from 'react';
import { css } from '@patternfly/react-styles';
import styles from '@patternfly/react-styles/css/components/Topology/topology-pipelines';
import { Tooltip } from '@patternfly/react-core';
import { observer } from '../../../mobx-exports';
import { Node } from '../../../types';
import { RunStatus } from '../../types';
import { useAnchor, WithSelectionProps } from '../../../behavior';
import { truncateMiddle } from '../../../utils/truncate-middle';
import { useSize } from '../../../utils';
import { getRunStatusModifier } from '../../utils';
import StatusIcon from '../../utils/StatusIcon';
import { RectAnchor } from '../../../anchors';
import TaskNode, { TaskNodeProps } from './TaskNode';

type FinallyNodeProps = {
element: Node;
className?: string;
paddingX?: number;
nameLabelClass?: string;
status?: RunStatus;
statusWidth?: number;
showStatusState?: boolean;
truncateLength?: number;
disableTooltip?: boolean;
toolTip?: React.ReactNode;
} & Partial<WithSelectionProps>;
const FinallyNode: React.FC<TaskNodeProps> = props => (
<TaskNode whenOffset={0} whenSize={0} truncateLength={22} {...props} />
);

const FinallyNode: React.FC<FinallyNodeProps> = ({
element,
className,
paddingX = 8,
status,
statusWidth = 16,
showStatusState = true,
truncateLength = 14,
toolTip,
disableTooltip = false,
selected,
children
}) => {
const { height, width } = element.getBounds();
const [textSize, textRef] = useSize([element.getLabel()]);
const textHeight = textSize?.height ?? 0;
useAnchor(RectAnchor);

const truncatedName = React.useMemo(() => truncateMiddle(element.getLabel(), { length: truncateLength }), [
element,
truncateLength
]);
const nameLabel = (
<text ref={textRef} className={css('topology-pipelines--pill__text')}>
{truncatedName}
</text>
);

const taskPill = (
<g className={css(styles.topologyPipelinesPill, className)}>
<rect
width={width}
height={height}
rx={height / 2}
className={css(styles.topologyPipelinesPillBackground, selected && styles.modifiers.selected)}
/>
<g
transform={`translate(${(status && showStatusState ? statusWidth : 0) + 2 * paddingX}, ${(height +
textHeight / 2) /
2})`}
>
{element.getLabel() !== truncatedName && !disableTooltip ? (
<Tooltip content={element.getLabel()}>{nameLabel}</Tooltip>
) : (
nameLabel
)}
</g>
{status && showStatusState && (
<g
transform={`translate(${paddingX}, ${(height - statusWidth) / 2 - 1})`}
width={statusWidth}
height={statusWidth}
>
<g
className={css(
styles.topologyPipelinesPillStatus,
getRunStatusModifier(status),
(status === RunStatus.Running || status === RunStatus['In Progress']) && styles.modifiers.spin
)}
>
<StatusIcon status={status} />
</g>
</g>
)}
{children}
</g>
);

return (
<g className={css('pf-topology__pipelines__task-node', className)}>
{!toolTip || disableTooltip ? (
taskPill
) : (
<Tooltip position="bottom" enableFlip={false} content={toolTip}>
{taskPill}
</Tooltip>
)}
</g>
);
};

export default observer(FinallyNode);
export default FinallyNode;
Loading

0 comments on commit d60db7e

Please sign in to comment.