Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

fix(alerts-new): show tabs and breadcrumbs on create alert (#11316)

Vinicius Lourenço5419e8461cb2
diff --git a/frontend/src/AppRoutes/pageComponents.ts b/frontend/src/AppRoutes/pageComponents.ts
index b9b30a5b3b..26b74499bf 100644
--- a/frontend/src/AppRoutes/pageComponents.ts
+++ b/frontend/src/AppRoutes/pageComponents.ts
@@ -47,7 +47,6 @@ export const TracesFunnels = Loadable(
import(/* webpackChunkName: "Traces Funnels" */ 'pages/TracesModulePage'),
);
export const TracesFunnelDetails = Loadable(
- // eslint-disable-next-line sonarjs/no-identical-functions
() =>
import(
/* webpackChunkName: "Traces Funnel Details" */ 'pages/TracesModulePage'
@@ -313,13 +312,6 @@ export const PublicDashboardPage = Loadable(
),
);
-export const AlertTypeSelectionPage = Loadable(
- () =>
- import(
- /* webpackChunkName: "Alert Type Selection Page" */ 'pages/AlertTypeSelection'
- ),
-);
-
export const MeterExplorerPage = Loadable(
() =>
import(/* webpackChunkName: "Meter Explorer Page" */ 'pages/MeterExplorer'),
diff --git a/frontend/src/AppRoutes/routes.ts b/frontend/src/AppRoutes/routes.ts
index 563147222a..e0e0fdfc0f 100644
--- a/frontend/src/AppRoutes/routes.ts
+++ b/frontend/src/AppRoutes/routes.ts
@@ -5,7 +5,6 @@ import {
AIAssistantPage,
AlertHistory,
AlertOverview,
- AlertTypeSelectionPage,
AllAlertChannels,
AllErrors,
ApiMonitoring,
@@ -213,13 +212,6 @@ const routes: AppRoutes[] = [
isPrivate: true,
key: 'LIST_ALL_ALERT',
},
- {
- path: ROUTES.ALERT_TYPE_SELECTION,
- exact: true,
- component: AlertTypeSelectionPage,
- isPrivate: true,
- key: 'ALERT_TYPE_SELECTION',
- },
{
path: ROUTES.ALERTS_NEW,
exact: true,
@@ -533,18 +525,6 @@ export const LIST_LICENSES: AppRoutes = {
key: 'LIST_LICENSES',
};
-export const oldRoutes = [
- '/pipelines',
- '/logs-explorer',
- '/logs-explorer/live',
- '/logs-save-views',
- '/traces-save-views',
- '/settings/access-tokens',
- '/settings/api-keys',
- '/messaging-queues',
- '/alerts/edit',
-];
-
export const oldNewRoutesMapping: Record<string, string> = {
'/pipelines': '/logs/pipelines',
'/logs-explorer': '/logs/logs-explorer',
@@ -555,7 +535,9 @@ export const oldNewRoutesMapping: Record<string, string> = {
'/settings/api-keys': '/settings/service-accounts',
'/messaging-queues': '/messaging-queues/overview',
'/alerts/edit': '/alerts/overview',
+ '/alerts/type-selection': '/alerts/new',
};
+export const oldRoutes = Object.keys(oldNewRoutesMapping);
export const ROUTES_NOT_TO_BE_OVERRIDEN: string[] = [
ROUTES.WORKSPACE_LOCKED,
diff --git a/frontend/src/components/AlertBreadcrumb/AlertBreadcrumb.module.scss b/frontend/src/components/AlertBreadcrumb/AlertBreadcrumb.module.scss
new file mode 100644
index 0000000000..60807c37bf
--- /dev/null
+++ b/frontend/src/components/AlertBreadcrumb/AlertBreadcrumb.module.scss
@@ -0,0 +1,17 @@
+.breadcrumb {
+ padding-left: 16px;
+
+ ol {
+ align-items: center;
+ }
+
+ :global(.ant-breadcrumb-separator) {
+ color: var(--muted-foreground);
+ }
+}
+
+.divider {
+ border-color: var(--l1-border);
+ margin: 16px 0;
+ margin-top: 10px;
+}
diff --git a/frontend/src/components/AlertBreadcrumb/AlertBreadcrumb.tsx b/frontend/src/components/AlertBreadcrumb/AlertBreadcrumb.tsx
new file mode 100644
index 0000000000..e7ef3d4986
--- /dev/null
+++ b/frontend/src/components/AlertBreadcrumb/AlertBreadcrumb.tsx
@@ -0,0 +1,32 @@
+import { Breadcrumb, Divider } from 'antd';
+
+import styles from './AlertBreadcrumb.module.scss';
+import BreadcrumbItem, { BreadcrumbItemConfig } from './BreadcrumbItem';
+
+export interface AlertBreadcrumbProps {
+ items: BreadcrumbItemConfig[];
+ className?: string;
+ showDivider?: boolean;
+}
+
+function AlertBreadcrumb({
+ items,
+ className,
+ showDivider = true,
+}: AlertBreadcrumbProps): JSX.Element {
+ const breadcrumbItems = items.map((item) => ({
+ title: <BreadcrumbItem {...item} />,
+ }));
+
+ return (
+ <>
+ <Breadcrumb
+ className={`${styles.breadcrumb} ${className || ''}`}
+ items={breadcrumbItems}
+ />
+ {showDivider && <Divider className={styles.divider} />}
+ </>
+ );
+}
+
+export default AlertBreadcrumb;
diff --git a/frontend/src/components/AlertBreadcrumb/BreadcrumbItem.module.scss b/frontend/src/components/AlertBreadcrumb/BreadcrumbItem.module.scss
new file mode 100644
index 0000000000..1709824bcf
--- /dev/null
+++ b/frontend/src/components/AlertBreadcrumb/BreadcrumbItem.module.scss
@@ -0,0 +1,9 @@
+.item {
+ --button-padding: 0;
+ --button-font-size: var(--periscope-font-size-base);
+}
+
+.itemLast {
+ color: var(--muted-foreground);
+ font-size: var(--periscope-font-size-base);
+}
diff --git a/frontend/src/components/AlertBreadcrumb/BreadcrumbItem.tsx b/frontend/src/components/AlertBreadcrumb/BreadcrumbItem.tsx
new file mode 100644
index 0000000000..f40dd1bd8c
--- /dev/null
+++ b/frontend/src/components/AlertBreadcrumb/BreadcrumbItem.tsx
@@ -0,0 +1,45 @@
+import { Button } from '@signozhq/ui/button';
+import { useSafeNavigate } from 'hooks/useSafeNavigate';
+import { isModifierKeyPressed } from 'utils/app';
+
+import styles from './BreadcrumbItem.module.scss';
+
+export type BreadcrumbItemConfig =
+ | {
+ title: string | null;
+ route?: string;
+ }
+ | {
+ title: string | null;
+ isLast?: true;
+ };
+
+function BreadcrumbItem({
+ title,
+ ...props
+}: BreadcrumbItemConfig): JSX.Element {
+ const { safeNavigate } = useSafeNavigate();
+
+ if ('isLast' in props) {
+ return <div className={styles.itemLast}>{title}</div>;
+ }
+
+ return (
+ <Button
+ variant="ghost"
+ color="secondary"
+ className={styles.item}
+ onClick={(e: React.MouseEvent): void => {
+ if (!('route' in props) || !props.route) {
+ return;
+ }
+
+ safeNavigate(props.route, { newTab: isModifierKeyPressed(e) });
+ }}
+ >
+ {title}
+ </Button>
+ );
+}
+
+export default BreadcrumbItem;
diff --git a/frontend/src/components/AlertBreadcrumb/index.tsx b/frontend/src/components/AlertBreadcrumb/index.tsx
new file mode 100644
index 0000000000..f615c24042
--- /dev/null
+++ b/frontend/src/components/AlertBreadcrumb/index.tsx
@@ -0,0 +1,6 @@
+export { default } from './AlertBreadcrumb';
+export {
+ default as BreadcrumbItem,
+ type BreadcrumbItemConfig,
+} from './BreadcrumbItem';
+export type { AlertBreadcrumbProps } from './AlertBreadcrumb';
diff --git a/frontend/src/constants/routes.ts b/frontend/src/constants/routes.ts
index 8b77f43591..32fb7bde78 100644
--- a/frontend/src/constants/routes.ts
+++ b/frontend/src/constants/routes.ts
@@ -29,7 +29,6 @@ const ROUTES = {
ALERTS_NEW: '/alerts/new',
ALERT_HISTORY: '/alerts/history',
ALERT_OVERVIEW: '/alerts/overview',
- ALERT_TYPE_SELECTION: '/alerts/type-selection',
ALL_CHANNELS: '/settings/channels',
CHANNELS_NEW: '/settings/channels/new',
CHANNELS_EDIT: '/settings/channels/edit/:channelId',
diff --git a/frontend/src/container/CreateAlertRule/AlertRuleDocumentationRedirection.test.tsx b/frontend/src/container/CreateAlertRule/AlertRuleDocumentationRedirection.test.tsx
index c1abae6835..8d18d7bdf1 100644
--- a/frontend/src/container/CreateAlertRule/AlertRuleDocumentationRedirection.test.tsx
+++ b/frontend/src/container/CreateAlertRule/AlertRuleDocumentationRedirection.test.tsx
@@ -1,12 +1,23 @@
import ROUTES from 'constants/routes';
import * as usePrefillAlertConditions from 'container/FormAlertRules/usePrefillAlertConditions';
-import AlertTypeSelectionPage from 'pages/AlertTypeSelection';
import CreateAlertPage from 'pages/CreateAlert';
import { act, fireEvent, render } from 'tests/test-utils';
import { AlertTypes } from 'types/api/alerts/alertTypes';
import { ALERT_TYPE_TO_TITLE, ALERT_TYPE_URL_MAP } from './constants';
+jest.mock('react-router-dom-v5-compat', () => ({
+ ...jest.requireActual('react-router-dom-v5-compat'),
+ useNavigationType: jest.fn(() => 'PUSH'),
+ useLocation: jest.fn(() => ({
+ pathname: '/alerts/new',
+ search: '',
+ hash: '',
+ state: null,
+ })),
+ useSearchParams: jest.fn(() => [new URLSearchParams(), jest.fn()]),
+}));
+
jest
.spyOn(usePrefillAlertConditions, 'usePrefillAlertConditions')
.mockReturnValue({
@@ -54,20 +65,13 @@ describe('Alert rule documentation redirection', () => {
window.open = mockWindowOpen;
});
- jest.mock('react-router-dom', () => ({
- ...jest.requireActual('react-router-dom'),
- useLocation: (): { pathname: string } => ({
- pathname: `${process.env.FRONTEND_API_ENDPOINT}${ROUTES.ALERT_TYPE_SELECTION}`,
- }),
- }));
-
beforeEach(() => {
act(() => {
renderResult = render(
- <AlertTypeSelectionPage />,
+ <CreateAlertPage />,
{},
{
- initialRoute: ROUTES.ALERT_TYPE_SELECTION,
+ initialRoute: ROUTES.ALERTS_NEW,
},
);
});
diff --git a/frontend/src/container/CreateAlertRule/AnomalyAlertDocumentationRedirection.test.tsx b/frontend/src/container/CreateAlertRule/AnomalyAlertDocumentationRedirection.test.tsx
index c0a5634afb..fe798c6e03 100644
--- a/frontend/src/container/CreateAlertRule/AnomalyAlertDocumentationRedirection.test.tsx
+++ b/frontend/src/container/CreateAlertRule/AnomalyAlertDocumentationRedirection.test.tsx
@@ -15,6 +15,18 @@ jest.mock('react-router-dom', () => ({
}),
}));
+jest.mock('react-router-dom-v5-compat', () => ({
+ ...jest.requireActual('react-router-dom-v5-compat'),
+ useNavigationType: jest.fn(() => 'PUSH'),
+ useLocation: jest.fn(() => ({
+ pathname: '/alerts/new',
+ search: 'ruleType=anomaly_rule',
+ hash: '',
+ state: null,
+ })),
+ useSearchParams: jest.fn(() => [new URLSearchParams(), jest.fn()]),
+}));
+
window.ResizeObserver =
window.ResizeObserver ||
jest.fn().mockImplementation(() => ({
diff --git a/frontend/src/container/CreateAlertRule/CreateAlertRule.styles.scss b/frontend/src/container/CreateAlertRule/CreateAlertRule.styles.scss
new file mode 100644
index 0000000000..f9eb4d555a
--- /dev/null
+++ b/frontend/src/container/CreateAlertRule/CreateAlertRule.styles.scss
@@ -0,0 +1,75 @@
+.create-alert-tabs {
+ &__extra {
+ display: flex;
+ align-items: center;
+ gap: 16px;
+ }
+}
+
+.create-alert-wrapper {
+ margin-top: 10px;
+
+ .divider {
+ border-color: var(--l1-border);
+ margin: 16px 0;
+ }
+
+ .breadcrumb-divider {
+ margin-top: 10px;
+ }
+}
+
+.create-alert__breadcrumb {
+ padding-left: 16px;
+
+ ol {
+ align-items: center;
+ }
+
+ .breadcrumb-item {
+ color: var(--l2-foreground);
+ font-size: 14px;
+ line-height: 20px;
+ letter-spacing: 0.25px;
+ padding: 0;
+ }
+
+ .ant-breadcrumb-separator,
+ .breadcrumb-item--last {
+ color: var(--muted-foreground);
+ font-family: 'Geist Mono';
+ }
+}
+
+.alerts-container {
+ .top-level-tab.periscope-tab {
+ padding: 2px 0;
+ }
+
+ .ant-tabs {
+ &-nav {
+ padding: 0 8px;
+ margin-bottom: 0 !important;
+
+ &::before {
+ border-bottom: 1px solid var(--l1-border) !important;
+ }
+ }
+
+ &-tab {
+ &[data-node-key='TriggeredAlerts'] {
+ margin-left: 16px;
+ }
+
+ &:not(:first-of-type) {
+ margin-left: 24px !important;
+ }
+
+ [aria-selected='false'] {
+ .periscope-tab {
+ color: var(--l2-foreground);
+ }
+ }
+ }
+ }
+}
diff --git a/frontend/src/container/CreateAlertRule/SelectAlertType/__tests__/SelectAlertType.test.tsx b/frontend/src/container/CreateAlertRule/SelectAlertType/__tests__/SelectAlertType.test.tsx
new file mode 100644
index 0000000000..7fc924e3a3
--- /dev/null
+++ b/frontend/src/container/CreateAlertRule/SelectAlertType/__tests__/SelectAlertType.test.tsx
@@ -0,0 +1,111 @@
+import { fireEvent, render, screen } from '@testing-library/react';
+import { FeatureKeys } from 'constants/features';
+import { getAppContextMockState } from 'container/RoutingPolicies/__tests__/testUtils';
+import * as appHooks from 'providers/App/App';
+import { AlertTypes } from 'types/api/alerts/alertTypes';
+
+import SelectAlertType from '..';
+
+const useAppContextSpy = jest.spyOn(appHooks, 'useAppContext');
+
+describe('SelectAlertType', () => {
+ const mockOnSelect = jest.fn();
+
+ beforeEach(() => {
+ jest.clearAllMocks();
+ useAppContextSpy.mockReturnValue(getAppContextMockState());
+ });
+
+ it('should render all alert type options when anomaly detection is enabled', () => {
+ useAppContextSpy.mockReturnValue({
+ ...getAppContextMockState({}),
+ featureFlags: [
+ {
+ name: FeatureKeys.ANOMALY_DETECTION,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ ],
+ });
+
+ render(<SelectAlertType onSelect={mockOnSelect} />);
+
+ expect(screen.getByText('metric_based_alert')).toBeInTheDocument();
+ expect(screen.getByText('log_based_alert')).toBeInTheDocument();
+ expect(screen.getByText('traces_based_alert')).toBeInTheDocument();
+ expect(screen.getByText('exceptions_based_alert')).toBeInTheDocument();
+ expect(screen.getByText('anomaly_based_alert')).toBeInTheDocument();
+ });
+
+ it('should render all alert type options except anomaly based alert when anomaly detection is disabled', () => {
+ render(<SelectAlertType onSelect={mockOnSelect} />);
+
+ expect(screen.getByText('metric_based_alert')).toBeInTheDocument();
+ expect(screen.getByText('log_based_alert')).toBeInTheDocument();
+ expect(screen.getByText('traces_based_alert')).toBeInTheDocument();
+ expect(screen.getByText('exceptions_based_alert')).toBeInTheDocument();
+ expect(screen.queryByText('anomaly_based_alert')).not.toBeInTheDocument();
+ });
+
+ it('should call onSelect with metrics based alert type', () => {
+ render(<SelectAlertType onSelect={mockOnSelect} />);
+ fireEvent.click(screen.getByText('metric_based_alert'));
+
+ expect(mockOnSelect).toHaveBeenCalledWith(
+ AlertTypes.METRICS_BASED_ALERT,
+ false,
+ );
+ });
+
+ it('should call onSelect with anomaly based alert type', () => {
+ useAppContextSpy.mockReturnValue({
+ ...getAppContextMockState({}),
+ featureFlags: [
+ {
+ name: FeatureKeys.ANOMALY_DETECTION,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ ],
+ });
+
+ render(<SelectAlertType onSelect={mockOnSelect} />);
+ fireEvent.click(screen.getByText('anomaly_based_alert'));
+
+ expect(mockOnSelect).toHaveBeenCalledWith(
+ AlertTypes.ANOMALY_BASED_ALERT,
+ false,
+ );
+ });
+
+ it('should call onSelect with log based alert type', () => {
+ render(<SelectAlertType onSelect={mockOnSelect} />);
+ fireEvent.click(screen.getByText('log_based_alert'));
+
+ expect(mockOnSelect).toHaveBeenCalledWith(AlertTypes.LOGS_BASED_ALERT, false);
+ });
+
+ it('should call onSelect with traces based alert type', () => {
+ render(<SelectAlertType onSelect={mockOnSelect} />);
+ fireEvent.click(screen.getByText('traces_based_alert'));
+
+ expect(mockOnSelect).toHaveBeenCalledWith(
+ AlertTypes.TRACES_BASED_ALERT,
+ false,
+ );
+ });
+
+ it('should call onSelect with exceptions based alert type', () => {
+ render(<SelectAlertType onSelect={mockOnSelect} />);
+ fireEvent.click(screen.getByText('exceptions_based_alert'));
+
+ expect(mockOnSelect).toHaveBeenCalledWith(
+ AlertTypes.EXCEPTIONS_BASED_ALERT,
+ false,
+ );
+ });
+});
diff --git a/frontend/src/container/CreateAlertRule/__tests__/CreateAlertRule.test.tsx b/frontend/src/container/CreateAlertRule/__tests__/CreateAlertRule.test.tsx
index d9e1bf2c0b..bc1c9d2619 100644
--- a/frontend/src/container/CreateAlertRule/__tests__/CreateAlertRule.test.tsx
+++ b/frontend/src/container/CreateAlertRule/__tests__/CreateAlertRule.test.tsx
@@ -1,13 +1,37 @@
-import { render, screen } from '@testing-library/react';
+import { fireEvent, screen } from '@testing-library/react';
+import { FeatureKeys } from 'constants/features';
import { QueryParams } from 'constants/query';
import { initialQueriesMap } from 'constants/queryBuilder';
+import { getAppContextMockState } from 'container/RoutingPolicies/__tests__/testUtils';
import * as useCompositeQueryParamHooks from 'hooks/queryBuilder/useGetCompositeQueryParam';
+import * as navigateHooks from 'hooks/useSafeNavigate';
import * as useUrlQueryHooks from 'hooks/useUrlQuery';
+import * as appHooks from 'providers/App/App';
+import { render } from 'tests/test-utils';
import { AlertTypes } from 'types/api/alerts/alertTypes';
import { DataSource } from 'types/common/queryBuilder';
import CreateAlertRule from '../index';
+jest.mock('react-router-dom-v5-compat', () => ({
+ ...jest.requireActual('react-router-dom-v5-compat'),
+ useNavigationType: jest.fn(() => 'PUSH'),
+ useLocation: jest.fn(() => ({
+ pathname: '/alerts/new',
+ search: '',
+ hash: '',
+ state: null,
+ })),
+ useSearchParams: jest.fn(() => [new URLSearchParams(), jest.fn()]),
+}));
+
+jest.mock('container/TopNav/DateTimeSelectionV2', () => ({
+ __esModule: true,
+ default: function MockDateTimeSelector(): JSX.Element {
+ return <div data-testid="datetime-selector">Mock DateTime Selector</div>;
+ },
+}));
+
jest.mock('container/FormAlertRules', () => ({
__esModule: true,
default: function MockFormAlertRules({
@@ -48,10 +72,14 @@ const useCompositeQueryParamSpy = jest.spyOn(
'useGetCompositeQueryParam',
);
const useUrlQuerySpy = jest.spyOn(useUrlQueryHooks, 'default');
+const useSafeNavigateSpy = jest.spyOn(navigateHooks, 'useSafeNavigate');
+const useAppContextSpy = jest.spyOn(appHooks, 'useAppContext');
const mockSetUrlQuery = jest.fn();
const mockToString = jest.fn();
const mockGetUrlQuery = jest.fn();
+const mockSafeNavigate = jest.fn();
+const mockDeleteUrlQuery = jest.fn();
const FORM_ALERT_RULES_TEXT = 'Form Alert Rules';
const CREATE_ALERT_V2_TEXT = 'Create Alert V2';
@@ -63,8 +91,13 @@ describe('CreateAlertRule', () => {
set: mockSetUrlQuery,
toString: mockToString,
get: mockGetUrlQuery,
+ delete: mockDeleteUrlQuery,
} as Partial<URLSearchParams> as URLSearchParams);
useCompositeQueryParamSpy.mockReturnValue(initialQueriesMap.metrics);
+ useSafeNavigateSpy.mockReturnValue({
+ safeNavigate: mockSafeNavigate,
+ });
+ useAppContextSpy.mockReturnValue(getAppContextMockState());
});
it('should render classic flow when showClassicCreateAlertsPage is true', () => {
@@ -72,16 +105,51 @@ describe('CreateAlertRule', () => {
if (key === QueryParams.showClassicCreateAlertsPage) {
return 'true';
}
+ if (key === QueryParams.alertType) {
+ return AlertTypes.METRICS_BASED_ALERT;
+ }
return null;
});
render(<CreateAlertRule />);
expect(screen.getByText(FORM_ALERT_RULES_TEXT)).toBeInTheDocument();
});
- it('should render new flow by default', () => {
+ it('should render new flow when alertType is provided', () => {
+ mockGetUrlQuery.mockImplementation((key: string) => {
+ if (key === QueryParams.alertType) {
+ return AlertTypes.METRICS_BASED_ALERT;
+ }
+ return null;
+ });
+ render(<CreateAlertRule />);
+ expect(screen.getByText(CREATE_ALERT_V2_TEXT)).toBeInTheDocument();
+ });
+
+ it('should render type selection when no alertType in URL and no compositeQuery', () => {
mockGetUrlQuery.mockReturnValue(null);
+ useCompositeQueryParamSpy.mockReturnValue(null);
+ render(<CreateAlertRule />);
+ expect(screen.queryByText(FORM_ALERT_RULES_TEXT)).not.toBeInTheDocument();
+ expect(screen.queryByText(CREATE_ALERT_V2_TEXT)).not.toBeInTheDocument();
+ });
+
+ it('should skip type selection and render alert form when compositeQuery is present', () => {
+ mockGetUrlQuery.mockReturnValue(null);
+ useCompositeQueryParamSpy.mockReturnValue({
+ ...initialQueriesMap.metrics,
+ builder: {
+ ...initialQueriesMap.metrics.builder,
+ queryData: [
+ {
+ ...initialQueriesMap.metrics.builder.queryData[0],
+ dataSource: DataSource.METRICS,
+ },
+ ],
+ },
+ });
render(<CreateAlertRule />);
expect(screen.getByText(CREATE_ALERT_V2_TEXT)).toBeInTheDocument();
+ expect(screen.getByText(AlertTypes.METRICS_BASED_ALERT)).toBeInTheDocument();
});
it('should render classic flow when ruleType is anomaly_rule even if showClassicCreateAlertsPage is not true', () => {
@@ -111,8 +179,13 @@ describe('CreateAlertRule', () => {
expect(screen.getByText(AlertTypes.LOGS_BASED_ALERT)).toBeInTheDocument();
});
- it('should use alertType from compositeQuery dataSource when alertType is not in URL', () => {
- mockGetUrlQuery.mockReturnValue(null);
+ it('should use alertType from URL over compositeQuery dataSource', () => {
+ mockGetUrlQuery.mockImplementation((key: string) => {
+ if (key === QueryParams.alertType) {
+ return AlertTypes.LOGS_BASED_ALERT;
+ }
+ return null;
+ });
useCompositeQueryParamSpy.mockReturnValue({
...initialQueriesMap.metrics,
builder: {
@@ -127,14 +200,123 @@ describe('CreateAlertRule', () => {
});
render(<CreateAlertRule />);
expect(screen.getByText(CREATE_ALERT_V2_TEXT)).toBeInTheDocument();
- expect(screen.getByText(AlertTypes.TRACES_BASED_ALERT)).toBeInTheDocument();
+ expect(screen.getByText(AlertTypes.LOGS_BASED_ALERT)).toBeInTheDocument();
});
- it('should default to METRICS_BASED_ALERT when no alertType and no compositeQuery', () => {
- mockGetUrlQuery.mockReturnValue(null);
- useCompositeQueryParamSpy.mockReturnValue(null);
- render(<CreateAlertRule />);
- expect(screen.getByText(CREATE_ALERT_V2_TEXT)).toBeInTheDocument();
- expect(screen.getByText(AlertTypes.METRICS_BASED_ALERT)).toBeInTheDocument();
+ describe('handleSelectType navigation', () => {
+ beforeEach(() => {
+ mockGetUrlQuery.mockReturnValue(null);
+ useCompositeQueryParamSpy.mockReturnValue(null);
+ });
+
+ it('should navigate with threshold alert params for metrics alert', () => {
+ render(<CreateAlertRule />);
+ fireEvent.click(screen.getByText('metric_based_alert'));
+
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.ruleType,
+ 'threshold_rule',
+ );
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.alertType,
+ AlertTypes.METRICS_BASED_ALERT,
+ );
+ expect(mockSafeNavigate).toHaveBeenCalled();
+ });
+
+ it('should navigate with threshold alert params for logs alert', () => {
+ render(<CreateAlertRule />);
+ fireEvent.click(screen.getByText('log_based_alert'));
+
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.ruleType,
+ 'threshold_rule',
+ );
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.alertType,
+ AlertTypes.LOGS_BASED_ALERT,
+ );
+ expect(mockSafeNavigate).toHaveBeenCalled();
+ });
+
+ it('should navigate with threshold alert params for traces alert', () => {
+ render(<CreateAlertRule />);
+ fireEvent.click(screen.getByText('traces_based_alert'));
+
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.ruleType,
+ 'threshold_rule',
+ );
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.alertType,
+ AlertTypes.TRACES_BASED_ALERT,
+ );
+ expect(mockSafeNavigate).toHaveBeenCalled();
+ });
+
+ it('should navigate with threshold alert params for exceptions alert', () => {
+ render(<CreateAlertRule />);
+ fireEvent.click(screen.getByText('exceptions_based_alert'));
+
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.ruleType,
+ 'threshold_rule',
+ );
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.alertType,
+ AlertTypes.EXCEPTIONS_BASED_ALERT,
+ );
+ expect(mockSafeNavigate).toHaveBeenCalled();
+ });
+
+ it('should navigate with anomaly detection params for anomaly alert', () => {
+ useAppContextSpy.mockReturnValue({
+ ...getAppContextMockState({}),
+ featureFlags: [
+ {
+ name: FeatureKeys.ANOMALY_DETECTION,
+ active: true,
+ usage: 0,
+ usage_limit: -1,
+ route: '',
+ },
+ ],
+ });
+
+ render(<CreateAlertRule />);
+ fireEvent.click(screen.getByText('anomaly_based_alert'));
+
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.ruleType,
+ 'anomaly_rule',
+ );
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.alertType,
+ AlertTypes.METRICS_BASED_ALERT,
+ );
+ expect(mockSafeNavigate).toHaveBeenCalled();
+ });
+
+ it('should navigate even when showClassicCreateAlertsPage flag is present', () => {
+ mockGetUrlQuery.mockImplementation((key: string) => {
+ if (key === QueryParams.showClassicCreateAlertsPage) {
+ return 'true';
+ }
+ return null;
+ });
+
+ render(<CreateAlertRule />);
+ fireEvent.click(screen.getByText('metric_based_alert'));
+
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.ruleType,
+ 'threshold_rule',
+ );
+ expect(mockSetUrlQuery).toHaveBeenCalledWith(
+ QueryParams.alertType,
+ AlertTypes.METRICS_BASED_ALERT,
+ );
+ expect(mockSafeNavigate).toHaveBeenCalled();
+ });
});
});
diff --git a/frontend/src/container/CreateAlertRule/defaults.ts b/frontend/src/container/CreateAlertRule/defaults.ts
index 0a9598b5f2..215ff90188 100644
--- a/frontend/src/container/CreateAlertRule/defaults.ts
+++ b/frontend/src/container/CreateAlertRule/defaults.ts
@@ -208,3 +208,11 @@ export const ALERTS_VALUES_MAP: Record<AlertTypes, AlertDef> = {
[AlertTypes.TRACES_BASED_ALERT]: traceAlertDefaults,
[AlertTypes.EXCEPTIONS_BASED_ALERT]: exceptionAlertDefaults,
};
+
+export const ALERT_TYPE_BREADCRUMB_TITLE: Record<AlertTypes, string> = {
+ [AlertTypes.ANOMALY_BASED_ALERT]: 'Anomaly-Based Alert',
+ [AlertTypes.METRICS_BASED_ALERT]: 'Metric-Based Alert',
+ [AlertTypes.LOGS_BASED_ALERT]: 'Log-Based Alert',
+ [AlertTypes.TRACES_BASED_ALERT]: 'Traces-Based Alert',
+ [AlertTypes.EXCEPTIONS_BASED_ALERT]: 'Exceptions-Based Alert',
+};
diff --git a/frontend/src/container/CreateAlertRule/index.tsx b/frontend/src/container/CreateAlertRule/index.tsx
index ef0418d049..50a98c115c 100644
--- a/frontend/src/container/CreateAlertRule/index.tsx
+++ b/frontend/src/container/CreateAlertRule/index.tsx
@@ -1,21 +1,34 @@
-import { useMemo } from 'react';
-import { Form } from 'antd';
+import { useCallback, useEffect, useMemo } from 'react';
+import { Form, Tabs, TabsProps } from 'antd';
+import logEvent from 'api/common/logEvent';
+import ConfigureIcon from 'assets/AlertHistory/ConfigureIcon';
+import AlertBreadcrumb from 'components/AlertBreadcrumb';
+import HeaderRightSection from 'components/HeaderRightSection/HeaderRightSection';
import { ENTITY_VERSION_V5 } from 'constants/app';
import { QueryParams } from 'constants/query';
+import ROUTES from 'constants/routes';
import CreateAlertV2 from 'container/CreateAlertV2';
import FormAlertRules, { AlertDetectionTypes } from 'container/FormAlertRules';
+import DateTimeSelector from 'container/TopNav/DateTimeSelectionV2';
import { useGetCompositeQueryParam } from 'hooks/queryBuilder/useGetCompositeQueryParam';
+import { useSafeNavigate } from 'hooks/useSafeNavigate';
import useUrlQuery from 'hooks/useUrlQuery';
+import { AlertListTabs } from 'pages/AlertList/types';
+import { GalleryVerticalEnd, Pyramid } from '@signozhq/icons';
import { AlertTypes } from 'types/api/alerts/alertTypes';
import { AlertDef } from 'types/api/alerts/def';
import { ALERT_TYPE_VS_SOURCE_MAPPING } from './config';
-import { ALERTS_VALUES_MAP } from './defaults';
+import { ALERTS_VALUES_MAP, ALERT_TYPE_BREADCRUMB_TITLE } from './defaults';
+import SelectAlertType from './SelectAlertType';
+
+import './CreateAlertRule.styles.scss';
function CreateRules(): JSX.Element {
const [formInstance] = Form.useForm();
const compositeQuery = useGetCompositeQueryParam();
const queryParams = useUrlQuery();
+ const { safeNavigate } = useSafeNavigate();
const ruleTypeFromURL = queryParams.get(QueryParams.ruleType);
const alertTypeFromURL = queryParams.get(QueryParams.alertType);
@@ -23,6 +36,15 @@ function CreateRules(): JSX.Element {
const showClassicCreateAlertsPageFlag =
queryParams.get(QueryParams.showClassicCreateAlertsPage) === 'true';
+ const isTypeSelectionMode =
+ !alertTypeFromURL && !ruleTypeFromURL && !compositeQuery;
+
+ useEffect(() => {
+ if (isTypeSelectionMode) {
+ logEvent('Alert: New alert data source selection page visited', {});
+ }
+ }, [isTypeSelectionMode]);
+
const alertType = useMemo(() => {
if (ruleTypeFromURL === AlertDetectionTypes.ANOMALY_DETECTION_ALERT) {
return AlertTypes.ANOMALY_BASED_ALERT;
@@ -45,22 +67,142 @@ function CreateRules(): JSX.Element {
[alertType, version],
);
- // Load old alerts flow always for anomaly based alerts and when showClassicCreateAlertsPage is true
- if (
- showClassicCreateAlertsPageFlag ||
- alertType === AlertTypes.ANOMALY_BASED_ALERT
- ) {
- return (
- <FormAlertRules
- alertType={alertType}
- formInstance={formInstance}
- initialValue={initialAlertValue}
- ruleId=""
- />
- );
- }
-
- return <CreateAlertV2 alertType={alertType} />;
+ const handleTabChange = useCallback(
+ (tab: string): void => {
+ queryParams.set('tab', tab);
+ queryParams.delete('subTab');
+ queryParams.delete('search');
+ safeNavigate(`${ROUTES.LIST_ALL_ALERT}?${queryParams.toString()}`);
+ },
+ [safeNavigate, queryParams],
+ );
+
+ const handleSelectType = useCallback(
+ (type: AlertTypes, newTab?: boolean): void => {
+ if (type === AlertTypes.ANOMALY_BASED_ALERT) {
+ queryParams.set(
+ QueryParams.ruleType,
+ AlertDetectionTypes.ANOMALY_DETECTION_ALERT,
+ );
+ queryParams.set(QueryParams.alertType, AlertTypes.METRICS_BASED_ALERT);
+ } else {
+ queryParams.set(QueryParams.ruleType, AlertDetectionTypes.THRESHOLD_ALERT);
+ queryParams.set(QueryParams.alertType, type);
+ }
+
+ safeNavigate(`${ROUTES.ALERTS_NEW}?${queryParams.toString()}`, { newTab });
+ },
+ [queryParams, safeNavigate],
+ );
+
+ const alertContent = useMemo(() => {
+ if (isTypeSelectionMode) {
+ return <SelectAlertType onSelect={handleSelectType} />;
+ }
+
+ if (
+ showClassicCreateAlertsPageFlag ||
+ alertType === AlertTypes.ANOMALY_BASED_ALERT
+ ) {
+ return (
+ <FormAlertRules
+ alertType={alertType}
+ formInstance={formInstance}
+ initialValue={initialAlertValue}
+ ruleId=""
+ />
+ );
+ }
+ return <CreateAlertV2 alertType={alertType} />;
+ }, [
+ isTypeSelectionMode,
+ handleSelectType,
+ showClassicCreateAlertsPageFlag,
+ alertType,
+ formInstance,
+ initialAlertValue,
+ ]);
+
+ const items: TabsProps['items'] = [
+ {
+ label: (
+ <div className="periscope-tab top-level-tab">
+ <GalleryVerticalEnd size={14} />
+ Triggered Alerts
+ </div>
+ ),
+ key: AlertListTabs.TRIGGERED_ALERTS,
+ children: null,
+ },
+ {
+ label: (
+ <div className="periscope-tab top-level-tab">
+ <Pyramid size={14} />
+ Alert Rules
+ </div>
+ ),
+ key: AlertListTabs.ALERT_RULES,
+ children: (
+ <div className="create-alert-wrapper">
+ <AlertBreadcrumb
+ className="create-alert__breadcrumb"
+ items={
+ isTypeSelectionMode
+ ? [
+ {
+ title: 'Alert Rules',
+ route: `${ROUTES.LIST_ALL_ALERT}?tab=${AlertListTabs.ALERT_RULES}`,
+ },
+ { title: 'Select Alert Type', isLast: true },
+ ]
+ : [
+ {
+ title: 'Alert Rules',
+ route: `${ROUTES.LIST_ALL_ALERT}?tab=${AlertListTabs.ALERT_RULES}`,
+ },
+ { title: 'Select Alert Type', route: ROUTES.ALERTS_NEW },
+ {
+ title: ALERT_TYPE_BREADCRUMB_TITLE[alertType],
+ isLast: true,
+ },
+ ]
+ }
+ />
+ {alertContent}
+ </div>
+ ),
+ },
+ {
+ label: (
+ <div className="periscope-tab top-level-tab">
+ <ConfigureIcon width={14} height={14} />
+ Configuration
+ </div>
+ ),
+ key: AlertListTabs.CONFIGURATION,
+ children: null,
+ },
+ ];
+
+ return (
+ <Tabs
+ destroyInactiveTabPane
+ items={items}
+ activeKey={AlertListTabs.ALERT_RULES}
+ onChange={handleTabChange}
+ className="alerts-container create-alert-tabs"
+ tabBarExtraContent={
+ <div className="create-alert-tabs__extra">
+ <DateTimeSelector showAutoRefresh />
+ <HeaderRightSection
+ enableAnnouncements={false}
+ enableShare
+ enableFeedback
+ />
+ </div>
+ }
+ />
+ );
}
export default CreateRules;
diff --git a/frontend/src/container/ListAlertRules/ListAlert.tsx b/frontend/src/container/ListAlertRules/ListAlert.tsx
index a60f2a1bb2..719a598975 100644
--- a/frontend/src/container/ListAlertRules/ListAlert.tsx
+++ b/frontend/src/container/ListAlertRules/ListAlert.tsx
@@ -111,7 +111,7 @@ function ListAlert({ allAlertRules, refetch }: ListAlertProps): JSX.Element {
number: allAlertRules?.length,
layout: 'new',
});
- safeNavigate(ROUTES.ALERT_TYPE_SELECTION, {
+ safeNavigate(ROUTES.ALERTS_NEW, {
newTab: isModifierKeyPressed(e),
});
},
diff --git a/frontend/src/container/TopNav/index.tsx b/frontend/src/container/TopNav/index.tsx
index eb591a2410..8eb161e89a 100644
--- a/frontend/src/container/TopNav/index.tsx
+++ b/frontend/src/container/TopNav/index.tsx
@@ -33,14 +33,12 @@ function TopNav(): JSX.Element | null {
[location.pathname],
);
- const isNewAlertsLandingPage = useMemo(
- () =>
- matchPath(location.pathname, { path: ROUTES.ALERTS_NEW, exact: true }) &&
- !location.search,
- [location.pathname, location.search],
+ const isAlertCreationPage = useMemo(
+ () => matchPath(location.pathname, { path: ROUTES.ALERTS_NEW, exact: true }),
+ [location.pathname],
);
- if (isSignUpPage || isDisabled || isRouteToSkip || isNewAlertsLandingPage) {
+ if (isSignUpPage || isDisabled || isRouteToSkip || isAlertCreationPage) {
return null;
}
diff --git a/frontend/src/pages/AlertDetails/AlertDetails.styles.scss b/frontend/src/pages/AlertDetails/AlertDetails.styles.scss
index d420771b12..48aa18d760 100644
--- a/frontend/src/pages/AlertDetails/AlertDetails.styles.scss
+++ b/frontend/src/pages/AlertDetails/AlertDetails.styles.scss
@@ -41,7 +41,6 @@
}
.alert-details {
- margin-top: 10px;
.divider {
border-color: var(--l1-border);
margin: 16px 0;
diff --git a/frontend/src/pages/AlertDetails/AlertDetails.tsx b/frontend/src/pages/AlertDetails/AlertDetails.tsx
index 084bb8df0b..230f5e5bc9 100644
--- a/frontend/src/pages/AlertDetails/AlertDetails.tsx
+++ b/frontend/src/pages/AlertDetails/AlertDetails.tsx
@@ -1,8 +1,9 @@
import React, { useEffect, useMemo } from 'react';
import { useLocation } from 'react-router-dom';
-import { Breadcrumb, Button, Divider } from 'antd';
+import { Divider } from 'antd';
import logEvent from 'api/common/logEvent';
import classNames from 'classnames';
+import AlertBreadcrumb from 'components/AlertBreadcrumb';
import { Filters } from 'components/AlertDetailsFilters/Filters';
import RouteTab from 'components/RouteTab';
import Spinner from 'components/Spinner';
@@ -10,13 +11,11 @@ import { QueryParams } from 'constants/query';
import ROUTES from 'constants/routes';
import { CreateAlertProvider } from 'container/CreateAlertV2/context';
import { getCreateAlertLocalStateFromAlertDef } from 'container/CreateAlertV2/utils';
-import { useSafeNavigate } from 'hooks/useSafeNavigate';
import useUrlQuery from 'hooks/useUrlQuery';
import history from 'lib/history';
import { AlertTypes } from 'types/api/alerts/alertTypes';
import { NEW_ALERT_SCHEMA_VERSION } from 'types/api/alerts/alertTypesV2';
import { fromRuleDTOToPostableRuleV2 } from 'types/api/alerts/convert';
-import { isModifierKeyPressed } from 'utils/app';
import AlertHeader from './AlertHeader/AlertHeader';
import AlertNotFound from './AlertNotFound';
@@ -24,38 +23,6 @@ import { useGetAlertRuleDetails, useRouteTabUtils } from './hooks';
import './AlertDetails.styles.scss';
-function BreadCrumbItem({
- title,
- isLast,
- route,
-}: {
- title: string | null;
- isLast?: boolean;
- route?: string;
-}): JSX.Element {
- const { safeNavigate } = useSafeNavigate();
- if (isLast) {
- return <div className="breadcrumb-item breadcrumb-item--last">{title}</div>;
- }
- const handleNavigate = (e: React.MouseEvent): void => {
- if (!route) {
- return;
- }
- safeNavigate(ROUTES.LIST_ALL_ALERT, { newTab: isModifierKeyPressed(e) });
- };
-
- return (
- <Button type="text" className="breadcrumb-item" onClick={handleNavigate}>
- {title}
- </Button>
- );
-}
-
-BreadCrumbItem.defaultProps = {
- isLast: false,
- route: '',
-};
-
function AlertDetails(): JSX.Element {
const { pathname } = useLocation();
const { routes } = useRouteTabUtils();
@@ -126,20 +93,13 @@ function AlertDetails(): JSX.Element {
<div
className={classNames('alert-details', { 'alert-details-v2': isV2Alert })}
>
- <Breadcrumb
+ <AlertBreadcrumb
className="alert-details__breadcrumb"
items={[
- {
- title: (
- <BreadCrumbItem title="Alert Rules" route={ROUTES.LIST_ALL_ALERT} />
- ),
- },
- {
- title: <BreadCrumbItem title={ruleId} isLast />,
- },
+ { title: 'Alert Rules', route: ROUTES.LIST_ALL_ALERT },
+ { title: ruleId, isLast: true },
]}
/>
- <Divider className="divider breadcrumb-divider" />
{alertRuleDetails && <AlertHeader alertDetails={alertRuleDetails} />}
<Divider className="divider" />
diff --git a/frontend/src/pages/AlertList/AlertList.styles.scss b/frontend/src/pages/AlertList/AlertList.styles.scss
index 0fc7089020..1e4c6efbab 100644
--- a/frontend/src/pages/AlertList/AlertList.styles.scss
+++ b/frontend/src/pages/AlertList/AlertList.styles.scss
@@ -1,15 +1,44 @@
.alerts-container {
- .ant-tabs-nav {
- padding: 0 8px;
+ .top-level-tab.periscope-tab {
+ padding: 2px 0;
}
- .configuration-tabs {
- margin-top: -16px;
+ .ant-tabs {
+ &-nav {
+ padding: 0 8px;
+ margin-bottom: 0 !important;
+
+ &::before {
+ border-bottom: 1px solid var(--l1-border) !important;
+ }
+ }
+
+ &-tab {
+ &[data-node-key='TriggeredAlerts'] {
+ margin-left: 16px;
+ }
+
+ &:not(:first-of-type) {
+ margin-left: 24px !important;
+ }
+ [aria-selected='false'] {
+ .periscope-tab {
+ color: var(--l2-foreground);
+ }
+ }
+ }
+ }
+
+ .configuration-tabs {
.ant-tabs-nav {
.ant-tabs-nav-wrap {
padding: 0 8px;
}
}
}
+
+ .alert-rules-container {
+ margin-top: 10px;
+ }
}
diff --git a/frontend/src/pages/AlertTypeSelection/AlertTypeSelection.tsx b/frontend/src/pages/AlertTypeSelection/AlertTypeSelection.tsx
deleted file mode 100644
index 81b109f3d3..0000000000
--- a/frontend/src/pages/AlertTypeSelection/AlertTypeSelection.tsx
+++ /dev/null
@@ -1,56 +0,0 @@
-import { useCallback, useEffect } from 'react';
-import { Row } from 'antd';
-import logEvent from 'api/common/logEvent';
-import { QueryParams } from 'constants/query';
-import ROUTES from 'constants/routes';
-import SelectAlertType from 'container/CreateAlertRule/SelectAlertType';
-import { AlertDetectionTypes } from 'container/FormAlertRules';
-import { useSafeNavigate } from 'hooks/useSafeNavigate';
-import useUrlQuery from 'hooks/useUrlQuery';
-import { AlertTypes } from 'types/api/alerts/alertTypes';
-
-function AlertTypeSelectionPage(): JSX.Element {
- const { safeNavigate } = useSafeNavigate();
- const queryParams = useUrlQuery();
-
- useEffect(() => {
- logEvent('Alert: New alert data source selection page visited', {});
- }, []);
-
- const handleSelectType = useCallback(
- (type: AlertTypes, newTab?: boolean): void => {
- // For anamoly based alert, we need to set the ruleType to anomaly_rule
- // and alertType to metrics_based_alert
- if (type === AlertTypes.ANOMALY_BASED_ALERT) {
- queryParams.set(
- QueryParams.ruleType,
- AlertDetectionTypes.ANOMALY_DETECTION_ALERT,
- );
- queryParams.set(QueryParams.alertType, AlertTypes.METRICS_BASED_ALERT);
- // For other alerts, we need to set the ruleType to threshold_rule
- // and alertType to the selected type
- } else {
- queryParams.set(QueryParams.ruleType, AlertDetectionTypes.THRESHOLD_ALERT);
- queryParams.set(QueryParams.alertType, type);
- }
-
- const showClassicCreateAlertsPageFlag = queryParams.get(
- QueryParams.showClassicCreateAlertsPage,
- );
- if (showClassicCreateAlertsPageFlag === 'true') {
- queryParams.set(QueryParams.showClassicCreateAlertsPage, 'true');
- }
-
- safeNavigate(`${ROUTES.ALERTS_NEW}?${queryParams.toString()}`, { newTab });
- },
- [queryParams, safeNavigate],
- );
-
- return (
- <Row wrap={false}>
- <SelectAlertType onSelect={handleSelectType} />
- </Row>
- );
-}
-
-export default AlertTypeSelectionPage;
diff --git a/frontend/src/pages/AlertTypeSelection/__tests__/AlertTypeSelection.test.tsx b/frontend/src/pages/AlertTypeSelection/__tests__/AlertTypeSelection.test.tsx
deleted file mode 100644
index 432596eb36..0000000000
--- a/frontend/src/pages/AlertTypeSelection/__tests__/AlertTypeSelection.test.tsx
+++ /dev/null
@@ -1,189 +0,0 @@
-import { fireEvent, render, screen } from '@testing-library/react';
-import { FeatureKeys } from 'constants/features';
-import { QueryParams } from 'constants/query';
-import { AlertDetectionTypes } from 'container/FormAlertRules';
-import { getAppContextMockState } from 'container/RoutingPolicies/__tests__/testUtils';
-import * as navigateHooks from 'hooks/useSafeNavigate';
-import * as useUrlQueryHooks from 'hooks/useUrlQuery';
-import * as appHooks from 'providers/App/App';
-import { AlertTypes } from 'types/api/alerts/alertTypes';
-
-import AlertTypeSelection from '../AlertTypeSelection';
-
-const useUrlQuerySpy = jest.spyOn(useUrlQueryHooks, 'default');
-const useSafeNavigateSpy = jest.spyOn(navigateHooks, 'useSafeNavigate');
-const useAppContextSpy = jest.spyOn(appHooks, 'useAppContext');
-
-const mockSetUrlQuery = jest.fn();
-const mockSafeNavigate = jest.fn();
-const mockToString = jest.fn();
-const mockGetUrlQuery = jest.fn();
-
-describe('AlertTypeSelection', () => {
- beforeEach(() => {
- jest.clearAllMocks();
- useAppContextSpy.mockReturnValue(getAppContextMockState());
- useUrlQuerySpy.mockReturnValue({
- set: mockSetUrlQuery,
- toString: mockToString,
- get: mockGetUrlQuery,
- } as Partial<URLSearchParams> as URLSearchParams);
- useSafeNavigateSpy.mockReturnValue({
- safeNavigate: mockSafeNavigate,
- });
- });
-
- it('should render all alert type options when anomaly detection is enabled', () => {
- useAppContextSpy.mockReturnValue({
- ...getAppContextMockState({}),
- featureFlags: [
- {
- name: FeatureKeys.ANOMALY_DETECTION,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- ],
- });
-
- render(<AlertTypeSelection />);
-
- expect(screen.getByText('metric_based_alert')).toBeInTheDocument();
- expect(screen.getByText('log_based_alert')).toBeInTheDocument();
- expect(screen.getByText('traces_based_alert')).toBeInTheDocument();
- expect(screen.getByText('exceptions_based_alert')).toBeInTheDocument();
- expect(screen.getByText('anomaly_based_alert')).toBeInTheDocument();
- });
-
- it('should render all alert type options except anomaly based alert when anomaly detection is disabled', () => {
- render(<AlertTypeSelection />);
-
- expect(screen.getByText('metric_based_alert')).toBeInTheDocument();
- expect(screen.getByText('log_based_alert')).toBeInTheDocument();
- expect(screen.getByText('traces_based_alert')).toBeInTheDocument();
- expect(screen.getByText('exceptions_based_alert')).toBeInTheDocument();
- expect(screen.queryByText('anomaly_based_alert')).not.toBeInTheDocument();
- });
-
- it('should navigate to metrics based alert with correct params', () => {
- render(<AlertTypeSelection />);
- fireEvent.click(screen.getByText('metric_based_alert'));
-
- expect(mockSetUrlQuery).toHaveBeenCalledTimes(2);
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.ruleType,
- AlertDetectionTypes.THRESHOLD_ALERT,
- );
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.alertType,
- AlertTypes.METRICS_BASED_ALERT,
- );
- expect(mockSafeNavigate).toHaveBeenCalled();
- });
-
- it('should navigate to anomaly based alert with correct params', () => {
- useAppContextSpy.mockReturnValue({
- ...getAppContextMockState({}),
- featureFlags: [
- {
- name: FeatureKeys.ANOMALY_DETECTION,
- active: true,
- usage: 0,
- usage_limit: -1,
- route: '',
- },
- ],
- });
-
- render(<AlertTypeSelection />);
- fireEvent.click(screen.getByText('anomaly_based_alert'));
-
- expect(mockSetUrlQuery).toHaveBeenCalledTimes(2);
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.ruleType,
- AlertDetectionTypes.ANOMALY_DETECTION_ALERT,
- );
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.alertType,
- AlertTypes.METRICS_BASED_ALERT,
- );
- expect(mockSafeNavigate).toHaveBeenCalled();
- });
-
- it('should navigate to log based alert with correct params', () => {
- render(<AlertTypeSelection />);
- fireEvent.click(screen.getByText('log_based_alert'));
-
- expect(mockSetUrlQuery).toHaveBeenCalledTimes(2);
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.ruleType,
- AlertDetectionTypes.THRESHOLD_ALERT,
- );
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.alertType,
- AlertTypes.LOGS_BASED_ALERT,
- );
- expect(mockSafeNavigate).toHaveBeenCalled();
- });
-
- it('should navigate to traces based alert with correct params', () => {
- render(<AlertTypeSelection />);
- fireEvent.click(screen.getByText('traces_based_alert'));
- expect(mockSetUrlQuery).toHaveBeenCalledTimes(2);
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.ruleType,
- AlertDetectionTypes.THRESHOLD_ALERT,
- );
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.alertType,
- AlertTypes.TRACES_BASED_ALERT,
- );
- expect(mockSafeNavigate).toHaveBeenCalled();
- });
-
- it('should navigate to exceptions based alert with correct params', () => {
- render(<AlertTypeSelection />);
- fireEvent.click(screen.getByText('exceptions_based_alert'));
- expect(mockSetUrlQuery).toHaveBeenCalledTimes(2);
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.ruleType,
- AlertDetectionTypes.THRESHOLD_ALERT,
- );
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.alertType,
- AlertTypes.EXCEPTIONS_BASED_ALERT,
- );
- expect(mockSafeNavigate).toHaveBeenCalled();
- });
-
- it('should navigate to classic create alerts page with correct params if showClassicCreateAlertsPage is true', () => {
- useUrlQuerySpy.mockReturnValue({
- set: mockSetUrlQuery,
- toString: mockToString,
- get: mockGetUrlQuery.mockImplementation((key: string) => {
- if (key === QueryParams.showClassicCreateAlertsPage) {
- return 'true';
- }
- return null;
- }),
- } as Partial<URLSearchParams> as URLSearchParams);
-
- render(<AlertTypeSelection />);
- fireEvent.click(screen.getByText('metric_based_alert'));
- expect(mockSetUrlQuery).toHaveBeenCalledTimes(3);
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.ruleType,
- AlertDetectionTypes.THRESHOLD_ALERT,
- );
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.alertType,
- AlertTypes.METRICS_BASED_ALERT,
- );
- expect(mockSetUrlQuery).toHaveBeenCalledWith(
- QueryParams.showClassicCreateAlertsPage,
- 'true',
- );
- expect(mockSafeNavigate).toHaveBeenCalled();
- });
-});
diff --git a/frontend/src/pages/AlertTypeSelection/index.tsx b/frontend/src/pages/AlertTypeSelection/index.tsx
deleted file mode 100644
index 16ec4ffad3..0000000000
--- a/frontend/src/pages/AlertTypeSelection/index.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-import AlertTypeSelectionPage from './AlertTypeSelection';
-
-export default AlertTypeSelectionPage;
diff --git a/frontend/src/utils/permission/index.ts b/frontend/src/utils/permission/index.ts
index abb0ebe868..2372e7a153 100644
--- a/frontend/src/utils/permission/index.ts
+++ b/frontend/src/utils/permission/index.ts
@@ -132,7 +132,6 @@ export const routePermission: Record<keyof typeof ROUTES, ROLES[]> = {
METER: ['ADMIN', 'EDITOR', 'VIEWER'],
METER_EXPLORER_VIEWS: ['ADMIN', 'EDITOR', 'VIEWER'],
PUBLIC_DASHBOARD: ['ADMIN', 'EDITOR', 'VIEWER'],
- ALERT_TYPE_SELECTION: ['ADMIN', 'EDITOR'],
AI_ASSISTANT: ['ADMIN', 'EDITOR', 'VIEWER'],
AI_ASSISTANT_ICON_PREVIEW: ['ADMIN', 'EDITOR', 'VIEWER'],
MCP_SERVER: ['ADMIN', 'EDITOR', 'VIEWER'],