Skip to content

Commit cb40081

Browse files
committed
pr review comments
Signed-off-by: Dallas Nicol <[email protected]>
1 parent c6c0ed4 commit cb40081

File tree

4 files changed

+45
-33
lines changed

4 files changed

+45
-33
lines changed

DONUT_CHART_PF5_MIGRATION_SUMMARY.md

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ Successfully migrated the DonutChart component from PatternFly React v2 (C3.js-b
4242
- ✅ Updated padding for better chart display
4343
- ✅ Maintained backward compatibility by keeping C3.js properties for reference
4444

45-
## Props Interface - UNCHANGED
46-
All existing props work the same:
45+
## Props Interface ✅
46+
All existing props work the same (except unloadData which was removed):
4747
```javascript
4848
{
4949
data: Array, // [['Label', value, color], ...]
5050
config: String, // 'regular' | 'medium' | 'large'
5151
noDataMsg: String, // Custom empty state message
5252
title: Object, // { type: 'percent', precision: 1 } or { primary, secondary }
53-
unloadData: Boolean, // Kept for compatibility (not used in PF5)
5453
onclick: Function, // Click handler
5554
searchUrl: String, // URL for search navigation
5655
searchFilters: Object, // Search filter mapping
@@ -126,10 +125,12 @@ const percentage = ((maxValue / total) * 100).toFixed(precision);
126125

127126

128127
### ⚠️ Known Differences
129-
1. **unloadData prop**: PF5 doesn't support `unloadBeforeLoad` - prop is accepted but ignored
130-
2. **Legend**: Large config legend may need styling adjustments
131-
3. **Tooltip Styling**: Victory tooltips have different visual styling than C3.js (but show same percentage information)
132-
4. **Animations**: PF5 charts have built-in animations (C3.js animations were configurable)
128+
1. **unloadData prop**: Removed (PF5 doesn't support `unloadBeforeLoad`)
129+
2. **Label truncation**: Labels are no longer truncated at 30 characters (was not visible in UI)
130+
3. **Legend**: Large config legend may need styling adjustments
131+
4. **Tooltip Styling**: Victory tooltips have different visual styling than C3.js (but show same percentage information)
132+
5. **Animations**: PF5 charts have built-in animations (C3.js animations were configurable)
133+
6. **Chart wrapper**: Added `margin: auto` for proper centering
133134

134135
## Configuration Mapping
135136

@@ -155,4 +156,29 @@ const percentage = ((maxValue / total) * 100).toFixed(precision);
155156

156157
**Can be removed eventually (after all charts migrated):**
157158
- `patternfly-react` ^2.40.0 (still needed for Bar/Line/Area charts)
158-
- `patternfly` ^3.59.5 (still needed for C3.js charts)
159+
- `patternfly` ^3.59.5 (still needed for C3.js charts)
160+
161+
## PR Review Changes
162+
163+
### Changes based on code review feedback:
164+
165+
1. **Removed `unloadData` prop**
166+
- This prop was not used by any components
167+
- PF5 doesn't support `unloadBeforeLoad` anyway
168+
- Files updated: DonutChart/index.js
169+
170+
2. **Added CSS centering**
171+
- Added `margin: auto` to wrapper div style
172+
- Ensures chart is centered in all contexts (including /legacy/job_invocations)
173+
- Files updated: DonutChart/index.js
174+
175+
3. **Fixed integration test selector**
176+
- Added `.donut-chart-pf` class back to wrapper div for tests
177+
- Files updated: DonutChart/index.js
178+
179+
4. **Removed unused label truncation logic**
180+
- Removed shortLabel logic that truncated labels at 30 characters
181+
- This truncation was not visible anywhere in the UI (no legend displayed)
182+
- Simplified code by using full labels directly
183+
- Updated tests to reflect the change
184+
- Files updated: ChartService.js, DonutChartService.test.js

webpack/assets/javascripts/react_app/components/common/charts/DonutChart/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const DonutChart = ({
1212
config,
1313
noDataMsg,
1414
title,
15-
unloadData, // Note: PF5 doesn't have unloadBeforeLoad, this prop is kept for compatibility but not used
1615
searchUrl,
1716
searchFilters,
1817
}) => {
@@ -62,7 +61,7 @@ const DonutChart = ({
6261
}
6362

6463
return (
65-
<div style={{ height, width }}>
64+
<div className="donut-chart-pf" style={{ height, width, margin: 'auto' }}>
6665
<ChartDonut
6766
ariaDesc="Donut chart"
6867
ariaTitle={subtitleText || 'Chart'}
@@ -91,7 +90,6 @@ DonutChart.propTypes = {
9190
config: PropTypes.oneOf(['regular', 'medium', 'large']),
9291
noDataMsg: PropTypes.string,
9392
title: PropTypes.object,
94-
unloadData: PropTypes.bool,
9593
onclick: PropTypes.func,
9694
searchUrl: PropTypes.string,
9795
searchFilters: PropTypes.object,
@@ -102,7 +100,6 @@ DonutChart.defaultProps = {
102100
config: 'regular',
103101
noDataMsg: __('No data available'),
104102
title: { type: 'percent', precision: 1 },
105-
unloadData: false,
106103
onclick: noop,
107104
searchUrl: undefined,
108105
searchFilters: undefined,

webpack/assets/javascripts/services/charts/ChartService.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,10 @@ export const getDonutChartConfigPF5 = ({
124124
// Transform data from [label, value, color] to Victory format
125125
const transformedData = [];
126126
const colorScale = [];
127-
const longNames = {};
128127

129128
data.forEach(item => {
130129
const [label, value, color] = item;
131-
const shortLabel =
132-
label.length > 30 ? `${label.substring(0, 27)}...` : label;
133-
134-
longNames[shortLabel] = label;
135-
transformedData.push({ x: shortLabel, y: value, name: label });
130+
transformedData.push({ x: label, y: value, name: label });
136131

137132
if (color) {
138133
colorScale.push(color);
@@ -175,9 +170,8 @@ export const getDonutChartConfigPF5 = ({
175170

176171
// Configure labels to show full name and percentage in tooltip
177172
const labels = ({ datum }) => {
178-
const fullName = longNames[datum.x] || datum.x;
179173
const percentage = total > 0 ? ((datum.y / total) * 100).toFixed(1) : 0;
180-
return `${fullName}: ${percentage}%`;
174+
return `${datum.name}: ${percentage}%`;
181175
};
182176

183177
return {

webpack/assets/javascripts/services/charts/DonutChartService.test.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ describe('getDonutChartConfig', () => {
107107
});
108108
});
109109

110-
describe('label truncation', () => {
111-
it('truncates labels longer than 30 characters', () => {
110+
describe('label handling', () => {
111+
it('preserves full labels including long ones', () => {
112112
const result = getDonutChartConfig({
113113
data: inputDataWithLongLabels,
114114
onclick: jest.fn(),
@@ -120,17 +120,14 @@ describe('getDonutChartConfig', () => {
120120
item.name.includes('extra extra extra extra extra extra extra')
121121
);
122122

123-
// x should be truncated
124-
expect(longLabelItem.x.length).toBeLessThanOrEqual(30);
125-
expect(longLabelItem.x).toMatch(/\.\.\.$/);
126-
127-
// name should preserve full label
123+
// Both x and name should contain the full label
124+
expect(longLabelItem.x).toBe(longLabelItem.name);
128125
expect(longLabelItem.name).toContain(
129126
'extra extra extra extra extra extra extra'
130127
);
131128
});
132129

133-
it('preserves labels shorter than 30 characters', () => {
130+
it('preserves all labels as-is', () => {
134131
const result = getDonutChartConfig({
135132
data: inputData,
136133
onclick: jest.fn(),
@@ -139,9 +136,7 @@ describe('getDonutChartConfig', () => {
139136
});
140137

141138
result.data.forEach(item => {
142-
if (item.name.length <= 30) {
143-
expect(item.x).toBe(item.name);
144-
}
139+
expect(item.x).toBe(item.name);
145140
});
146141
});
147142

@@ -252,8 +247,8 @@ describe('getDonutChartConfig', () => {
252247
id: 'test-id',
253248
});
254249

255-
const label1 = result.labels({ datum: { x: 'Item 1', y: 40 } });
256-
const label2 = result.labels({ datum: { x: 'Item 2', y: 60 } });
250+
const label1 = result.labels({ datum: { x: 'Item 1', y: 40, name: 'Item 1' } });
251+
const label2 = result.labels({ datum: { x: 'Item 2', y: 60, name: 'Item 2' } });
257252

258253
expect(label1).toBe('Item 1: 40.0%');
259254
expect(label2).toBe('Item 2: 60.0%');

0 commit comments

Comments
 (0)