You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2024/04/10 19:49:13 UTC
(superset) branch master updated: fix(alerts/reports): removing duplicate notification method options (#27239)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new eb4ca010ae fix(alerts/reports): removing duplicate notification method options (#27239)
eb4ca010ae is described below
commit eb4ca010ae6f79853f5a7f821bd93925e06b920b
Author: Jack <41...@users.noreply.github.com>
AuthorDate: Wed Apr 10 14:49:08 2024 -0500
fix(alerts/reports): removing duplicate notification method options (#27239)
---
.../src/features/alerts/AlertReportModal.tsx | 49 ++++++++++++++--------
.../alerts/components/NotificationMethod.tsx | 10 +----
superset-frontend/src/features/alerts/types.ts | 6 +++
3 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/superset-frontend/src/features/alerts/AlertReportModal.tsx b/superset-frontend/src/features/alerts/AlertReportModal.tsx
index 2a9a9f438d..50e2380b5f 100644
--- a/superset-frontend/src/features/alerts/AlertReportModal.tsx
+++ b/superset-frontend/src/features/alerts/AlertReportModal.tsx
@@ -50,6 +50,7 @@ import { useCommonConf } from 'src/features/databases/state';
import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
import {
NotificationMethodOption,
+ NotificationSetting,
AlertObject,
ChartObject,
DashboardObject,
@@ -395,12 +396,6 @@ const NotificationMethodAdd: FunctionComponent<NotificationMethodAddProps> = ({
);
};
-type NotificationSetting = {
- method?: NotificationMethodOption;
- recipients: string;
- options: NotificationMethodOption[];
-};
-
const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
addDangerToast,
onAdd,
@@ -497,15 +492,26 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
NotificationSetting[]
>([]);
const onNotificationAdd = () => {
- const settings: NotificationSetting[] = notificationSettings.slice();
- settings.push({
- recipients: '',
- options: allowedNotificationMethods,
- });
+ setNotificationSettings([
+ ...notificationSettings,
+ {
+ recipients: '',
+ // options shown in the newly added notification method
+ options: allowedNotificationMethods.filter(
+ // are filtered such that
+ option =>
+ // options are not included
+ !notificationSettings.reduce(
+ // when it exists in previous notificationSettings
+ (accum, setting) => accum || option === setting.method,
+ false,
+ ),
+ ),
+ },
+ ]);
- setNotificationSettings(settings);
setNotificationAddState(
- settings.length === allowedNotificationMethods.length
+ notificationSettings.length === allowedNotificationMethods.length
? 'hidden'
: 'disabled',
);
@@ -547,13 +553,20 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
index: number,
setting: NotificationSetting,
) => {
- const settings = notificationSettings.slice();
+ // if you've changed notification method
+ if (notificationSettings[index].method !== setting.method) {
+ notificationSettings[index] = setting;
- settings[index] = setting;
- setNotificationSettings(settings);
+ setNotificationSettings(
+ notificationSettings.filter((_, idx) => idx <= index),
+ );
+ if (notificationSettings.length - 1 > index) {
+ setNotificationAddState('active');
+ }
- if (setting.method !== undefined && notificationAddState !== 'hidden') {
- setNotificationAddState('active');
+ if (setting.method !== undefined && notificationAddState !== 'hidden') {
+ setNotificationAddState('active');
+ }
}
};
diff --git a/superset-frontend/src/features/alerts/components/NotificationMethod.tsx b/superset-frontend/src/features/alerts/components/NotificationMethod.tsx
index 1708c76f76..b50988700e 100644
--- a/superset-frontend/src/features/alerts/components/NotificationMethod.tsx
+++ b/superset-frontend/src/features/alerts/components/NotificationMethod.tsx
@@ -20,7 +20,7 @@ import React, { FunctionComponent, useState } from 'react';
import { styled, t, useTheme } from '@superset-ui/core';
import { Select } from 'src/components';
import Icons from 'src/components/Icons';
-import { NotificationMethodOption } from '../types';
+import { NotificationMethodOption, NotificationSetting } from '../types';
import { StyledInputContainer } from '../AlertReportModal';
const StyledNotificationMethod = styled.div`
@@ -46,12 +46,6 @@ const StyledNotificationMethod = styled.div`
}
`;
-type NotificationSetting = {
- method?: NotificationMethodOption;
- recipients: string;
- options: NotificationMethodOption[];
-};
-
interface NotificationMethodProps {
setting?: NotificationSetting | null;
index: number;
@@ -130,7 +124,7 @@ export const NotificationMethod: FunctionComponent<NotificationMethodProps> = ({
)}
value={method}
/>
- {method !== undefined && index !== 0 && !!onRemove ? (
+ {index !== 0 && !!onRemove ? (
<span
role="button"
tabIndex={0}
diff --git a/superset-frontend/src/features/alerts/types.ts b/superset-frontend/src/features/alerts/types.ts
index c4264c7912..6dd57ccf0a 100644
--- a/superset-frontend/src/features/alerts/types.ts
+++ b/superset-frontend/src/features/alerts/types.ts
@@ -43,6 +43,12 @@ export type DatabaseObject = {
export type NotificationMethodOption = 'Email' | 'Slack';
+export type NotificationSetting = {
+ method?: NotificationMethodOption;
+ recipients: string;
+ options: NotificationMethodOption[];
+};
+
export type Recipient = {
recipient_config_json: {
target: string;