diff --git a/.changeset/alert-state-badge-click-ui.md b/.changeset/alert-state-badge-click-ui.md new file mode 100644 index 0000000000..ffdf486db5 --- /dev/null +++ b/.changeset/alert-state-badge-click-ui.md @@ -0,0 +1,6 @@ +--- +'@hyperdx/app': patch +--- + +feat: use the click-ui `Badge` for alert state badges. A fired alert shows a +solid red badge, and an evaluation error shows a light red badge. diff --git a/agent_docs/code_style.md b/agent_docs/code_style.md index d1e9ff1aff..cc4b5ff14c 100644 --- a/agent_docs/code_style.md +++ b/agent_docs/code_style.md @@ -418,6 +418,14 @@ Storybook and `renderWithMantine` in tests get the provider for free. `Badge`, `Separator`, `Spacer`, `Icon`). Import from `@clickhouse/click-ui`. - **Do not**: Mix both libraries inside one small component, and do not replace working Mantine code outside the change you were asked to make. +- **`Container` is not a `Box`**: click-ui has no plain-wrapper equivalent of + Mantine `Box`. `Container` is a flex layout, closer to `Group` or `Stack`. It + defaults to `display="flex"`, `orientation="horizontal"`, and + `alignItems="center"`, so a direct swap puts the children in one row. It also + has no `m`/`p`/`w`-style props, only `gap` and `padding` tokens. To replace a + `Box` that only carries attributes such as `id` or `data-testid`, use a plain + HTML element. To replace a `Box` that uses Mantine style props, keep the + `Box`, or set `Container` props to match the layout and check it visually. - **Styling**: click-ui styles live in the `clickui` CSS cascade layer, so any unlayered app or Mantine rule wins over them. Override `--click-*` variables outside the layer if a token must change. diff --git a/packages/app/src/components/alerts/AlertStateBadge.tsx b/packages/app/src/components/alerts/AlertStateBadge.tsx index a514329a30..0eb0774194 100644 --- a/packages/app/src/components/alerts/AlertStateBadge.tsx +++ b/packages/app/src/components/alerts/AlertStateBadge.tsx @@ -1,6 +1,6 @@ import * as React from 'react'; +import { Badge } from '@clickhouse/click-ui'; import { AlertState } from '@hyperdx/common-utils/dist/types'; -import { Badge } from '@mantine/core'; import { ALERT_STATE_LABELS } from '@/utils/alerts'; @@ -13,30 +13,14 @@ export function AlertStateBadge({ state }: AlertStateBadgeProps) { switch (state) { case AlertState.ALERT: - return ( - - {label} - - ); + return ; case AlertState.PENDING: - return ( - - {label} - - ); + return ; case AlertState.ERROR: - return ( - - {label} - - ); + return ; case AlertState.OK: - return {label}; + return ; default: - return ( - - {label} - - ); + return ; } } diff --git a/packages/app/src/components/alerts/__tests__/AlertStateBadge.test.tsx b/packages/app/src/components/alerts/__tests__/AlertStateBadge.test.tsx new file mode 100644 index 0000000000..61bd976c91 --- /dev/null +++ b/packages/app/src/components/alerts/__tests__/AlertStateBadge.test.tsx @@ -0,0 +1,45 @@ +import { AlertState } from '@hyperdx/common-utils/dist/types'; +import { screen } from '@testing-library/react'; + +import { AlertStateBadge } from '@/components/alerts/AlertStateBadge'; + +// click-ui encodes state and type only in hashed CSS module class names, so +// the mock exposes the props as attributes to assert on. +jest.mock('@clickhouse/click-ui', () => ({ + ...jest.requireActual('@clickhouse/click-ui'), + Badge: ({ + text, + state, + type, + }: { + text: React.ReactNode; + state?: string; + type?: string; + }) => ( + + {text} + + ), +})); + +describe('AlertStateBadge', () => { + it.each([ + [AlertState.ALERT, 'Alert', 'danger', 'solid'], + [AlertState.PENDING, 'Pending', 'warning', undefined], + [AlertState.ERROR, 'Error', 'danger', undefined], + [AlertState.OK, 'Ok', 'success', undefined], + [AlertState.DISABLED, 'Disabled', 'neutral', undefined], + [AlertState.INSUFFICIENT_DATA, 'No data', 'neutral', undefined], + ])('renders %s with the %s label', (state, label, badgeState, badgeType) => { + renderWithMantine(); + + const badge = screen.getByTestId('badge'); + expect(badge).toHaveTextContent(label); + expect(badge).toHaveAttribute('data-state', badgeState); + if (badgeType) { + expect(badge).toHaveAttribute('data-type', badgeType); + } else { + expect(badge).not.toHaveAttribute('data-type'); + } + }); +});