Skip to content

Commit

Permalink
updating notification method logic
Browse files Browse the repository at this point in the history
lint

editing pattern to filter reduce
  • Loading branch information
fisjac committed Mar 27, 2024
1 parent ce02f8f commit 59f9cdb
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
42 changes: 30 additions & 12 deletions superset-frontend/src/features/alerts/AlertReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -492,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',
);
Expand Down Expand Up @@ -542,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');

Check warning on line 564 in superset-frontend/src/features/alerts/AlertReportModal.tsx

View check run for this annotation

Codecov / codecov/patch

superset-frontend/src/features/alerts/AlertReportModal.tsx#L564

Added line #L564 was not covered by tests
}

if (setting.method !== undefined && notificationAddState !== 'hidden') {
setNotificationAddState('active');
if (setting.method !== undefined && notificationAddState !== 'hidden') {
setNotificationAddState('active');
}
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export const NotificationMethod: FunctionComponent<NotificationMethodProps> = ({
)}
value={method}
/>
{method !== undefined && index !== 0 && !!onRemove ? (
{index !== 0 && !!onRemove ? (
<span
role="button"
tabIndex={0}
Expand Down
1 change: 0 additions & 1 deletion superset-frontend/src/features/alerts/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,3 @@ export enum Sections {
Schedule = 'scheduleSection',
Notification = 'notificationSection',
}

0 comments on commit 59f9cdb

Please sign in to comment.