Skip to content

Fixes #38879 - Update BarChart to Patternfly5#10743

Open
tlabaj wants to merge 1 commit intotheforeman:developfrom
tlabaj:barchart
Open

Fixes #38879 - Update BarChart to Patternfly5#10743
tlabaj wants to merge 1 commit intotheforeman:developfrom
tlabaj:barchart

Conversation

@tlabaj
Copy link
Contributor

@tlabaj tlabaj commented Oct 30, 2025

Fixes: #38879

This PR updates the Bar Chart to use the PF5 components.
API's have been maintained as to not introduce breaking changes to any plugins that may be using the component.
Tests have been updated to use RTL.

Before:
Screenshot 2025-10-29 at 4 21 00 PM

After:
Screenshot 2025-10-30 at 10 31 37 AM

@adamruzicka
Copy link
Contributor

Looking at those screenshots, could the chart fill the entire width of the card like it used to?

@tlabaj tlabaj changed the title Barchart Fixes #38879 - Update BarChart to Patternfly5 Nov 3, 2025
@lhellebr lhellebr self-requested a review November 24, 2025 12:17
Copy link
Contributor

@kmalyjur kmalyjur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I'm leaving some comments.
I haven't tested the chart in the foreman_openscap yet.

import React from 'react';
import PropTypes from 'prop-types';
import { BarChart as PfBarChart } from 'patternfly-react';
import { getBarChartConfig } from '../../../../../services/charts/BarChartService';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The BarChartService.js file could be deleted when it's not used anymore

return <MessageBox msg={noDataMsg} icontype="info" />;

// Configuration based on size
const getChartDimensions = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Adam noticed, it would be nice if it filled the space

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not have data in my bar chart, but this is how it looks filling the space.

image

Comment on lines 25 to 34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could be moved outside of the BarChart component

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom coloring doesn't work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fireEvent is not used

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'container' is declared but its value is never read.ts(6133)

The same happens for "renders with custom axis labels" test

@lhellebr
Copy link
Contributor

lhellebr commented Dec 2, 2025

@kmalyjur Is this ~finished enough to test with packit?

@kmalyjur
Copy link
Contributor

kmalyjur commented Dec 3, 2025

@kmalyjur Is this ~finished enough to test with packit?

@lhellebr I'm not sure, to be honest. I would wait for the changes.

Copy link
Contributor

@kmalyjur kmalyjur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything is great now, but I forgot that when deleting functions (getBarChartConfig) in foreman core, we need to add a deprecation message first. I'm sorry for not mentioning this before.

There is a deprecation function for that, here is an example of usage: https://github.com/theforeman/foreman/pull/8267/files.
The message could be something like "Please use COMPONENT_NAME from IMPORT_PATH instead".
Could you please not delete getBarChartConfig (and the tests) and deprecate it instead?

Also, the file foreman/config/irbrc_history could be deleted.

@kmalyjur
Copy link
Contributor

kmalyjur commented Jan 2, 2026

Thank you, now it just needs to be verified

@lhellebr
Copy link
Contributor

lhellebr commented Jan 7, 2026

/packit build

@lhellebr
Copy link
Contributor

lhellebr commented Jan 7, 2026

@adamruzicka
Copy link
Contributor

/packit build

@lhellebr
Copy link
Contributor

lhellebr commented Jan 8, 2026

FailedQA with foreman-3.18.0-0.20260107161624001555.pr10743.8932.g7a7c7f239.el9.noarch on Firefox 146.0 build 20251211125526 and Chromium 143.0.7499.169.

When hovered, the tooltip isn't shown so it's not at all clear from the graph what value exactly the bar represents.
Original state:
Screenshot From 2026-01-08 15-32-37

New state:
Screenshot From 2026-01-08 15-32-52

In SCAP, there is a table next to the graph, but that's not true for other places.

@tlabaj tlabaj requested a review from a team as a code owner February 4, 2026 20:27
@lhellebr
Copy link
Contributor

lhellebr commented Feb 4, 2026

@tlabaj there have been 57 commits added to this PR, that doesn't seem right

@tlabaj tlabaj force-pushed the barchart branch 3 times, most recently from 30d3a1e to 8e3e638 Compare February 9, 2026 22:14
@tlabaj
Copy link
Contributor Author

tlabaj commented Feb 9, 2026

@lhellebr @kmalyjur I updated the tooltip. I also fixed the commit issue.

image

Copy link
Contributor

@kmalyjur kmalyjur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested this using bundle exec rake seed:reports origin=Puppet hosts=3 reports=5 lines=10, but I couldn't see the tooltips until I made these adjustments.
What do you think about it? If it works for you just fine without my changes, I might have something wrong with my environment. I'm honestly not sure about it.

Comment on lines +22 to +27
return rawData.map(item => ({
x: item[0], // label
y: item[1], // value
name: item[0],
color: item[2] || undefined, // custom color if provided
}));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return rawData.map(item => ({
x: item[0], // label
y: item[1], // value
name: item[0],
color: item[2] || undefined, // custom color if provided
}));
return rawData.map((item, index) => ({
x: item?.x ?? item[0], // label
y: item?.y ?? item[1], // value
name: item?.name ?? (item?.x ?? item[0]),
color: item?.color ?? (item[2] || undefined), // custom color if provided
}));

Comment on lines +177 to +178
<ChartVoronoiContainer
labels={({ datum }) => getTooltipValue(datum)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the hover area vertical slices, so it's easier to trigger the tooltip

Suggested change
<ChartVoronoiContainer
labels={({ datum }) => getTooltipValue(datum)}
<ChartVoronoiContainer
voronoiDimension="x"
labels={({ datum }) => getTooltipValue(datum)}

Comment on lines +181 to +182
constrainToVisibleArea
renderInPortal
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting renderInPortal

Suggested change
constrainToVisibleArea
renderInPortal
constrainToVisibleArea

Comment on lines 234 to 235
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
BarChart.propTypes = {
data: PropTypes.arrayOf(PropTypes.any),

Comment on lines +108 to +136
style={{
background: 'var(--pf-v5-global--BackgroundColor--dark-100)',
color: 'var(--pf-v5-global--Color--light-100)',
padding:
'var(--pf-v5-global--spacer--sm) var(--pf-v5-global--spacer--md)',
borderRadius: 'var(--pf-v5-global--BorderRadius--sm)',
fontSize: 'var(--pf-v5-global--FontSize--sm)',
fontFamily: 'var(--pf-v5-global--FontFamily--sans-serif)',
}}
>
<div style={{ fontWeight: 700 }}>{tooltipTitle}</div>
<Divider
style={{
margin: 'var(--pf-v5-global--spacer--xs) 0',
backgroundColor: 'var(--pf-v5-global--Color--200)',
}}
/>
<div style={{ display: 'flex', alignItems: 'center' }}>
<span
style={{
width: 'var(--pf-v5-global--spacer--sm)',
height: 'var(--pf-v5-global--spacer--sm)',
background: color,
display: 'inline-block',
marginRight: 'var(--pf-v5-global--spacer--xs)',
}}
/>
<span>Value:</span>
<span style={{ marginLeft: 'var(--pf-v5-global--spacer--xs)' }}>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move the inline styles into a separate BarChart.scss.

unloadBeforeLoad={unloadData}
/>
<g>
<foreignObject
Copy link
Contributor

@kmalyjur kmalyjur Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tooltip looks great, however, can I please ask why foreignObject is used instead of ChartTooltip from PF?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am using the ChartTooltip. I followed the PF example on how to embed HTML in the tooltip and foreignObject is used. This was the best way to get the tooltip to look like it was with the prior implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thank you for the explanation

Comment on lines +147 to +149
x: PropTypes.any,
y: PropTypes.any,
name: PropTypes.any,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There could be more specific PropTypes used than any.

@lhellebr
Copy link
Contributor

I, just as @kmalyjur , wasn't able to get the tooltips working out of the box => failed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments