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.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
fix(notification-channels): edit not persisting any information (#11888)
Vinicius Lourenço810bf5d9a001
diff --git a/frontend/src/container/AllAlertChannels/__tests__/EditAlertChannel.test.tsx b/frontend/src/container/AllAlertChannels/__tests__/EditAlertChannel.test.tsxindex a0dac0e039..fc2fd8f785 100644--- a/frontend/src/container/AllAlertChannels/__tests__/EditAlertChannel.test.tsx+++ b/frontend/src/container/AllAlertChannels/__tests__/EditAlertChannel.test.tsx@@ -26,7 +26,12 @@ jest.mock('components/MarkdownRenderer/MarkdownRenderer', () => ({describe('Should check if the edit alert channel is properly displayed', () => {beforeEach(() => {- render(<EditAlertChannels initialValue={editAlertChannelInitialValue} />);+ render(+ <EditAlertChannels+ channelId="3"+ initialValue={editAlertChannelInitialValue}+ />,+ );});afterEach(() => {jest.clearAllMocks();diff --git a/frontend/src/container/AllAlertChannels/__tests__/EditAlertChannelSave.test.tsx b/frontend/src/container/AllAlertChannels/__tests__/EditAlertChannelSave.test.tsxnew file mode 100644index 0000000000..cb56bce9a6--- /dev/null+++ b/frontend/src/container/AllAlertChannels/__tests__/EditAlertChannelSave.test.tsx@@ -0,0 +1,81 @@+import EditAlertChannels from 'container/EditAlertChannels';+import { editAlertChannelInitialValue } from 'mocks-server/__mockdata__/alerts';+import { server } from 'mocks-server/server';+import { rest } from 'msw';+import { render, screen, userEvent, waitFor } from 'tests/test-utils';++jest.mock('hooks/useNotifications', () => ({+ __esModule: true,+ useNotifications: jest.fn(() => ({+ notifications: { success: jest.fn(), error: jest.fn() },+ })),+}));++jest.mock('components/MarkdownRenderer/MarkdownRenderer', () => ({+ MarkdownRenderer: jest.fn(() => <div>Mocked MarkdownRenderer</div>),+}));++interface EditRequest {+ id: string;+ body: { name: string; slack_configs: { send_resolved: boolean }[] };+}++// Captures the PUT /channels/:id request the edit form fires, so assertions can+// run against the real HTTP payload instead of a hand-mocked api client.+function mockEditChannel(): { calls: EditRequest[] } {+ const result: { calls: EditRequest[] } = { calls: [] };+ server.use(+ rest.put('http://localhost/api/v1/channels/:id', async (req, res, ctx) => {+ result.calls.push({+ id: req.params.id as string,+ body: await req.json(),+ });+ return res(+ ctx.status(200),+ ctx.json({ status: 'success', data: 'channel updated' }),+ );+ }),+ );+ return result;+}++describe('EditAlertChannels save', () => {+ afterEach(() => jest.clearAllMocks());++ it('sends the channelId in the edit request (regression: empty id)', async () => {+ const edit = mockEditChannel();+ render(+ <EditAlertChannels+ channelId="3"+ initialValue={editAlertChannelInitialValue}+ />,+ );++ const user = userEvent.setup();+ await user.click(screen.getByTestId('save-channel-button'));++ await waitFor(() => expect(edit.calls).toHaveLength(1));+ expect(edit.calls[0].id).toBe('3');+ });++ it('persists send_resolved toggle in the edit request', async () => {+ const edit = mockEditChannel();+ render(+ <EditAlertChannels+ channelId="3"+ initialValue={editAlertChannelInitialValue}+ />,+ );++ const user = userEvent.setup();+ const sendResolved = screen.getByTestId('field-send-resolved-checkbox');+ expect(sendResolved).toBeChecked();++ await user.click(sendResolved);+ await user.click(screen.getByTestId('save-channel-button'));++ await waitFor(() => expect(edit.calls).toHaveLength(1));+ expect(edit.calls[0].id).toBe('3');+ expect(edit.calls[0].body.slack_configs[0].send_resolved).toBe(false);+ });+});diff --git a/frontend/src/container/EditAlertChannels/index.tsx b/frontend/src/container/EditAlertChannels/index.tsxindex 644cbca43e..af986afe06 100644--- a/frontend/src/container/EditAlertChannels/index.tsx+++ b/frontend/src/container/EditAlertChannels/index.tsx@@ -32,6 +32,7 @@ import APIError from 'types/api/error';function EditAlertChannels({initialValue,+ channelId: id,}: EditAlertChannelsProps): JSX.Element {// init namespace for translationsconst { t } = useTranslation('channels');@@ -53,11 +54,6 @@ function EditAlertChannels({const [testingState, setTestingState] = useState<boolean>(false);const { notifications } = useNotifications();- // Extract channelId from URL pathname since useParams doesn't work in nested routing- const { pathname } = window.location;- const channelIdMatch = pathname.match(/\/settings\/channels\/edit\/([^/]+)/);- const id = channelIdMatch ? channelIdMatch[1] : '';-const [type, setType] = useState<ChannelType>(initialValue?.type ? (initialValue.type as ChannelType) : ChannelType.Slack,);@@ -520,6 +516,7 @@ interface EditAlertChannelsProps {initialValue: {[x: string]: unknown;};+ channelId: string;}export default EditAlertChannels;diff --git a/frontend/src/container/FormAlertChannels/index.tsx b/frontend/src/container/FormAlertChannels/index.tsxindex cab5e27d67..3057a25521 100644--- a/frontend/src/container/FormAlertChannels/index.tsx+++ b/frontend/src/container/FormAlertChannels/index.tsx@@ -136,6 +136,7 @@ function FormAlertChannels({<Form.Item><Button+ data-testid="save-channel-button"disabled={savingState}loading={savingState}type="primary"@@ -144,6 +145,7 @@ function FormAlertChannels({{t('button_save_channel')}</Button><Button+ data-testid="test-channel-button"disabled={testingState}loading={testingState}onClick={(): void => onTestHandler(type)}@@ -151,6 +153,7 @@ function FormAlertChannels({{t('button_test_channel')}</Button><Button+ data-testid="return-button"onClick={(): void => {history.replace(ROUTES.ALL_CHANNELS);}}diff --git a/frontend/src/pages/ChannelsEdit/index.tsx b/frontend/src/pages/ChannelsEdit/index.tsxindex 40312ce41d..9a89122a0f 100644--- a/frontend/src/pages/ChannelsEdit/index.tsx+++ b/frontend/src/pages/ChannelsEdit/index.tsx@@ -2,6 +2,7 @@import { useTranslation } from 'react-i18next';import { useQuery } from 'react-query';+import { matchPath, useLocation } from 'react-router-dom';import { Typography } from '@signozhq/ui/typography';import get from 'api/channels/get';import AlertBreadcrumb from 'components/AlertBreadcrumb';@@ -24,10 +25,10 @@ import './ChannelsEdit.styles.scss';function ChannelsEdit(): JSX.Element {const { t } = useTranslation();- // Extract channelId from URL pathname- const { pathname } = window.location;- const channelIdMatch = pathname.match(/\/alerts\/channels\/edit\/([^/]+)/);- const channelId = channelIdMatch ? channelIdMatch[1] : undefined;+ const { pathname } = useLocation();+ const channelId = matchPath<{ channelId: string }>(pathname, {+ path: ROUTES.CHANNELS_EDIT,+ })?.params?.channelId;const { isFetching, isError, data, error } = useQuery<SuccessResponseV2<Channels>,@@ -147,6 +148,7 @@ function ChannelsEdit(): JSX.Element {<div className="edit-alert-channels-container"><EditAlertChannels{...{+ channelId: channelId || '',initialValue: {...target.channel,type: target.type,