Skip to content

Commit f0a87ba

Browse files
feat(topology): Allow tooltip usage on pipeline task node badges (#8208)
1 parent a738bb9 commit f0a87ba

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

packages/react-integration/demo-app-ts/src/components/demos/TopologyDemo/PipelineTasks.tsx

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { Flex, FlexItem, Radio, ToolbarItem } from '@patternfly/react-core';
2+
import { Checkbox, Flex, FlexItem, Radio, ToolbarItem } from '@patternfly/react-core';
33
import {
44
TopologyView,
55
Visualization,
@@ -21,11 +21,22 @@ export const PipelineTasks: React.FC = () => {
2121
const [showBadges, setShowBadges] = React.useState<boolean>(false);
2222
const [showIcons, setShowIcons] = React.useState<boolean>(false);
2323
const [selectedIds, setSelectedIds] = React.useState<string[]>();
24+
const [badgeTooltips, setBadgeTooltips] = React.useState<boolean>(false);
2425

2526
const controller = useVisualizationController();
2627

2728
React.useEffect(() => {
28-
const tasks = createStatusTasks('task', 4, undefined, false, false, showContext, showBadges, showIcons);
29+
const tasks = createStatusTasks(
30+
'task',
31+
4,
32+
undefined,
33+
false,
34+
false,
35+
showContext,
36+
showBadges,
37+
showIcons,
38+
badgeTooltips
39+
);
2940
setWhenStatus(tasks);
3041
const finallyNodes = createFinallyTasks('finally', 2, tasks);
3142
const finallyGroup = {
@@ -45,7 +56,7 @@ export const PipelineTasks: React.FC = () => {
4556
nodes: [...tasks, ...finallyNodes, finallyGroup]
4657
};
4758
controller.fromModel(model, false);
48-
}, [controller, showBadges, showContext, showIcons]);
59+
}, [badgeTooltips, controller, showBadges, showContext, showIcons]);
4960

5061
useEventListener<SelectionEventListener>(SELECTION_EVENT, ids => {
5162
setSelectedIds(ids);
@@ -126,6 +137,14 @@ export const PipelineTasks: React.FC = () => {
126137
onChange={checked => checked && setShowContext(false)}
127138
/>
128139
</FlexItem>
140+
<FlexItem className="pf-u-ml-2xl">
141+
<Checkbox
142+
id="badge-tips-checkbox"
143+
label="Use tooltips for badges"
144+
isChecked={badgeTooltips}
145+
onChange={setBadgeTooltips}
146+
/>
147+
</FlexItem>
129148
</Flex>
130149
</ToolbarItem>
131150
</>

packages/react-integration/demo-app-ts/src/components/demos/TopologyDemo/components/DemoTaskNode.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ type DemoTaskNodeProps = {
2121
} & WithContextMenuProps &
2222
WithSelectionProps;
2323

24+
const DEMO_TIP_TEXT =
25+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.';
26+
2427
const DemoTaskNode: React.FunctionComponent<DemoTaskNodeProps> = ({
2528
element,
2629
onContextMenu,
@@ -49,13 +52,14 @@ const DemoTaskNode: React.FunctionComponent<DemoTaskNodeProps> = ({
4952
leftOffset={hasTaskIcon ? DEFAULT_WHEN_OFFSET + (element.getBounds().height - 4) * 0.75 : DEFAULT_WHEN_OFFSET}
5053
/>
5154
) : null;
55+
56+
// Set the badgePopoverParams, but if the node has badgeTooltips, this will be ignored
5257
const badgePopoverParams: PopoverProps = {
53-
headerContent: <div>Popover header</div>,
54-
bodyContent: (
55-
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam id feugiat augue, nec fringilla turpis.</div>
56-
),
58+
headerContent: 'Popover header',
59+
bodyContent: DEMO_TIP_TEXT,
5760
footerContent: 'Popover footer'
5861
};
62+
5963
return (
6064
<Layer id={detailsLevel !== ScaleDetailsLevel.high && hover ? TOP_LAYER : DEFAULT_LAYER}>
6165
<TaskNode
@@ -68,6 +72,7 @@ const DemoTaskNode: React.FunctionComponent<DemoTaskNodeProps> = ({
6872
{...passedData}
6973
{...rest}
7074
badgePopoverParams={badgePopoverParams}
75+
badgeTooltip={data.badgeTooltips && DEMO_TIP_TEXT}
7176
>
7277
{whenDecorator}
7378
</TaskNode>

packages/react-integration/demo-app-ts/src/components/demos/TopologyDemo/utils/pipelineUtils.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const createTask = (options: {
4646
showContextMenu?: boolean;
4747
showBadge?: boolean;
4848
showIcon?: boolean;
49+
badgeTooltips?: boolean;
4950
}): PipelineNodeModel => {
5051
const width = options.width || DEFAULT_TASK_WIDTH;
5152
const height = options.height || DEFAULT_TASK_HEIGHT;
@@ -86,7 +87,8 @@ export const createStatusTasks = (
8687
noLocation?: boolean,
8788
showContextMenu?: boolean,
8889
showBadge?: boolean,
89-
showIcon?: boolean
90+
showIcon?: boolean,
91+
badgeTooltips?: boolean
9092
): PipelineNodeModel[] =>
9193
TASK_STATUSES.map((status, index) =>
9294
createTask({
@@ -100,6 +102,7 @@ export const createStatusTasks = (
100102
showContextMenu,
101103
showBadge,
102104
showIcon,
105+
badgeTooltips,
103106
width: DEFAULT_TASK_WIDTH + (showContextMenu ? 10 : 0) + (showBadge ? 40 : 0)
104107
})
105108
);

packages/react-topology/src/pipelines/components/nodes/TaskNode.tsx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ export type TaskNodeProps = {
4545
badgeTextColor?: string;
4646
badgeBorderColor?: string;
4747
badgeClassName?: string;
48+
/** @deprecated Use badgePopoverParams instead */
4849
badgePopoverProps?: string;
49-
badgePopoverParams?: PopoverProps;
50+
badgeTooltip?: React.ReactNode; // Set to use a tooltip on the badge, takes precedence over the badgePopoverParams
51+
badgePopoverParams?: PopoverProps; // Set to use a popover on the badge, ignored if the badgeTooltip parameter is set
5052
taskIconClass?: string; // Icon to show for the task
5153
taskIcon?: React.ReactNode;
5254
taskIconTooltip?: React.ReactNode;
@@ -81,6 +83,8 @@ const TaskNode: React.FC<TaskNodeProps & { innerRef: React.Ref<SVGGElement> }> =
8183
badgeTextColor,
8284
badgeBorderColor,
8385
badgeClassName = styles.topologyPipelinesPillBadge,
86+
badgeTooltip,
87+
badgePopoverProps,
8488
badgePopoverParams,
8589
taskIconClass,
8690
taskIcon,
@@ -114,6 +118,11 @@ const TaskNode: React.FC<TaskNodeProps & { innerRef: React.Ref<SVGGElement> }> =
114118
const [contextSize, contextRef] = useSize([onContextMenu, paddingX]);
115119
const detailsLevel = useDetailsLevel();
116120

121+
if (badgePopoverProps) {
122+
// eslint-disable-next-line no-console
123+
console.warn('badgePopoverProps is deprecated. Use badgePopoverParams instead.');
124+
}
125+
117126
const textWidth = textSize?.width ?? 0;
118127
const textHeight = textSize?.height ?? 0;
119128
useAnchor(
@@ -261,7 +270,7 @@ const TaskNode: React.FC<TaskNodeProps & { innerRef: React.Ref<SVGGElement> }> =
261270
/>
262271
);
263272

264-
const badgeComponent = badge && (
273+
const badgeLabel = badge ? (
265274
<LabelBadge
266275
ref={badgeRef}
267276
x={badgeStartX}
@@ -272,7 +281,20 @@ const TaskNode: React.FC<TaskNodeProps & { innerRef: React.Ref<SVGGElement> }> =
272281
badgeTextColor={badgeTextColor}
273282
badgeBorderColor={badgeBorderColor}
274283
/>
275-
);
284+
) : null;
285+
286+
let badgeComponent: React.ReactNode;
287+
if (badgeLabel && badgeTooltip) {
288+
badgeComponent = <Tooltip content={badgeTooltip}>{badgeLabel}</Tooltip>;
289+
} else if (badgeLabel && badgePopoverParams) {
290+
badgeComponent = (
291+
<g onClick={e => e.stopPropagation()}>
292+
<Popover {...badgePopoverParams}>{badgeLabel}</Popover>
293+
</g>
294+
);
295+
} else {
296+
badgeComponent = badgeLabel;
297+
}
276298

277299
const renderTask = () => {
278300
if (showStatusState && !scaleNode && hideDetailsAtMedium && detailsLevel !== ScaleDetailsLevel.high) {
@@ -352,14 +374,7 @@ const TaskNode: React.FC<TaskNodeProps & { innerRef: React.Ref<SVGGElement> }> =
352374
)}
353375
{taskIconComponent &&
354376
(taskIconTooltip ? <Tooltip content={taskIconTooltip}>{taskIconComponent}</Tooltip> : taskIconComponent)}
355-
{badgeComponent &&
356-
(badgePopoverParams ? (
357-
<g onClick={e => e.stopPropagation()}>
358-
<Popover {...badgePopoverParams}>{badgeComponent}</Popover>
359-
</g>
360-
) : (
361-
badgeComponent
362-
))}
377+
{badgeComponent}
363378
{actionIcon && (
364379
<>
365380
<line

0 commit comments

Comments
 (0)