Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/alert-state-badge-click-ui.md
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 8 additions & 0 deletions agent_docs/code_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
28 changes: 6 additions & 22 deletions packages/app/src/components/alerts/AlertStateBadge.tsx
Original file line number Diff line number Diff line change
@@ -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';

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

switch (state) {
case AlertState.ALERT:
return (
<Badge variant="light" color="red">
{label}
</Badge>
);
return <Badge text={label} state="danger" type="solid" />;
case AlertState.PENDING:
return (
<Badge variant="light" color="orange">
{label}
</Badge>
);
return <Badge text={label} state="warning" />;
case AlertState.ERROR:
return (
<Badge variant="outline" color="red">
{label}
</Badge>
);
return <Badge text={label} state="danger" />;
case AlertState.OK:
return <Badge variant="light">{label}</Badge>;
return <Badge text={label} state="success" />;
default:
return (
<Badge variant="light" color="gray">
{label}
</Badge>
);
return <Badge text={label} state="neutral" />;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}) => (
<span data-testid="badge" data-state={state} data-type={type}>
{text}
</span>
),
}));

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(<AlertStateBadge state={state} />);

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');
}
});
});
Loading