Fixes #38879 - Update BarChart to Patternfly5#10743
Fixes #38879 - Update BarChart to Patternfly5#10743tlabaj wants to merge 1 commit intotheforeman:developfrom
Conversation
|
Looking at those screenshots, could the chart fill the entire width of the card like it used to? |
kmalyjur
left a comment
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
The BarChartService.js file could be deleted when it's not used anymore
webpack/assets/javascripts/react_app/components/common/charts/BarChart/index.js
Outdated
Show resolved
Hide resolved
| return <MessageBox msg={noDataMsg} icontype="info" />; | ||
|
|
||
| // Configuration based on size | ||
| const getChartDimensions = () => { |
There was a problem hiding this comment.
As Adam noticed, it would be nice if it filled the space
There was a problem hiding this comment.
This function could be moved outside of the BarChart component
There was a problem hiding this comment.
The custom coloring doesn't work
There was a problem hiding this comment.
'container' is declared but its value is never read.ts(6133)
The same happens for "renders with custom axis labels" test
|
@kmalyjur Is this ~finished enough to test with packit? |
kmalyjur
left a comment
There was a problem hiding this comment.
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.
|
Thank you, now it just needs to be verified |
|
/packit build |
|
https://copr.fedorainfracloud.org/coprs/fulltext/?fulltext=packit%2Ftheforeman-foreman-10743 is missing, can someone build it please? |
|
/packit build |
|
@tlabaj there have been 57 commits added to this PR, that doesn't seem right |
30d3a1e to
8e3e638
Compare
kmalyjur
left a comment
There was a problem hiding this comment.
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.
| return rawData.map(item => ({ | ||
| x: item[0], // label | ||
| y: item[1], // value | ||
| name: item[0], | ||
| color: item[2] || undefined, // custom color if provided | ||
| })); |
There was a problem hiding this comment.
| 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 | |
| })); |
| <ChartVoronoiContainer | ||
| labels={({ datum }) => getTooltipValue(datum)} |
There was a problem hiding this comment.
This makes the hover area vertical slices, so it's easier to trigger the tooltip
| <ChartVoronoiContainer | |
| labels={({ datum }) => getTooltipValue(datum)} | |
| <ChartVoronoiContainer | |
| voronoiDimension="x" | |
| labels={({ datum }) => getTooltipValue(datum)} |
| constrainToVisibleArea | ||
| renderInPortal |
There was a problem hiding this comment.
Deleting renderInPortal
| constrainToVisibleArea | |
| renderInPortal | |
| constrainToVisibleArea |
There was a problem hiding this comment.
| BarChart.propTypes = { | |
| data: PropTypes.arrayOf(PropTypes.any), |
| 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)' }}> |
There was a problem hiding this comment.
We should move the inline styles into a separate BarChart.scss.
| unloadBeforeLoad={unloadData} | ||
| /> | ||
| <g> | ||
| <foreignObject |
There was a problem hiding this comment.
The tooltip looks great, however, can I please ask why foreignObject is used instead of ChartTooltip from PF?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
That makes sense, thank you for the explanation
| x: PropTypes.any, | ||
| y: PropTypes.any, | ||
| name: PropTypes.any, |
There was a problem hiding this comment.
There could be more specific PropTypes used than any.
|
I, just as @kmalyjur , wasn't able to get the tooltips working out of the box => failed. |




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:

After:
