diff --git a/.changeset/cost-insights-fuzzy-boats-float.md b/.changeset/cost-insights-fuzzy-boats-float.md new file mode 100644 index 0000000000..c987363480 --- /dev/null +++ b/.changeset/cost-insights-fuzzy-boats-float.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-cost-insights': minor +--- + +support jsx in alert titles diff --git a/plugins/cost-insights/src/components/ActionItems/ActionItemCard.test.tsx b/plugins/cost-insights/src/components/ActionItems/ActionItemCard.test.tsx index 70ae44bcdc..b686076e17 100644 --- a/plugins/cost-insights/src/components/ActionItems/ActionItemCard.test.tsx +++ b/plugins/cost-insights/src/components/ActionItems/ActionItemCard.test.tsx @@ -43,4 +43,22 @@ describe('', () => { expect(rendered.getByText(alert.title)).toBeInTheDocument(); expect(rendered.getByText(alert.subtitle)).toBeInTheDocument(); }); + + it('renders custom title elements', async () => { + const rendered = await renderInTestApp( + + Foo, + subtitle: Bar, + }} + avatar={
1
} + /> +
, + ); + + expect(rendered.getByText('Foo')).toBeInTheDocument(); + expect(rendered.getByText('Bar')).toBeInTheDocument(); + }); }); diff --git a/plugins/cost-insights/src/components/AlertInsights/AlertInsightsSection.test.tsx b/plugins/cost-insights/src/components/AlertInsights/AlertInsightsSection.test.tsx index 093ca1ff0c..f9fe985e43 100644 --- a/plugins/cost-insights/src/components/AlertInsights/AlertInsightsSection.test.tsx +++ b/plugins/cost-insights/src/components/AlertInsights/AlertInsightsSection.test.tsx @@ -41,14 +41,33 @@ describe('', () => { onAccept={jest.fn()} />, ); - expect(getByText(mockAlert.title)).toBeInTheDocument(); - expect(getByText(mockAlert.subtitle)).toBeInTheDocument(); + expect(getByText(mockAlert.title as string)).toBeInTheDocument(); + expect(getByText(mockAlert.subtitle as string)).toBeInTheDocument(); expect(getByText('View Instructions')).toBeInTheDocument(); expect(queryByText('Snooze')).not.toBeInTheDocument(); expect(queryByText('Accept')).not.toBeInTheDocument(); expect(queryByText('Dismiss')).not.toBeInTheDocument(); }); + it('renders custom title elements', () => { + const { getByText } = renderInContext( + Foo, + subtitle: Bar, + }} + number={1} + onSnooze={jest.fn()} + onDismiss={jest.fn()} + onAccept={jest.fn()} + />, + ); + + expect(getByText('Foo')).toBeInTheDocument(); + expect(getByText('Bar')).toBeInTheDocument(); + }); + it('Hides instructions button if url is not provided', () => { const alert: Alert = { ...mockAlert, diff --git a/plugins/cost-insights/src/components/AlertInsights/AlertStatusSummary.test.tsx b/plugins/cost-insights/src/components/AlertInsights/AlertStatusSummary.test.tsx index ab39e0364e..754bc6db5c 100644 --- a/plugins/cost-insights/src/components/AlertInsights/AlertStatusSummary.test.tsx +++ b/plugins/cost-insights/src/components/AlertInsights/AlertStatusSummary.test.tsx @@ -50,8 +50,8 @@ describe('', () => { , ); [mockSnoozed, mockAccepted, mockDismissed].forEach(a => { - expect(getByText(a.title)).toBeInTheDocument(); - expect(getByText(a.subtitle)).toBeInTheDocument(); + expect(getByText(a.title as string)).toBeInTheDocument(); + expect(getByText(a.subtitle as string)).toBeInTheDocument(); expect(getByRole('img', { name: a.status })).toBeInTheDocument(); }); }); diff --git a/plugins/cost-insights/src/example/alerts/KubernetesMigrationAlert.tsx b/plugins/cost-insights/src/example/alerts/KubernetesMigrationAlert.tsx index 4878462f62..8b386f338c 100644 --- a/plugins/cost-insights/src/example/alerts/KubernetesMigrationAlert.tsx +++ b/plugins/cost-insights/src/example/alerts/KubernetesMigrationAlert.tsx @@ -17,6 +17,7 @@ import React from 'react'; import pluralize from 'pluralize'; import { KubernetesMigrationAlertCard } from '../components'; +import { Lifecycle } from '@backstage/core'; import { CostInsightsApi } from '../../api'; import { Alert, @@ -87,11 +88,13 @@ export class KubernetesMigrationAlert implements KubernetesMigrationApi { } get title() { - return `Consider migrating ${pluralize( - 'service', - this.data.services.length, - true, - )} to Kubernetes.`; + return ( + + Consider migrating{' '} + {pluralize('service', this.data.services.length, true)} to Kubernetes{' '} + + + ); } get element() { diff --git a/plugins/cost-insights/src/types/Alert.ts b/plugins/cost-insights/src/types/Alert.ts index 84c37a7c15..a8b041a67e 100644 --- a/plugins/cost-insights/src/types/Alert.ts +++ b/plugins/cost-insights/src/types/Alert.ts @@ -34,8 +34,8 @@ import { Maybe } from './Maybe'; */ export type Alert = { - title: string; - subtitle: string; + title: string | JSX.Element; + subtitle: string | JSX.Element; element?: JSX.Element; status?: AlertStatus; url?: string;