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.

refactor(alerts): read the channel pickers from the v2 list API (#13129)

Ashwin Bhatkal63924a0fbb15
diff --git a/frontend/src/container/CreateAlertV2/AlertCondition/AlertCondition.tsx b/frontend/src/container/CreateAlertV2/AlertCondition/AlertCondition.tsx
index 2463eab9dc..f3bbfcb804 100644
--- a/frontend/src/container/CreateAlertV2/AlertCondition/AlertCondition.tsx
+++ b/frontend/src/container/CreateAlertV2/AlertCondition/AlertCondition.tsx
@@ -1,12 +1,8 @@
-import { useQuery } from 'react-query';
import { Button, Tooltip } from 'antd';
-import getAllChannels from 'api/channels/getAll';
import classNames from 'classnames';
import { ChartLine } from '@signozhq/icons';
-import { SuccessResponseV2 } from 'types/api';
+import { useChannelOptions } from 'hooks/notificationChannels/useChannelOptions';
import { AlertTypes } from 'types/api/alerts/alertTypes';
-import { Channels } from 'types/api/channels/getAll';
-import APIError from 'types/api/error';
import { useCreateAlertState } from '../context';
import AdvancedOptions from '../EvaluationSettings/AdvancedOptions';
@@ -21,14 +17,11 @@ function AlertCondition(): JSX.Element {
const { alertType, setAlertType } = useCreateAlertState();
const {
- data,
+ data: channels,
isLoading: isLoadingChannels,
isError: isErrorChannels,
refetch: refreshChannels,
- } = useQuery<SuccessResponseV2<Channels[]>, APIError>(['getChannels'], {
- queryFn: () => getAllChannels(),
- });
- const channels = data?.data || [];
+ } = useChannelOptions();
const showMultipleTabs =
alertType === AlertTypes.ANOMALY_BASED_ALERT ||
diff --git a/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/AlertThreshold.test.tsx b/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/AlertThreshold.test.tsx
index 31ba457f75..6c0c3f256c 100644
--- a/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/AlertThreshold.test.tsx
+++ b/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/AlertThreshold.test.tsx
@@ -2,12 +2,12 @@ import { QueryClient, QueryClientProvider } from 'react-query';
import { MemoryRouter } from 'react-router-dom';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { AlertTypes } from 'types/api/alerts/alertTypes';
-import { Channels } from 'types/api/channels/getAll';
+import { ChannelOption } from 'hooks/notificationChannels/useChannelOptions';
import { CreateAlertProvider } from '../../context';
import AlertThreshold from '../AlertThreshold';
-const mockChannels: Channels[] = [];
+const mockChannels: ChannelOption[] = [];
const mockRefreshChannels = jest.fn();
const mockIsLoadingChannels = false;
const mockIsErrorChannels = false;
@@ -85,16 +85,17 @@ jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
}));
// Mock getAllChannels API
-jest.mock('api/channels/getAll', () => ({
+jest.mock('hooks/notificationChannels/useChannelOptions', () => ({
__esModule: true,
- default: jest.fn(() =>
- Promise.resolve({
- data: [
- { id: '1', name: 'Email Channel' },
- { id: '2', name: 'Slack Channel' },
- ] as Channels[],
- }),
- ),
+ useChannelOptions: jest.fn(() => ({
+ data: [
+ { id: '1', name: 'Email Channel' },
+ { id: '2', name: 'Slack Channel' },
+ ] as ChannelOption[],
+ isLoading: false,
+ isError: false,
+ refetch: jest.fn(),
+ })),
}));
// Mock alert format categories
diff --git a/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/ThresholdItem.test.tsx b/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/ThresholdItem.test.tsx
index 9825ea715e..7bb512d6c5 100644
--- a/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/ThresholdItem.test.tsx
+++ b/frontend/src/container/CreateAlertV2/AlertCondition/__tests__/ThresholdItem.test.tsx
@@ -3,7 +3,7 @@ import type { DefaultOptionType } from 'antd/es/select';
import { createMockAlertContextState } from 'container/CreateAlertV2/EvaluationSettings/__tests__/testUtils';
import { getAppContextMockState } from 'container/RoutingPolicies/__tests__/testUtils';
import * as appHooks from 'providers/App/App';
-import { Channels } from 'types/api/channels/getAll';
+import { ChannelOption } from 'hooks/notificationChannels/useChannelOptions';
import * as context from '../../context';
import ThresholdItem from '../ThresholdItem';
@@ -57,7 +57,7 @@ const mockThreshold = {
color: '#ff0000',
};
-const mockChannels: Channels[] = [
+const mockChannels: ChannelOption[] = [
{
id: TEST_CONSTANTS.CHANNEL_1,
name: TEST_CONSTANTS.EMAIL_CHANNEL_NAME,
diff --git a/frontend/src/container/CreateAlertV2/AlertCondition/types.ts b/frontend/src/container/CreateAlertV2/AlertCondition/types.ts
index 3da8052858..d51e81636a 100644
--- a/frontend/src/container/CreateAlertV2/AlertCondition/types.ts
+++ b/frontend/src/container/CreateAlertV2/AlertCondition/types.ts
@@ -1,5 +1,5 @@
import type { DefaultOptionType } from 'antd/es/select';
-import { Channels } from 'types/api/channels/getAll';
+import { ChannelOption } from 'hooks/notificationChannels/useChannelOptions';
import {
NotificationSettingsAction,
@@ -21,7 +21,7 @@ export interface ThresholdItemProps {
updateThreshold: UpdateThreshold;
removeThreshold: (thresholdId: string) => void;
showRemoveButton: boolean;
- channels: Channels[];
+ channels: ChannelOption[];
isLoadingChannels: boolean;
units: DefaultOptionType[];
isErrorChannels: boolean;
@@ -29,7 +29,7 @@ export interface ThresholdItemProps {
}
export interface AnomalyAndThresholdProps {
- channels: Channels[];
+ channels: ChannelOption[];
isLoadingChannels: boolean;
isErrorChannels: boolean;
refreshChannels: () => void;
diff --git a/frontend/src/container/FormAlertRules/BasicInfo.tsx b/frontend/src/container/FormAlertRules/BasicInfo.tsx
index 38788f93a5..44a189a542 100644
--- a/frontend/src/container/FormAlertRules/BasicInfo.tsx
+++ b/frontend/src/container/FormAlertRules/BasicInfo.tsx
@@ -1,19 +1,16 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { useQuery } from 'react-query';
import { Plus } from '@signozhq/icons';
import { Button, Flex, Form, Select, Tooltip } from 'antd';
import { Switch } from '@signozhq/ui/switch';
-import getAll from 'api/channels/getAll';
import logEvent from 'api/common/logEvent';
import { ALERTS_DATA_SOURCE_MAP } from 'constants/alerts';
import ROUTES from 'constants/routes';
+import { useChannelOptions } from 'hooks/notificationChannels/useChannelOptions';
import useComponentPermission from 'hooks/useComponentPermission';
import { useAppContext } from 'providers/App/App';
-import { SuccessResponseV2 } from 'types/api';
import { AlertTypes } from 'types/api/alerts/alertTypes';
import { AlertDef, Labels } from 'types/api/alerts/def';
-import { Channels } from 'types/api/channels/getAll';
import APIError from 'types/api/error';
import { requireErrorMessage } from 'utils/form/requireErrorMessage';
import { openInNewTab } from 'utils/navigation';
@@ -47,12 +44,13 @@ function BasicInfo({
}: BasicInfoProps): JSX.Element {
const { t } = useTranslation('alerts');
- const { isLoading, data, error, isError, refetch } = useQuery<
- SuccessResponseV2<Channels[]>,
- APIError
- >(['getChannels'], {
- queryFn: () => getAll(),
- });
+ const {
+ isLoading,
+ data: channels,
+ error,
+ isError,
+ refetch,
+ } = useChannelOptions();
const { user } = useAppContext();
const [addNewChannelPermission] = useComponentPermission(
@@ -81,7 +79,7 @@ function BasicInfo({
});
};
- const noChannels = data?.data?.length === 0;
+ const noChannels = channels.length === 0;
const handleCreateNewChannels = useCallback(() => {
logEvent('Alert: Create notification channel button clicked', {
dataSource: ALERTS_DATA_SOURCE_MAP[alertDef?.alertType as AlertTypes],
@@ -96,7 +94,7 @@ function BasicInfo({
if (!isLoading && isNewRule && !hasLoggedEvent.current) {
logEvent('Alert: New alert creation page visited', {
dataSource: ALERTS_DATA_SOURCE_MAP[alertDef?.alertType as AlertTypes],
- numberOfChannels: data?.data?.length,
+ numberOfChannels: channels.length,
});
hasLoggedEvent.current = true;
}
@@ -230,7 +228,7 @@ function BasicInfo({
disabled={shouldBroadCastToAllChannels}
currentValue={alertDef.preferredChannels}
handleCreateNewChannels={handleCreateNewChannels}
- channels={data?.data || []}
+ channels={channels}
isLoading={isLoading}
hasError={isError}
error={error as APIError}
diff --git a/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx b/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx
index d97e1f5b5b..9eef852405 100644
--- a/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx
+++ b/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx
@@ -2,10 +2,10 @@ import { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
import { Plus } from '@signozhq/icons';
import { Select, Spin } from 'antd';
+import { ChannelOption } from 'hooks/notificationChannels/useChannelOptions';
import useComponentPermission from 'hooks/useComponentPermission';
import { useNotifications } from 'hooks/useNotifications';
import { useAppContext } from 'providers/App/App';
-import { Channels } from 'types/api/channels/getAll';
import APIError from 'types/api/error';
import { StyledCreateChannelOption, StyledSelect } from './styles';
@@ -16,7 +16,7 @@ export interface ChannelSelectProps {
onSelectChannels: (s: string[]) => void;
onDropdownOpen: () => void;
isLoading: boolean;
- channels: Channels[];
+ channels: ChannelOption[];
hasError: boolean;
error: APIError;
handleCreateNewChannels: () => void;
diff --git a/frontend/src/container/RoutingPolicies/__tests__/testUtils.ts b/frontend/src/container/RoutingPolicies/__tests__/testUtils.ts
index 1e4ff4356a..3e360afd65 100644
--- a/frontend/src/container/RoutingPolicies/__tests__/testUtils.ts
+++ b/frontend/src/container/RoutingPolicies/__tests__/testUtils.ts
@@ -1,6 +1,6 @@
import { ApiRoutingPolicy } from 'api/routingPolicies/getRoutingPolicies';
import { IAppContext, IUser } from 'providers/App/types';
-import { Channels } from 'types/api/channels/getAll';
+import { ChannelOption } from 'hooks/notificationChannels/useChannelOptions';
import { RoutingPolicy, UseRoutingPoliciesReturn } from '../types';
@@ -28,21 +28,13 @@ export const MOCK_ROUTING_POLICY_2: RoutingPolicy = {
updatedBy: '[email protected]',
};
-export const MOCK_CHANNEL_1: Channels = {
+export const MOCK_CHANNEL_1: ChannelOption = {
name: 'Channel 1',
- created_at: '2021-01-01',
- data: 'data 1',
id: '1',
- type: 'type 1',
- updated_at: '2021-01-01',
};
-export const MOCK_CHANNEL_2: Channels = {
+export const MOCK_CHANNEL_2: ChannelOption = {
name: 'Channel 2',
- created_at: '2021-01-02',
- data: 'data 2',
id: '2',
- type: 'type 2',
- updated_at: '2021-01-02',
};
export function getUseRoutingPoliciesMockData(
diff --git a/frontend/src/container/RoutingPolicies/__tests__/useRoutingPolicies.test.tsx b/frontend/src/container/RoutingPolicies/__tests__/useRoutingPolicies.test.tsx
index ddb6aca94a..64c9e3d7ee 100644
--- a/frontend/src/container/RoutingPolicies/__tests__/useRoutingPolicies.test.tsx
+++ b/frontend/src/container/RoutingPolicies/__tests__/useRoutingPolicies.test.tsx
@@ -77,12 +77,14 @@ jest.mock('hooks/routingPolicies/useDeleteRoutingPolicy', () => ({
isLoading: false,
}),
}));
-jest.mock('api/channels/getAll', () => ({
+jest.mock('hooks/notificationChannels/useChannelOptions', () => ({
__esModule: true,
- default: (): any =>
- Promise.resolve({
- data: [MOCK_CHANNEL_1, MOCK_CHANNEL_2],
- }),
+ useChannelOptions: (): any => ({
+ data: [MOCK_CHANNEL_1, MOCK_CHANNEL_2],
+ isLoading: false,
+ isError: false,
+ refetch: jest.fn(),
+ }),
}));
const ROUTING_POLICY_1_NAME = 'Routing Policy 1';
diff --git a/frontend/src/container/RoutingPolicies/types.ts b/frontend/src/container/RoutingPolicies/types.ts
index 1b7cdb632f..e2ce61042b 100644
--- a/frontend/src/container/RoutingPolicies/types.ts
+++ b/frontend/src/container/RoutingPolicies/types.ts
@@ -1,4 +1,4 @@
-import { Channels } from 'types/api/channels/getAll';
+import { ChannelOption } from 'hooks/notificationChannels/useChannelOptions';
export interface RoutingPolicy {
id: string;
@@ -62,7 +62,7 @@ export interface RoutingPolicyDetailsProps {
routingPolicy: RoutingPolicy | null;
closeModal: () => void;
mode: PolicyDetailsModalMode;
- channels: Channels[];
+ channels: ChannelOption[];
isErrorChannels: boolean;
isLoadingChannels: boolean;
handlePolicyDetailsModalAction: HandlePolicyDetailsModalAction;
@@ -86,7 +86,7 @@ export interface UseRoutingPoliciesReturn {
isErrorRoutingPolicies: boolean;
refetchRoutingPolicies: () => void;
// Channels
- channels: Channels[];
+ channels: ChannelOption[];
isLoadingChannels: boolean;
isErrorChannels: boolean;
refreshChannels: () => void;
diff --git a/frontend/src/container/RoutingPolicies/useRoutingPolicies.ts b/frontend/src/container/RoutingPolicies/useRoutingPolicies.ts
index b47fd2013f..5cff9400bf 100644
--- a/frontend/src/container/RoutingPolicies/useRoutingPolicies.ts
+++ b/frontend/src/container/RoutingPolicies/useRoutingPolicies.ts
@@ -1,19 +1,17 @@
import { useMemo, useState } from 'react';
-import { useQuery, useQueryClient } from 'react-query';
+import { useQueryClient } from 'react-query';
import { useHistory } from 'react-router-dom';
import { toast } from '@signozhq/ui/sonner';
-import getAllChannels from 'api/channels/getAll';
import { GetRoutingPoliciesResponse } from 'api/routingPolicies/getRoutingPolicies';
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
import { useCreateRoutingPolicy } from 'hooks/routingPolicies/useCreateRoutingPolicy';
import { useDeleteRoutingPolicy } from 'hooks/routingPolicies/useDeleteRoutingPolicy';
+import { useChannelOptions } from 'hooks/notificationChannels/useChannelOptions';
import { useGetRoutingPolicies } from 'hooks/routingPolicies/useGetRoutingPolicies';
import { useUpdateRoutingPolicy } from 'hooks/routingPolicies/useUpdateRoutingPolicy';
import useDebouncedFn from 'hooks/useDebouncedFunction';
import useUrlQuery from 'hooks/useUrlQuery';
import { SuccessResponseV2 } from 'types/api';
-import { Channels } from 'types/api/channels/getAll';
-import APIError from 'types/api/error';
import {
PolicyDetailsModalMode,
@@ -83,14 +81,11 @@ function useRoutingPolicies(): UseRoutingPoliciesReturn {
// Channels list
const {
- data,
+ data: channels,
isLoading: isLoadingChannels,
isError: isErrorChannels,
refetch: refetchChannels,
- } = useQuery<SuccessResponseV2<Channels[]>, APIError>(['getChannels'], {
- queryFn: () => getAllChannels(),
- });
- const channels = data?.data || [];
+ } = useChannelOptions();
const refreshChannels = (): void => {
refetchChannels();
diff --git a/frontend/src/hooks/notificationChannels/useChannelOptions.ts b/frontend/src/hooks/notificationChannels/useChannelOptions.ts
new file mode 100644
index 0000000000..892aec9885
--- /dev/null
+++ b/frontend/src/hooks/notificationChannels/useChannelOptions.ts
@@ -0,0 +1,68 @@
+import { useQuery, UseQueryResult } from 'react-query';
+import { listNotificationChannels } from 'api/generated/services/channels';
+import {
+ AlertmanagertypesChannelListOrderDTO,
+ AlertmanagertypesChannelListSortDTO,
+ AlertmanagertypesListedNotificationChannelDTO,
+} from 'api/generated/services/sigNoz.schemas';
+import { range } from 'lodash-es';
+
+const PAGE_SIZE = 100;
+
+export const CHANNEL_OPTIONS_QUERY_KEY = ['notificationChannelOptions'];
+
+export interface ChannelOption {
+ id: string;
+ /** The display name, which is what rules and routing policies reference. */
+ name: string;
+}
+
+export type UseChannelOptionsResult = Omit<
+ UseQueryResult<ChannelOption[], Error>,
+ 'data'
+> & {
+ data: ChannelOption[];
+};
+
+function fetchPage(
+ offset: number,
+): ReturnType<typeof listNotificationChannels> {
+ return listNotificationChannels({
+ limit: PAGE_SIZE,
+ offset,
+ sort: AlertmanagertypesChannelListSortDTO.name,
+ order: AlertmanagertypesChannelListOrderDTO.asc,
+ });
+}
+
+/**
+ * Every channel, for the pickers that let a rule or a policy name one. The list
+ * API is paginated and silently clamps a larger limit, so the first page reports
+ * the total and any remainder is fetched alongside rather than truncating. One
+ * request covers an org with a page's worth of channels or fewer.
+ */
+async function fetchAllChannels(): Promise<ChannelOption[]> {
+ const first = await fetchPage(0);
+ const rest = await Promise.all(
+ range(PAGE_SIZE, first.data.total, PAGE_SIZE).map(fetchPage),
+ );
+
+ const channels: AlertmanagertypesListedNotificationChannelDTO[] = [
+ ...first.data.channels,
+ ...rest.flatMap((page) => page.data.channels),
+ ];
+
+ return channels.map((channel) => ({
+ id: channel.id,
+ name: channel.displayName,
+ }));
+}
+
+export function useChannelOptions(): UseChannelOptionsResult {
+ const query = useQuery<ChannelOption[], Error>(
+ CHANNEL_OPTIONS_QUERY_KEY,
+ fetchAllChannels,
+ );
+
+ return { ...query, data: query.data ?? [] };
+}
diff --git a/frontend/src/pages/AlertList/AlertHistory/stories/AlertHistory.stories.mocks.tsx b/frontend/src/pages/AlertList/AlertHistory/stories/AlertHistory.stories.mocks.tsx
index 8ea05c440b..a9e01d389a 100644
--- a/frontend/src/pages/AlertList/AlertHistory/stories/AlertHistory.stories.mocks.tsx
+++ b/frontend/src/pages/AlertList/AlertHistory/stories/AlertHistory.stories.mocks.tsx
@@ -24,7 +24,7 @@ import {
import {
alertRuleByIdResponse,
ALERT_SCHEMAS,
- channelsResponse,
+ notificationChannelsResponse,
CHANNEL_MAX,
FIRST_RULE_NAME,
type AlertSchema,
@@ -148,8 +148,8 @@ export const alertHistoryMocks = defineStoryMocks({
),
rest.get(
- 'http://localhost/api/v1/channels',
- response.json(() => channelsResponse(CHANNEL_MAX)),
+ 'http://localhost/api/v2/notification_channels',
+ response.json(() => notificationChannelsResponse(CHANNEL_MAX)),
),
],
config: () => ({
diff --git a/frontend/src/pages/AlertList/AlertOverview/stories/AlertOverview.stories.mocks.tsx b/frontend/src/pages/AlertList/AlertOverview/stories/AlertOverview.stories.mocks.tsx
index 75c6fc2797..ace2451d61 100644
--- a/frontend/src/pages/AlertList/AlertOverview/stories/AlertOverview.stories.mocks.tsx
+++ b/frontend/src/pages/AlertList/AlertOverview/stories/AlertOverview.stories.mocks.tsx
@@ -12,7 +12,7 @@ import { defineStoryMocks } from '@/storybook/controls/defineStoryMocks';
import {
alertRuleByIdResponse,
ALERT_SCHEMAS,
- channelsResponse,
+ notificationChannelsResponse,
CHANNEL_MAX,
RULE_STATE_CHOICES,
SEVERITY_CHOICES,
@@ -116,8 +116,8 @@ export const alertOverviewMocks = defineStoryMocks({
),
rest.get(
- 'http://localhost/api/v1/channels',
- response.json(() => channelsResponse(values.channels)),
+ 'http://localhost/api/v2/notification_channels',
+ response.json(() => notificationChannelsResponse(values.channels)),
),
rest.post(
diff --git a/frontend/src/pages/AlertList/RoutingPolicies/stories/RoutingPolicies.stories.mocks.tsx b/frontend/src/pages/AlertList/RoutingPolicies/stories/RoutingPolicies.stories.mocks.tsx
index fa51c286da..e3c2af35ad 100644
--- a/frontend/src/pages/AlertList/RoutingPolicies/stories/RoutingPolicies.stories.mocks.tsx
+++ b/frontend/src/pages/AlertList/RoutingPolicies/stories/RoutingPolicies.stories.mocks.tsx
@@ -17,7 +17,7 @@ import {
import {
CHANNEL_MAX,
channelNames,
- channelsResponse,
+ notificationChannelsResponse,
} from '../../stories/__story_mockdata__/alerts';
import { AlertListSubTabs, AlertListTabs } from '../../types';
@@ -118,10 +118,10 @@ export const routingPoliciesMocks = defineStoryMocks({
: res(ctx.status(200), ctx.json({ status: 'success', data: null })),
),
- rest.get('http://localhost/api/v1/channels', (_req, res, ctx) =>
+ rest.get('http://localhost/api/v2/notification_channels', (_req, res, ctx) =>
values.channelsState === 'error'
? res(ctx.status(500), ctx.json({ status: 'error' }))
- : res(ctx.json(channelsResponse(values.channels))),
+ : res(ctx.json(notificationChannelsResponse(values.channels))),
),
],
config: () => ({
diff --git a/frontend/src/pages/CreateAlert/stories/CreateAlert.stories.mocks.tsx b/frontend/src/pages/CreateAlert/stories/CreateAlert.stories.mocks.tsx
index 1e171ffc1f..0981cdda0e 100644
--- a/frontend/src/pages/CreateAlert/stories/CreateAlert.stories.mocks.tsx
+++ b/frontend/src/pages/CreateAlert/stories/CreateAlert.stories.mocks.tsx
@@ -21,7 +21,7 @@ import {
alertPreviewSeries,
} from '../../AlertList/stories/__story_mockdata__/alertQuery';
import {
- channelsResponse,
+ notificationChannelsResponse,
CHANNEL_MAX,
} from '../../AlertList/stories/__story_mockdata__/alerts';
@@ -127,8 +127,8 @@ export const createAlertMocks = defineStoryMocks({
),
rest.get(
- 'http://localhost/api/v1/channels',
- response.json(() => channelsResponse(values.channels)),
+ 'http://localhost/api/v2/notification_channels',
+ response.json(() => notificationChannelsResponse(values.channels)),
),
rest.post(
diff --git a/frontend/src/pages/EditRules/stories/EditRules.stories.mocks.tsx b/frontend/src/pages/EditRules/stories/EditRules.stories.mocks.tsx
index 1ad9218bc4..e7a70a3b67 100644
--- a/frontend/src/pages/EditRules/stories/EditRules.stories.mocks.tsx
+++ b/frontend/src/pages/EditRules/stories/EditRules.stories.mocks.tsx
@@ -20,7 +20,7 @@ import {
import {
alertRuleByIdResponse,
ALERT_SCHEMAS,
- channelsResponse,
+ notificationChannelsResponse,
CHANNEL_MAX,
type AlertSchema,
} from '../../AlertList/stories/__story_mockdata__/alerts';
@@ -77,8 +77,8 @@ export const editRulesMocks = defineStoryMocks({
),
rest.get(
- 'http://localhost/api/v1/channels',
- response.json(() => channelsResponse(values.channels)),
+ 'http://localhost/api/v2/notification_channels',
+ response.json(() => notificationChannelsResponse(values.channels)),
),
rest.post(
diff --git a/tests/e2e/helpers/alert-forms/shared.ts b/tests/e2e/helpers/alert-forms/shared.ts
index 4da38d9471..9c9f4a22b9 100644
--- a/tests/e2e/helpers/alert-forms/shared.ts
+++ b/tests/e2e/helpers/alert-forms/shared.ts
@@ -1,4 +1,4 @@
-import { expect, type Locator, type Page } from '@playwright/test';
+import { expect, type Locator, type Page, type Route } from '@playwright/test';
// ─── Antd select helpers ───────────────────────────────────────────────────
@@ -126,7 +126,7 @@ export async function pickChannelByName(
// ─── SEED-CH1: a stack with no notification channels ───────────────────────
/**
- * Route-stub `GET /api/v1/channels` to an empty list for this page only.
+ * Route-stub the channel list to an empty one for this page only.
*
* This is the **one** place the alerts suite mocks the network, and it is a
* deliberate exception to the standing no-stubbing rule. The justification: zero
@@ -136,11 +136,14 @@ export async function pickChannelByName(
* `alertChannel` is worker-scoped and parallel workers share one stack, so
* deleting the channel would break every other scenario running at that moment.
*
- * Both forms read the same endpoint through `api/channels/getAll`, so one stub
- * covers v1 and v2.
+ * Both list endpoints are stubbed: the pickers read v2, while screens still on
+ * the v1 client read v1, and a scenario may cross both.
*/
export async function stubNoChannels(page: Page): Promise<void> {
- await page.route('**/api/v1/channels', async (route) => {
+ const emptyList = async (
+ route: Route,
+ body: Record<string, unknown>,
+ ): Promise<void> => {
if (route.request().method() !== 'GET') {
await route.fallback();
return;
@@ -148,7 +151,15 @@ export async function stubNoChannels(page: Page): Promise<void> {
await route.fulfill({
status: 200,
contentType: 'application/json',
- body: JSON.stringify({ status: 'success', data: [] }),
+ body: JSON.stringify(body),
});
- });
+ };
+
+ await page.route('**/api/v1/channels', (route) =>
+ emptyList(route, { status: 'success', data: [] }),
+ );
+ // the v2 list is paginated, so the empty page has to carry its total
+ await page.route('**/api/v2/notification_channels*', (route) =>
+ emptyList(route, { status: 'success', data: { channels: [], total: 0 } }),
+ );
}