Skip to content

RHDHBUGS-3045 Scorecard: Display correct legend for average aggregation - #3147

Merged
imykhno merged 3 commits into
redhat-developer:mainfrom
imykhno:fix/legend-for-average-aggregation
May 15, 2026
Merged

RHDHBUGS-3045 Scorecard: Display correct legend for average aggregation#3147
imykhno merged 3 commits into
redhat-developer:mainfrom
imykhno:fix/legend-for-average-aggregation

Conversation

@imykhno

@imykhno imykhno commented May 14, 2026

Copy link
Copy Markdown
Contributor

Hey, I just made a Pull Request!

This issue originated from the homepage widget for the Average aggregation type card. The card features a chart with its own threshold color configuration, while the metric provider colors are also displayed in the legend. This can confuse users, as these colors may differ. The card was changed to the following:

Screenshot 2026-05-14 at 20 30 37

Fix for the:

✔️ Checklist

  • A changeset describing the change and affected packages. (more info)
  • Added or Updated documentation
  • Tests for new functionality and regression tests for bug fixes
  • Screenshots attached (for UI changes)

Signed-off-by: Ihor Mykhno <imykhno@redhat.com>
@rhdh-qodo-merge

rhdh-qodo-merge Bot commented May 14, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Remediation recommended

1. Status labels not localized ✓ Resolved 🐞 Bug ≡ Correctness
Description
DonutChartTooltipContent injects the status text by capitalizing the raw threshold key (e.g.,
"success" → "Success"), so non-English locales still show English status names inside an
otherwise-translated tooltip line. The codebase already has localized threshold labels (e.g.,
thresholds.success) and a fallback strategy, but the new tooltip bypasses it.
Code

workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx[R63-66]

+                {t('metric.averageCenterTooltipBreakdownRow', {
+                  count: row.count,
+                  status: row.name.charAt(0).toUpperCase() + row.name.slice(1),
+                  score: formatAggregationScoreDetail(row.score ?? 0),
Relevance

⭐⭐⭐ High

PR #2649 localized status keys via t('thresholds.*') with capitalization fallback; team prefers i18n
over raw keys.

PR-#2649

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The tooltip currently derives status from the raw rule key, while the codebase already has
localized threshold labels and a proven fallback pattern used elsewhere (legend). This makes the new
tooltip inconsistent and leaves status names untranslated for non-English locales.

workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx[57-67]
workspaces/scorecard/plugins/scorecard/src/components/Scorecard/CustomLegend.tsx[96-102]
workspaces/scorecard/plugins/scorecard/src/translations/ref.ts[168-172]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The per-status breakdown rows in the Average card center tooltip use a manually-capitalized `row.name` for `status`, which leaves status names untranslated in non-English locales.

## Issue Context
The app already provides localized threshold labels under `thresholds.<ruleKey>` and uses a fallback-to-capitalization strategy in the legend; the tooltip should reuse the same approach.

## Fix Focus Areas
- workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx[57-69]
- workspaces/scorecard/plugins/scorecard/src/components/Scorecard/CustomLegend.tsx[96-102]
- workspaces/scorecard/plugins/scorecard/src/translations/ref.ts[168-172]

## Suggested change
- Replace `row.name.charAt(0)...` with a translated label:
 - `const translated = t(`thresholds.${row.name}` as any, {});`
 - If `translated === `thresholds.${row.name}``, fallback to capitalized `row.name`
 - Pass that result as `status` into `t('metric.averageCenterTooltipBreakdownRow', { ... })`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Missing score shown as 0 🐞 Bug ≡ Correctness
Description
DonutChartTooltipContent converts an absent per-status row.score into 0 via row.score ?? 0,
which misrepresents missing data as an actual zero score. AggregatedMetricValue.score is optional
and the existing formatter already renders undefined values as an em-dash.
Code

workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx[R66-67]

+                  score: formatAggregationScoreDetail(row.score ?? 0),
+                } as any)}
Relevance

⭐⭐ Medium

No direct history on score undefined vs 0, but formatter already outputs em-dash; could be accepted.

PR-#2923

ⓘ Recommendations generated based on similar findings in past PRs

Evidence
The API type explicitly allows score to be absent, and the formatter is designed to render missing
values as ; coalescing to 0 defeats that and can mislead users.

workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx[63-67]
workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/TooltipContent.tsx[20-34]
workspaces/scorecard/plugins/scorecard-common/src/types/aggregation.ts[30-35]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The tooltip breakdown line forces `row.score` to `0` when it is missing (`row.score ?? 0`), which changes semantics from “unknown/missing” to “zero”.

## Issue Context
- `AggregatedMetricValue.score` is optional.
- `formatAggregationScoreDetail` already returns `—` for undefined/non-finite values.

## Fix Focus Areas
- workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx[63-67]
- workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/TooltipContent.tsx[20-34]
- workspaces/scorecard/plugins/scorecard-common/src/types/aggregation.ts[30-35]

## Suggested change
- Change:
 - `score: formatAggregationScoreDetail(row.score ?? 0)`
- To:
 - `score: formatAggregationScoreDetail(row.score)`
so missing scores render as `—` instead of `0`.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

@rhdh-gh-app

rhdh-gh-app Bot commented May 14, 2026

Copy link
Copy Markdown

Changed Packages

Package Name Package Path Changeset Bump Current Version
app-legacy workspaces/scorecard/packages/app-legacy none v0.0.0
@red-hat-developer-hub/backstage-plugin-scorecard workspaces/scorecard/plugins/scorecard patch v2.7.4

@rhdh-qodo-merge

Copy link
Copy Markdown

Review Summary by Qodo

Fix average card tooltip to show breakdown in center donut instead of legend

🐞 Bug fix ✨ Enhancement

Grey Divider

Walkthroughs

Description
• Replaced side-legend tooltips with center donut tooltip breakdown
• Added per-status breakdown rows in center tooltip showing count and score
• Removed status pie chart and legend from average card component
• Added new translation keys for center tooltip breakdown across 7 languages
• Updated e2e tests to verify center tooltip instead of legend tooltips
Diagram
flowchart LR
  A["Average Card Component"] -->|removed| B["Status Pie Chart"]
  A -->|removed| C["Legend Tooltips"]
  A -->|added| D["Center Donut Tooltip"]
  D -->|displays| E["Total Score"]
  D -->|displays| F["Max Possible Score"]
  D -->|displays| G["Per-Status Breakdown"]
  G -->|shows| H["Status, Count, Score"]
Loading

Grey Divider

File Changes

1. workspaces/scorecard/packages/app-legacy/e2e-tests/scorecard.test.ts 🧪 Tests +2/-3

Updated test to verify center tooltip breakdown

workspaces/scorecard/packages/app-legacy/e2e-tests/scorecard.test.ts


2. workspaces/scorecard/packages/app-legacy/e2e-tests/utils/averageCardAssertions.ts 🧪 Tests +51/-34

Replaced legend tooltip test with center tooltip test

workspaces/scorecard/packages/app-legacy/e2e-tests/utils/averageCardAssertions.ts


3. workspaces/scorecard/plugins/scorecard/src/translations/de.ts Translations +4/-0

Added German translations for center tooltip breakdown

workspaces/scorecard/plugins/scorecard/src/translations/de.ts


View more (14)
4. workspaces/scorecard/plugins/scorecard/src/translations/es.ts Translations +4/-0

Added Spanish translations for center tooltip breakdown

workspaces/scorecard/plugins/scorecard/src/translations/es.ts


5. workspaces/scorecard/plugins/scorecard/src/translations/fr.ts Translations +4/-0

Added French translations for center tooltip breakdown

workspaces/scorecard/plugins/scorecard/src/translations/fr.ts


6. workspaces/scorecard/plugins/scorecard/src/translations/it.ts Translations +4/-0

Added Italian translations for center tooltip breakdown

workspaces/scorecard/plugins/scorecard/src/translations/it.ts


7. workspaces/scorecard/plugins/scorecard/src/translations/ja.ts Translations +4/-0

Added Japanese translations for center tooltip breakdown

workspaces/scorecard/plugins/scorecard/src/translations/ja.ts


8. workspaces/scorecard/plugins/scorecard/src/translations/ref.ts Translations +4/-0

Added reference translations for center tooltip breakdown

workspaces/scorecard/plugins/scorecard/src/translations/ref.ts


9. workspaces/scorecard/.changeset/sharp-mangos-build.md 📝 Documentation +5/-0

Created changeset for average card tooltip fix

workspaces/scorecard/.changeset/sharp-mangos-build.md


10. workspaces/scorecard/plugins/scorecard/README.md 📝 Documentation +2/-0

Documented average card center donut tooltip behavior

workspaces/scorecard/plugins/scorecard/README.md


11. workspaces/scorecard/plugins/scorecard/report-alpha.api.md 📝 Documentation +2/-0

Updated API report with new translation keys

workspaces/scorecard/plugins/scorecard/report-alpha.api.md


12. workspaces/scorecard/plugins/scorecard/report.api.md 📝 Documentation +2/-0

Updated API report with new translation keys

workspaces/scorecard/plugins/scorecard/report.api.md


13. workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/AverageCardComponent.tsx 🐞 Bug fix +2/-55

Removed status pie chart and legend, kept center tooltip

workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/AverageCardComponent.tsx


14. workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/AverageCardPieCenterLabel.tsx 🐞 Bug fix +1/-6

Removed legend tooltip state management from center label

workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/AverageCardPieCenterLabel.tsx


15. workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx ✨ Enhancement +43/-10

Enhanced tooltip with per-status breakdown rows display

workspaces/scorecard/plugins/scorecard/src/components/AggregatedMetricCards/AverageCard/DonutChartTooltipContent.tsx


16. workspaces/scorecard/plugins/scorecard/src/components/ScorecardHomepageSection/ResponsivePieChart.tsx ✨ Enhancement +15/-12

Made legend optional and adjusted pie chart positioning

workspaces/scorecard/plugins/scorecard/src/components/ScorecardHomepageSection/ResponsivePieChart.tsx


17. workspaces/scorecard/plugins/scorecard/src/components/ScorecardHomepageSection/__tests__/ScorecardHomepageCard.test.tsx 🧪 Tests +5/-3

Updated mock to handle optional legend content

workspaces/scorecard/plugins/scorecard/src/components/ScorecardHomepageSection/tests/ScorecardHomepageCard.test.tsx


Grey Divider

Qodo Logo

@rhdh-qodo-merge rhdh-qodo-merge Bot added documentation Improvements or additions to documentation bug_fix Tests labels May 14, 2026
@codecov

codecov Bot commented May 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 21.05263% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.01%. Comparing base (8d71b85) to head (c7d08be).
⚠️ Report is 6 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3147      +/-   ##
==========================================
- Coverage   61.02%   61.01%   -0.02%     
==========================================
  Files        2084     2084              
  Lines       64523    64522       -1     
  Branches    16873    16875       +2     
==========================================
- Hits        39375    39365      -10     
- Misses      24861    24870       +9     
  Partials      287      287              
Flag Coverage Δ *Carryforward flag
adoption-insights 83.58% <ø> (ø) Carriedforward from 4e24d81
ai-integrations 70.03% <ø> (ø) Carriedforward from 4e24d81
app-defaults 69.60% <ø> (ø) Carriedforward from 4e24d81
augment 69.36% <ø> (ø) Carriedforward from 4e24d81
bulk-import 72.86% <ø> (ø) Carriedforward from 4e24d81
cost-management 16.49% <ø> (ø) Carriedforward from 4e24d81
dcm 32.85% <ø> (ø) Carriedforward from 4e24d81
extensions 61.79% <ø> (ø) Carriedforward from 4e24d81
global-floating-action-button 73.75% <ø> (ø) Carriedforward from 4e24d81
global-header 61.68% <ø> (ø) Carriedforward from 4e24d81
homepage 50.84% <ø> (ø) Carriedforward from 4e24d81
konflux 91.01% <ø> (ø) Carriedforward from 4e24d81
lightspeed 68.21% <ø> (ø) Carriedforward from 4e24d81
mcp-integrations 81.59% <ø> (ø) Carriedforward from 4e24d81
orchestrator 35.14% <ø> (ø) Carriedforward from 4e24d81
quickstart 62.64% <ø> (ø) Carriedforward from 4e24d81
sandbox 79.56% <ø> (ø) Carriedforward from 4e24d81
scorecard 83.55% <21.05%> (-0.28%) ⬇️
theme 64.54% <ø> (ø) Carriedforward from 4e24d81
translations 8.49% <ø> (ø) Carriedforward from 4e24d81
x2a 82.16% <ø> (ø) Carriedforward from 4e24d81

*This pull request uses carry forward flags. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8d71b85...c7d08be. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Eswaraiahsapram Eswaraiahsapram left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @imykhno, tested in local. Looks good to me.

However, there was a minor suggestion that needs to be addressed before this can be merged.

Image Image

imykhno added 2 commits May 15, 2026 12:19
Signed-off-by: Ihor Mykhno <imykhno@redhat.com>
Signed-off-by: Ihor Mykhno <imykhno@redhat.com>
@sonarqubecloud

Copy link
Copy Markdown

@Eswaraiahsapram Eswaraiahsapram left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @imykhno, tested locally. 🎉

/lgtm

@openshift-ci openshift-ci Bot added the lgtm label May 15, 2026
@imykhno
imykhno merged commit 942a9ae into redhat-developer:main May 15, 2026
62 checks passed
@imykhno
imykhno deleted the fix/legend-for-average-aggregation branch May 15, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug_fix documentation Improvements or additions to documentation lgtm Tests workspace/scorecard

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants