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.

feat: added an option to create channel when no Channels are available in alert config (#5195)

SagarRajput-7aa9689e025e7
diff --git a/frontend/src/container/AllAlertChannels/index.tsx b/frontend/src/container/AllAlertChannels/index.tsx
index 8038f17778..5f34264a60 100644
--- a/frontend/src/container/AllAlertChannels/index.tsx
+++ b/frontend/src/container/AllAlertChannels/index.tsx
@@ -1,5 +1,5 @@
import { PlusOutlined } from '@ant-design/icons';
-import { Typography } from 'antd';
+import { Tooltip, Typography } from 'antd';
import getAll from 'api/channels/getAll';
import Spinner from 'components/Spinner';
import TextToolTip from 'components/TextToolTip';
@@ -52,11 +52,21 @@ function AlertChannels(): JSX.Element {
url="https://signoz.io/docs/userguide/alerts-management/#setting-notification-channel"
/>
- {addNewChannelPermission && (
- <Button onClick={onToggleHandler} icon={<PlusOutlined />}>
+ <Tooltip
+ title={
+ !addNewChannelPermission
+ ? 'Ask an admin to create alert channel'
+ : undefined
+ }
+ >
+ <Button
+ onClick={onToggleHandler}
+ icon={<PlusOutlined />}
+ disabled={!addNewChannelPermission}
+ >
{t('button_new_channel')}
</Button>
- )}
+ </Tooltip>
</RightActionContainer>
</ButtonContainer>
diff --git a/frontend/src/container/FormAlertRules/BasicInfo.tsx b/frontend/src/container/FormAlertRules/BasicInfo.tsx
index 54877f5e0b..5fae4a713d 100644
--- a/frontend/src/container/FormAlertRules/BasicInfo.tsx
+++ b/frontend/src/container/FormAlertRules/BasicInfo.tsx
@@ -1,7 +1,17 @@
-import { Form, Select, Switch } from 'antd';
-import { useEffect, useState } from 'react';
+import './FormAlertRules.styles.scss';
+
+import { PlusOutlined } from '@ant-design/icons';
+import { Button, Form, Select, Switch, Tooltip } from 'antd';
+import getChannels from 'api/channels/getAll';
+import ROUTES from 'constants/routes';
+import useComponentPermission from 'hooks/useComponentPermission';
+import useFetch from 'hooks/useFetch';
+import { useCallback, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
+import { useSelector } from 'react-redux';
+import { AppState } from 'store/reducers';
import { AlertDef, Labels } from 'types/api/alerts/def';
+import AppReducer from 'types/reducer/app';
import { requireErrorMessage } from 'utils/form/requireErrorMessage';
import { popupContainer } from 'utils/selectPopupContainer';
@@ -31,6 +41,13 @@ function BasicInfo({
}: BasicInfoProps): JSX.Element {
const { t } = useTranslation('alerts');
+ const channels = useFetch(getChannels);
+ const { role } = useSelector<AppState, AppReducer>((state) => state.app);
+ const [addNewChannelPermission] = useComponentPermission(
+ ['add_new_channel'],
+ role,
+ );
+
const [
shouldBroadCastToAllChannels,
setShouldBroadCastToAllChannels,
@@ -54,6 +71,11 @@ function BasicInfo({
});
};
+ const noChannels = channels.payload?.length === 0;
+ const handleCreateNewChannels = useCallback(() => {
+ window.open(ROUTES.CHANNELS_NEW, '_blank');
+ }, []);
+
return (
<>
<StepHeading> {t('alert_form_step3')} </StepHeading>
@@ -137,32 +159,74 @@ function BasicInfo({
name="alert_all_configured_channels"
label="Alert all the configured channels"
>
- <Switch
- checked={shouldBroadCastToAllChannels}
- onChange={handleBroadcastToAllChannels}
- />
+ <Tooltip
+ title={
+ noChannels
+ ? 'No channels. Ask an admin to create a notification channel'
+ : undefined
+ }
+ placement="right"
+ >
+ <Switch
+ checked={shouldBroadCastToAllChannels}
+ onChange={handleBroadcastToAllChannels}
+ disabled={noChannels || !!channels.loading}
+ />
+ </Tooltip>
</FormItemMedium>
{!shouldBroadCastToAllChannels && (
- <FormItemMedium
- label="Notification Channels"
- name="notification_channels"
- required
- rules={[
- { required: true, message: requireErrorMessage(t('field_alert_name')) },
- ]}
+ <Tooltip
+ title={
+ noChannels
+ ? 'No channels. Ask an admin to create a notification channel'
+ : undefined
+ }
+ placement="right"
>
- <ChannelSelect
- disabled={shouldBroadCastToAllChannels}
- currentValue={alertDef.preferredChannels}
- onSelectChannels={(preferredChannels): void => {
- setAlertDef({
- ...alertDef,
- preferredChannels,
- });
- }}
- />
- </FormItemMedium>
+ <FormItemMedium
+ label="Notification Channels"
+ name="notification_channels"
+ required
+ rules={[
+ { required: true, message: requireErrorMessage(t('field_alert_name')) },
+ ]}
+ >
+ <ChannelSelect
+ disabled={
+ shouldBroadCastToAllChannels || noChannels || !!channels.loading
+ }
+ currentValue={alertDef.preferredChannels}
+ channels={channels}
+ onSelectChannels={(preferredChannels): void => {
+ setAlertDef({
+ ...alertDef,
+ preferredChannels,
+ });
+ }}
+ />
+ </FormItemMedium>
+ </Tooltip>
+ )}
+
+ {noChannels && (
+ <Tooltip
+ title={
+ !addNewChannelPermission
+ ? 'Ask an admin to create a notification channel'
+ : undefined
+ }
+ placement="right"
+ >
+ <Button
+ onClick={handleCreateNewChannels}
+ icon={<PlusOutlined />}
+ className="create-notification-btn"
+ disabled={!addNewChannelPermission}
+ >
+ Create a notification channel
+ </Button>
+ </Tooltip>
)}
</FormContainer>
</>
diff --git a/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx b/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx
index 15f391c7cf..ad1b9fb327 100644
--- a/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx
+++ b/frontend/src/container/FormAlertRules/ChannelSelect/index.tsx
@@ -1,9 +1,9 @@
import { Select } from 'antd';
-import getChannels from 'api/channels/getAll';
-import useFetch from 'hooks/useFetch';
+import { State } from 'hooks/useFetch';
import { useNotifications } from 'hooks/useNotifications';
import { ReactNode } from 'react';
import { useTranslation } from 'react-i18next';
+import { PayloadProps } from 'types/api/channels/getAll';
import { StyledSelect } from './styles';
@@ -11,38 +11,42 @@ export interface ChannelSelectProps {
disabled?: boolean;
currentValue?: string[];
onSelectChannels: (s: string[]) => void;
+ channels: State<PayloadProps | undefined>;
}
function ChannelSelect({
disabled,
currentValue,
onSelectChannels,
+ channels,
}: ChannelSelectProps): JSX.Element | null {
// init namespace for translations
const { t } = useTranslation('alerts');
- const { loading, payload, error, errorMessage } = useFetch(getChannels);
-
const { notifications } = useNotifications();
const handleChange = (value: string[]): void => {
onSelectChannels(value);
};
- if (error && errorMessage !== '') {
+ if (channels.error && channels.errorMessage !== '') {
notifications.error({
message: 'Error',
- description: errorMessage,
+ description: channels.errorMessage,
});
}
const renderOptions = (): ReactNode[] => {
const children: ReactNode[] = [];
- if (loading || payload === undefined || payload.length === 0) {
+ if (
+ channels.loading ||
+ channels.payload === undefined ||
+ channels.payload.length === 0
+ ) {
return children;
}
- payload.forEach((o) => {
+ channels.payload.forEach((o) => {
children.push(
<Select.Option key={o.id} value={o.name}>
{o.name}
@@ -55,7 +59,7 @@ function ChannelSelect({
return (
<StyledSelect
disabled={disabled}
- status={error ? 'error' : ''}
+ status={channels.error ? 'error' : ''}
mode="multiple"
style={{ width: '100%' }}
placeholder={t('placeholder_channel_select')}
diff --git a/frontend/src/container/FormAlertRules/FormAlertRules.styles.scss b/frontend/src/container/FormAlertRules/FormAlertRules.styles.scss
index 34a2b0b5f7..25b37923b5 100644
--- a/frontend/src/container/FormAlertRules/FormAlertRules.styles.scss
+++ b/frontend/src/container/FormAlertRules/FormAlertRules.styles.scss
@@ -71,3 +71,7 @@
}
}
}
+
+.create-notification-btn {
+ box-shadow: none;
+}