mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-17 13:51:10 +00:00
Compare commits
1 Commits
main
...
fix/alert-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5887dab7dc |
@@ -105,8 +105,3 @@
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.error {
|
||||
font-size: var(--font-size-xs);
|
||||
color: var(--danger-foreground);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ interface Props {
|
||||
query: string;
|
||||
grammar: DslGrammar;
|
||||
// Ids: `${testIdPrefix}-search-zone`, `-list-search*`, `-filter-zone`,
|
||||
// `-filter-clear`, `-filter-created-by`, `-filter-updated`, `-query-error`.
|
||||
// `-filter-clear`, `-filter-created-by`, `-filter-updated`.
|
||||
testIdPrefix: string;
|
||||
creatorOptions: CreatorOption[];
|
||||
source: SuggestionSource;
|
||||
@@ -35,8 +35,6 @@ interface Props {
|
||||
hasExtraFilters?: boolean;
|
||||
// Called by Clear after it empties the query.
|
||||
onClearAll?: () => void;
|
||||
// Shown under the search row.
|
||||
error?: string;
|
||||
// Wraps the search box and the filter controls (e.g. in an authz tooltip).
|
||||
wrapControl?: (node: ReactElement) => ReactElement;
|
||||
onSubmitted?: (hasQuery: boolean) => void;
|
||||
@@ -65,7 +63,6 @@ function FilterZone({
|
||||
extraFilters,
|
||||
hasExtraFilters = false,
|
||||
onClearAll,
|
||||
error,
|
||||
wrapControl = identity,
|
||||
onSubmitted,
|
||||
onFilterApplied,
|
||||
@@ -115,14 +112,6 @@ function FilterZone({
|
||||
)}
|
||||
{rightSlot}
|
||||
</div>
|
||||
{error && (
|
||||
<Typography.Text
|
||||
className={styles.error}
|
||||
testId={`${testIdPrefix}-query-error`}
|
||||
>
|
||||
{error}
|
||||
</Typography.Text>
|
||||
)}
|
||||
<div className={styles.filtersRow}>
|
||||
<Typography.Text className={styles.filtersLabel}>Filters</Typography.Text>
|
||||
{wrapControl(
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
.wrapper {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 320px;
|
||||
margin-top: 16px;
|
||||
padding: 105px 141px;
|
||||
gap: 4px;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
border-radius: 6px;
|
||||
border: 1px dashed var(--l1-border);
|
||||
}
|
||||
|
||||
.img {
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
.text {
|
||||
font-family: Inter;
|
||||
font-size: var(--font-size-sm);
|
||||
font-style: normal;
|
||||
line-height: 18px;
|
||||
letter-spacing: -0.07px;
|
||||
}
|
||||
|
||||
.title {
|
||||
composes: text;
|
||||
color: var(--l1-foreground);
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
|
||||
.detail {
|
||||
composes: text;
|
||||
color: var(--l2-foreground);
|
||||
font-weight: var(--font-weight-normal);
|
||||
}
|
||||
|
||||
.actionButtons {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
align-items: center;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.learnMoreArrow {
|
||||
margin-left: -20px;
|
||||
color: var(--bg-robin-400);
|
||||
cursor: pointer;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
import { Button } from '@signozhq/ui/button';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import { ArrowUpRight } from '@signozhq/icons';
|
||||
import { handleContactSupport } from 'container/Integrations/utils';
|
||||
|
||||
import awwSnapUrl from '@/assets/Icons/awwSnap.svg';
|
||||
|
||||
import { formatQueryErrorMessage } from './utils';
|
||||
import styles from './InvalidQueryState.module.scss';
|
||||
|
||||
interface Props {
|
||||
/** The backend's parse error for the list's DSL filter. */
|
||||
errorMessage?: string;
|
||||
isCloudUser: boolean;
|
||||
testIdPrefix: string;
|
||||
/** Runs before support opens, for analytics. */
|
||||
onContactSupport?: () => void;
|
||||
}
|
||||
|
||||
const INVALID_QUERY_FALLBACK = 'Please review the syntax and try again.';
|
||||
|
||||
function InvalidQueryState({
|
||||
errorMessage,
|
||||
isCloudUser,
|
||||
testIdPrefix,
|
||||
onContactSupport,
|
||||
}: Props): JSX.Element {
|
||||
const handleContactSupportClick = (): void => {
|
||||
onContactSupport?.();
|
||||
handleContactSupport(isCloudUser);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.wrapper} data-testid={`${testIdPrefix}-invalid-query`}>
|
||||
<img src={awwSnapUrl} alt="something went wrong" className={styles.img} />
|
||||
<Typography.Text
|
||||
className={styles.title}
|
||||
data-testid={`${testIdPrefix}-invalid-query-title`}
|
||||
>
|
||||
Invalid query
|
||||
</Typography.Text>
|
||||
<Typography.Text
|
||||
className={styles.detail}
|
||||
data-testid={`${testIdPrefix}-invalid-query-detail`}
|
||||
>
|
||||
{formatQueryErrorMessage(errorMessage) || INVALID_QUERY_FALLBACK}
|
||||
</Typography.Text>
|
||||
<section className={styles.actionButtons}>
|
||||
<Button
|
||||
size="md"
|
||||
variant="link"
|
||||
color="primary"
|
||||
onClick={handleContactSupportClick}
|
||||
testId={`${testIdPrefix}-contact-support`}
|
||||
>
|
||||
Contact Support
|
||||
</Button>
|
||||
<ArrowUpRight size={16} className={styles.learnMoreArrow} />
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default InvalidQueryState;
|
||||
@@ -0,0 +1,53 @@
|
||||
import { handleContactSupport } from 'container/Integrations/utils';
|
||||
import { render, screen, userEvent } from 'tests/test-utils';
|
||||
|
||||
import InvalidQueryState from '../InvalidQueryState';
|
||||
|
||||
jest.mock('container/Integrations/utils', () => ({
|
||||
handleContactSupport: jest.fn(),
|
||||
}));
|
||||
|
||||
describe('InvalidQueryState', () => {
|
||||
it('shows the backend message without its prefix and with quoted hints', () => {
|
||||
render(
|
||||
<InvalidQueryState
|
||||
errorMessage="invalid filter query: unknown field `nme`"
|
||||
isCloudUser={false}
|
||||
testIdPrefix="list"
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('list-invalid-query-title')).toHaveTextContent(
|
||||
'Invalid query',
|
||||
);
|
||||
expect(screen.getByTestId('list-invalid-query-detail')).toHaveTextContent(
|
||||
/^unknown field "nme"$/,
|
||||
);
|
||||
});
|
||||
|
||||
it('falls back to a syntax hint without a message', () => {
|
||||
render(<InvalidQueryState isCloudUser={false} testIdPrefix="list" />);
|
||||
|
||||
expect(screen.getByTestId('list-invalid-query-detail')).toHaveTextContent(
|
||||
'Please review the syntax and try again.',
|
||||
);
|
||||
});
|
||||
|
||||
it('runs the callback, then opens support', async () => {
|
||||
const user = userEvent.setup({ pointerEventsCheck: 0 });
|
||||
const onContactSupport = jest.fn();
|
||||
render(
|
||||
<InvalidQueryState
|
||||
errorMessage="bad"
|
||||
isCloudUser
|
||||
testIdPrefix="list"
|
||||
onContactSupport={onContactSupport}
|
||||
/>,
|
||||
);
|
||||
|
||||
await user.click(screen.getByTestId('list-contact-support'));
|
||||
|
||||
expect(onContactSupport).toHaveBeenCalledTimes(1);
|
||||
expect(jest.mocked(handleContactSupport)).toHaveBeenCalledWith(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
// Normalize BE query-parse error messages for display:
|
||||
// - Drop the "invalid filter query:" prefix (the UI already says "Invalid query").
|
||||
// - Backticks → double quotes for the format hint that follows the em-dash.
|
||||
// - Trim surrounding whitespace.
|
||||
export const formatQueryErrorMessage = (raw: string | undefined): string => {
|
||||
if (!raw) {
|
||||
return '';
|
||||
}
|
||||
return raw
|
||||
.replace(/^invalid filter query:\s*/i, '')
|
||||
.replace(/`([^`]+)`/g, '"$1"')
|
||||
.trim();
|
||||
};
|
||||
@@ -194,7 +194,7 @@ describe('ListAlertRules — search', () => {
|
||||
});
|
||||
|
||||
it.each(['rule_list_filter_invalid', 'rule_list_invalid'])(
|
||||
'shows the backend message and no-results state for %s',
|
||||
'shows the invalid query state with the backend message for %s',
|
||||
async (code) => {
|
||||
const user = userEvent.setup({ delay: null });
|
||||
server.use(
|
||||
@@ -219,12 +219,11 @@ describe('ListAlertRules — search', () => {
|
||||
await runSearchQuery(user, "nme = 'x'");
|
||||
|
||||
await expect(
|
||||
screen.findByTestId('alert-rules-query-error'),
|
||||
screen.findByTestId('alert-rules-invalid-query-detail'),
|
||||
).resolves.toHaveTextContent('unknown field "nme"');
|
||||
const empty = screen.getByTestId('no-results-empty-state');
|
||||
expect(within(empty).getByTestId('no-results-subtitle')).toHaveTextContent(
|
||||
'The filter query is invalid. Fix it or clear the search.',
|
||||
);
|
||||
expect(
|
||||
screen.queryByTestId('no-results-empty-state'),
|
||||
).not.toBeInTheDocument();
|
||||
expect(screen.queryByTestId('error-empty-state')).not.toBeInTheDocument();
|
||||
expect(screen.queryByText('High CPU Alert')).not.toBeInTheDocument();
|
||||
},
|
||||
|
||||
@@ -10,7 +10,6 @@ interface Props {
|
||||
states: string[];
|
||||
creatorOptions: CreatorOption[];
|
||||
source: SuggestionSource;
|
||||
error: string | null;
|
||||
onQueryChange: (query: string) => void;
|
||||
onStatesChange: (states: string[]) => void;
|
||||
}
|
||||
@@ -20,7 +19,6 @@ function AlertRulesFilterZone({
|
||||
states,
|
||||
creatorOptions,
|
||||
source,
|
||||
error,
|
||||
onQueryChange,
|
||||
onStatesChange,
|
||||
}: Props): JSX.Element {
|
||||
@@ -36,7 +34,6 @@ function AlertRulesFilterZone({
|
||||
extraFilters={<RuleStatesFilter states={states} onChange={onStatesChange} />}
|
||||
hasExtraFilters={states.length > 0}
|
||||
onClearAll={(): void => onStatesChange([])}
|
||||
error={error ?? undefined}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import ErrorEmptyState from 'components/Alerts/ErrorEmptyState';
|
||||
import NoResultsEmptyState from 'components/Alerts/NoResultsEmptyState';
|
||||
import InvalidQueryState from 'components/ListFilter/InvalidQueryState/InvalidQueryState';
|
||||
import ListCommandHeader from 'components/ListViews/ListCommandHeader/ListCommandHeader';
|
||||
import ListStatusBar from 'components/ListViews/ListStatusBar/ListStatusBar';
|
||||
import ViewsRail from 'components/ListViews/ViewsRail/ViewsRail';
|
||||
@@ -8,6 +9,7 @@ import TanStackTable from 'components/TanStackTableView';
|
||||
import { useCalculatedPageSize } from 'components/TanStackTableView/useCalculatedPageSize';
|
||||
import { useTableParams } from 'components/TanStackTableView/useTableParams';
|
||||
import useComponentPermission from 'hooks/useComponentPermission';
|
||||
import { useGetTenantLicense } from 'hooks/useGetTenantLicense';
|
||||
import { useAppContext } from 'providers/App/App';
|
||||
import { useTimezone } from 'providers/Timezone';
|
||||
|
||||
@@ -38,6 +40,7 @@ const DEFAULT_LIMIT = 10;
|
||||
|
||||
function ListAlertRules(): JSX.Element {
|
||||
const { user } = useAppContext();
|
||||
const { isCloudUser } = useGetTenantLicense();
|
||||
const [addNewAlert, action] = useComponentPermission(
|
||||
['add_new_alert', 'action'],
|
||||
user.role,
|
||||
@@ -199,7 +202,6 @@ function ListAlertRules(): JSX.Element {
|
||||
states={filter.states}
|
||||
creatorOptions={creatorOptions}
|
||||
source={source}
|
||||
error={queryError}
|
||||
onQueryChange={submitQuery}
|
||||
onStatesChange={changeStates}
|
||||
/>
|
||||
@@ -209,14 +211,16 @@ function ListAlertRules(): JSX.Element {
|
||||
<div ref={containerRef} className={styles.tableContainer}>
|
||||
{isError ? (
|
||||
<ErrorEmptyState title="Failed to load alert rules" onRefresh={refetch} />
|
||||
) : isEmptyDueToFilters && queryError ? (
|
||||
<InvalidQueryState
|
||||
errorMessage={queryError}
|
||||
isCloudUser={!!isCloudUser}
|
||||
testIdPrefix="alert-rules"
|
||||
/>
|
||||
) : isEmptyDueToFilters ? (
|
||||
<NoResultsEmptyState
|
||||
title="No matching alert rules"
|
||||
subtitle={
|
||||
queryError
|
||||
? 'The filter query is invalid. Fix it or clear the search.'
|
||||
: 'No alert rules match your search. Try adjusting your search criteria.'
|
||||
}
|
||||
subtitle="No alert rules match your search. Try adjusting your search criteria."
|
||||
onClear={handleClearFilters}
|
||||
clearButtonText="Clear Search"
|
||||
/>
|
||||
|
||||
@@ -139,7 +139,7 @@ export const alertRulesMocks = defineStoryMocks({
|
||||
invalidQuery: choiceControl<InvalidQueryChoice>('Invalid query', {
|
||||
group: LIST,
|
||||
description:
|
||||
'The 400 code any request carrying a `query` answers with. Both show the server message under the search box.',
|
||||
'The 400 code any request carrying a `query` answers with. Both replace the list with the Invalid query state and the server message.',
|
||||
options: INVALID_QUERY_CHOICES,
|
||||
value: 'off',
|
||||
}),
|
||||
|
||||
@@ -64,7 +64,7 @@ export const NoMatchingRules: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
/** The query the list was asked for does not parse: the server's message sits under the search box. */
|
||||
/** The query the list was asked for does not parse: the Invalid query state, with the server's message, replaces the list. */
|
||||
export const InvalidQuery: Story = {
|
||||
args: { invalidQuery: 'rule_list_filter_invalid' },
|
||||
parameters: {
|
||||
|
||||
@@ -14,12 +14,6 @@
|
||||
font-weight: var(--font-weight-medium);
|
||||
}
|
||||
|
||||
.errorDetail {
|
||||
composes: bodyText from '../states.module.scss';
|
||||
color: var(--l2-foreground);
|
||||
font-weight: var(--font-weight-normal);
|
||||
}
|
||||
|
||||
.actionButtons {
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
|
||||
@@ -2,12 +2,12 @@ import { Button } from '@signozhq/ui/button';
|
||||
import { Typography } from '@signozhq/ui/typography';
|
||||
import { ArrowUpRight, RotateCw } from '@signozhq/icons';
|
||||
import logEvent from 'api/common/logEvent';
|
||||
import InvalidQueryState from 'components/ListFilter/InvalidQueryState/InvalidQueryState';
|
||||
import { handleContactSupport } from 'container/Integrations/utils';
|
||||
import { DashboardListEvents } from 'pages/DashboardsListPage/constants/events';
|
||||
|
||||
import awwSnapUrl from '@/assets/Icons/awwSnap.svg';
|
||||
|
||||
import { formatQueryErrorMessage } from '../../../utils/helpers';
|
||||
import styles from './ErrorState.module.scss';
|
||||
|
||||
interface Props {
|
||||
@@ -19,7 +19,6 @@ interface Props {
|
||||
|
||||
const GENERIC_MESSAGE =
|
||||
'Something went wrong :/ Please retry or contact support.';
|
||||
const INVALID_QUERY_FALLBACK = 'Please review the syntax and try again.';
|
||||
|
||||
function ErrorState({
|
||||
isCloudUser,
|
||||
@@ -32,8 +31,6 @@ function ErrorState({
|
||||
const isClientError =
|
||||
httpStatus !== undefined && httpStatus >= 400 && httpStatus < 500;
|
||||
|
||||
const cleanedDetail = formatQueryErrorMessage(errorMessage);
|
||||
|
||||
const handleRetry = (): void => {
|
||||
void logEvent(DashboardListEvents.ErrorStateAction, {
|
||||
action: 'retry',
|
||||
@@ -41,45 +38,47 @@ function ErrorState({
|
||||
onRetry();
|
||||
};
|
||||
|
||||
const handleContactSupportClick = (): void => {
|
||||
const logContactSupport = (): void => {
|
||||
void logEvent(DashboardListEvents.ErrorStateAction, {
|
||||
action: 'contactSupport',
|
||||
});
|
||||
};
|
||||
|
||||
const handleContactSupportClick = (): void => {
|
||||
logContactSupport();
|
||||
handleContactSupport(isCloudUser);
|
||||
};
|
||||
|
||||
if (isClientError) {
|
||||
return (
|
||||
<InvalidQueryState
|
||||
errorMessage={errorMessage}
|
||||
isCloudUser={isCloudUser}
|
||||
testIdPrefix="dashboards-list"
|
||||
onContactSupport={logContactSupport}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={styles.wrapper}>
|
||||
<img src={awwSnapUrl} alt="something went wrong" className={styles.img} />
|
||||
|
||||
{isClientError ? (
|
||||
<>
|
||||
<Typography.Text className={styles.errorText}>
|
||||
Invalid query
|
||||
</Typography.Text>
|
||||
<Typography.Text className={styles.errorDetail}>
|
||||
{cleanedDetail || INVALID_QUERY_FALLBACK}
|
||||
</Typography.Text>
|
||||
</>
|
||||
) : (
|
||||
<Typography.Text className={styles.errorText}>
|
||||
{GENERIC_MESSAGE}
|
||||
</Typography.Text>
|
||||
)}
|
||||
<Typography.Text className={styles.errorText}>
|
||||
{GENERIC_MESSAGE}
|
||||
</Typography.Text>
|
||||
|
||||
<section className={styles.actionButtons}>
|
||||
{!isClientError && (
|
||||
<Button
|
||||
size="md"
|
||||
variant="outlined"
|
||||
color="secondary"
|
||||
prefix={<RotateCw size={16} />}
|
||||
onClick={handleRetry}
|
||||
testId="dashboards-list-retry"
|
||||
>
|
||||
Retry
|
||||
</Button>
|
||||
)}
|
||||
<Button
|
||||
size="md"
|
||||
variant="outlined"
|
||||
color="secondary"
|
||||
prefix={<RotateCw size={16} />}
|
||||
onClick={handleRetry}
|
||||
testId="dashboards-list-retry"
|
||||
>
|
||||
Retry
|
||||
</Button>
|
||||
<Button
|
||||
size="md"
|
||||
variant="link"
|
||||
|
||||
@@ -58,17 +58,3 @@ export const lastUpdatedLabel = (time: string | undefined): string => {
|
||||
const seconds = diff.diff(ref, 'seconds');
|
||||
return `Last Updated ${seconds} sec ago`;
|
||||
};
|
||||
|
||||
// Normalize BE query-parse error messages for display:
|
||||
// - Drop the "invalid filter query:" prefix (the UI already says "Invalid query").
|
||||
// - Backticks → double quotes for the format hint that follows the em-dash.
|
||||
// - Trim surrounding whitespace.
|
||||
export const formatQueryErrorMessage = (raw: string | undefined): string => {
|
||||
if (!raw) {
|
||||
return '';
|
||||
}
|
||||
return raw
|
||||
.replace(/^invalid filter query:\s*/i, '')
|
||||
.replace(/`([^`]+)`/g, '"$1"')
|
||||
.trim();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user