Skip to content

Commit ff005a3

Browse files
fix(scorecard): add translation for status column in scorecard entities table (#2649)
1 parent 6bd7c38 commit ff005a3

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-scorecard': patch
3+
---
4+
5+
add translation for the scorecard entities table status column

workspaces/scorecard/plugins/scorecard/src/components/ScorecardPage/EntitiesTable/cells/MetricStatusCell.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,16 @@
1717
import { memo } from 'react';
1818

1919
import Box from '@mui/material/Box';
20+
import { useTranslation } from '../../../../hooks/useTranslation';
2021

2122
export const MetricStatusCell = memo(
2223
({ status, theme }: { status: string | undefined; theme: any }) => {
24+
const { t } = useTranslation();
25+
26+
let translatedStatus = t(`thresholds.${status}` as any, {});
27+
if (translatedStatus === `thresholds.${status}` && status) {
28+
translatedStatus = status?.charAt(0).toUpperCase() + status?.slice(1);
29+
}
2330
return (
2431
<Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>
2532
<Box
@@ -32,7 +39,7 @@ export const MetricStatusCell = memo(
3239
flexShrink: 0,
3340
}}
3441
/>
35-
{status || '--'}
42+
{(status && translatedStatus) || '--'}
3643
</Box>
3744
);
3845
},

workspaces/scorecard/plugins/scorecard/src/components/ScorecardPage/EntitiesTable/cells/__tests__/MetricStatusCell.test.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('MetricStatusCell', () => {
3737
</ThemeProvider>,
3838
);
3939

40-
expect(screen.getByText('success')).toBeInTheDocument();
40+
expect(screen.getByText('Success')).toBeInTheDocument();
4141
});
4242

4343
it('should render -- when status is empty string', () => {
@@ -68,6 +68,34 @@ describe('MetricStatusCell', () => {
6868
</ThemeProvider>,
6969
);
7070

71-
expect(screen.getByText('customStatus')).toBeInTheDocument();
71+
expect(screen.getByText('CustomStatus')).toBeInTheDocument();
72+
});
73+
74+
it('should render translated label for known threshold statuses', () => {
75+
const { rerender } = render(
76+
<ThemeProvider theme={theme}>
77+
<MetricStatusCell status="warning" theme={theme} />
78+
</ThemeProvider>,
79+
);
80+
81+
expect(screen.getByText('Warning')).toBeInTheDocument();
82+
83+
rerender(
84+
<ThemeProvider theme={theme}>
85+
<MetricStatusCell status="error" theme={theme} />
86+
</ThemeProvider>,
87+
);
88+
89+
expect(screen.getByText('Error')).toBeInTheDocument();
90+
});
91+
92+
it('should capitalise unknown status when no translation key matches', () => {
93+
render(
94+
<ThemeProvider theme={theme}>
95+
<MetricStatusCell status="pending" theme={theme} />
96+
</ThemeProvider>,
97+
);
98+
99+
expect(screen.getByText('Pending')).toBeInTheDocument();
72100
});
73101
});

0 commit comments

Comments
 (0)