Skip to content

Commit 678b532

Browse files
chore: convert AlertStateBadge to use click-ui badge
1 parent 68082b6 commit 678b532

4 files changed

Lines changed: 65 additions & 22 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@hyperdx/app': patch
3+
---
4+
5+
feat: use the click-ui `Badge` for alert state badges. A fired alert shows a
6+
solid red badge, and an evaluation error shows a light red badge.

‎agent_docs/code_style.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,14 @@ Storybook and `renderWithMantine` in tests get the provider for free.
418418
`Badge`, `Separator`, `Spacer`, `Icon`). Import from `@clickhouse/click-ui`.
419419
- **Do not**: Mix both libraries inside one small component, and do not
420420
replace working Mantine code outside the change you were asked to make.
421+
- **`Container` is not a `Box`**: click-ui has no plain-wrapper equivalent of
422+
Mantine `Box`. `Container` is a flex layout, closer to `Group` or `Stack`. It
423+
defaults to `display="flex"`, `orientation="horizontal"`, and
424+
`alignItems="center"`, so a direct swap puts the children in one row. It also
425+
has no `m`/`p`/`w`-style props, only `gap` and `padding` tokens. To replace a
426+
`Box` that only carries attributes such as `id` or `data-testid`, use a plain
427+
HTML element. To replace a `Box` that uses Mantine style props, keep the
428+
`Box`, or set `Container` props to match the layout and check it visually.
421429
- **Styling**: click-ui styles live in the `clickui` CSS cascade layer, so any
422430
unlayered app or Mantine rule wins over them. Override `--click-*` variables
423431
outside the layer if a token must change.
Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
2+
import { Badge } from '@clickhouse/click-ui';
23
import { AlertState } from '@hyperdx/common-utils/dist/types';
3-
import { Badge } from '@mantine/core';
44

55
import { ALERT_STATE_LABELS } from '@/utils/alerts';
66

@@ -13,30 +13,14 @@ export function AlertStateBadge({ state }: AlertStateBadgeProps) {
1313

1414
switch (state) {
1515
case AlertState.ALERT:
16-
return (
17-
<Badge variant="light" color="red">
18-
{label}
19-
</Badge>
20-
);
16+
return <Badge text={label} state="danger" type="solid" />;
2117
case AlertState.PENDING:
22-
return (
23-
<Badge variant="light" color="orange">
24-
{label}
25-
</Badge>
26-
);
18+
return <Badge text={label} state="warning" />;
2719
case AlertState.ERROR:
28-
return (
29-
<Badge variant="outline" color="red">
30-
{label}
31-
</Badge>
32-
);
20+
return <Badge text={label} state="danger" />;
3321
case AlertState.OK:
34-
return <Badge variant="light">{label}</Badge>;
22+
return <Badge text={label} state="success" />;
3523
default:
36-
return (
37-
<Badge variant="light" color="gray">
38-
{label}
39-
</Badge>
40-
);
24+
return <Badge text={label} state="neutral" />;
4125
}
4226
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { AlertState } from '@hyperdx/common-utils/dist/types';
2+
import { screen } from '@testing-library/react';
3+
4+
import { AlertStateBadge } from '@/components/alerts/AlertStateBadge';
5+
6+
// click-ui encodes state and type only in hashed CSS module class names, so
7+
// the mock exposes the props as attributes to assert on.
8+
jest.mock('@clickhouse/click-ui', () => ({
9+
...jest.requireActual('@clickhouse/click-ui'),
10+
Badge: ({
11+
text,
12+
state,
13+
type,
14+
}: {
15+
text: React.ReactNode;
16+
state?: string;
17+
type?: string;
18+
}) => (
19+
<span data-testid="badge" data-state={state} data-type={type}>
20+
{text}
21+
</span>
22+
),
23+
}));
24+
25+
describe('AlertStateBadge', () => {
26+
it.each([
27+
[AlertState.ALERT, 'Alert', 'danger', 'solid'],
28+
[AlertState.PENDING, 'Pending', 'warning', undefined],
29+
[AlertState.ERROR, 'Error', 'danger', undefined],
30+
[AlertState.OK, 'Ok', 'success', undefined],
31+
[AlertState.DISABLED, 'Disabled', 'neutral', undefined],
32+
[AlertState.INSUFFICIENT_DATA, 'No data', 'neutral', undefined],
33+
])('renders %s with the %s label', (state, label, badgeState, badgeType) => {
34+
renderWithMantine(<AlertStateBadge state={state} />);
35+
36+
const badge = screen.getByTestId('badge');
37+
expect(badge).toHaveTextContent(label);
38+
expect(badge).toHaveAttribute('data-state', badgeState);
39+
if (badgeType) {
40+
expect(badge).toHaveAttribute('data-type', badgeType);
41+
} else {
42+
expect(badge).not.toHaveAttribute('data-type');
43+
}
44+
});
45+
});

0 commit comments

Comments
 (0)