Skip to content

Commit

Permalink
Modify code to work well
Browse files Browse the repository at this point in the history
  • Loading branch information
Puridach Wutthihathaithamrong committed Feb 21, 2024
1 parent d651ef4 commit 9a46987
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
11 changes: 2 additions & 9 deletions superset-frontend/src/features/alerts/AlertReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1250,14 +1250,6 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
}
};

const updatedNotificationSettings = notificationSettings.map(setting => {
const updatedEmailSubject = setting.email_subject || emailSubject;
return {
...setting,
email_subject: updatedEmailSubject,
};
});

return (
<StyledModal
className="no-content-padding"
Expand Down Expand Up @@ -1694,7 +1686,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
}
key="notification"
>
{updatedNotificationSettings.map((notificationSetting, i) => {
{notificationSettings.map((notificationSetting, i) => {

Check failure on line 1689 in superset-frontend/src/features/alerts/AlertReportModal.tsx

View workflow job for this annotation

GitHub Actions / frontend-build

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
return (
<StyledNotificationMethodWrapper
key={`NotificationMethodWrapper-${i}`}
Expand All @@ -1706,6 +1698,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
onUpdate={updateNotificationSetting}
onRemove={removeNotificationSetting}
onInputChange={onInputChange}
email_subject={currentAlert?.email_subject || ''}
defaultSubject={emailSubject || ''}
/>
</StyledNotificationMethodWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ const StyledNotificationMethod = styled.div`

type NotificationSetting = {
method?: NotificationMethodOption;
email_subject?: string;
recipients: string;
options: NotificationMethodOption[];
email_subject: string;
};

interface NotificationMethodProps {
Expand All @@ -61,6 +61,7 @@ interface NotificationMethodProps {
onInputChange?: (
event: React.ChangeEvent<HTMLTextAreaElement | HTMLInputElement>,
) => void;
email_subject?: string;
defaultSubject?: string;
}

Expand All @@ -74,9 +75,10 @@ export const NotificationMethod: FunctionComponent<NotificationMethodProps> = ({
onUpdate,
onRemove,
onInputChange,
email_subject,
defaultSubject,
}) => {
const { method, recipients, options, email_subject } = setting || {};
const { method, recipients, options } = setting || {};
const [recipientValue, setRecipientValue] = useState<string>(
recipients || '',
);
Expand All @@ -85,6 +87,18 @@ export const NotificationMethod: FunctionComponent<NotificationMethodProps> = ({
);
const theme = useTheme();

useEffect(() => {
if (onUpdate) {
const updatedSetting: NotificationSetting = {
...setting,
email_subject: defaultSubject,
recipients: setting?.recipients ?? '',
options: setting?.options ?? [],
};
onUpdate(index, updatedSetting);
}
}, []);

useEffect(() => {
setEmailSubject(email_subject || defaultSubject);
}, [defaultSubject]);
Expand Down
2 changes: 2 additions & 0 deletions tests/integration_tests/reports/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,7 @@ def test_create_multiple_creation_method_report_schedule_dashboards(self):
"crontab": "0 9 * * *",
"working_timeout": 3600,
"dashboard": dashboard.id,
"email_subject": "Subject",
}
uri = "api/v1/report/"
rv = self.post_assert_metric(uri, report_schedule_data, "post")
Expand All @@ -1057,6 +1058,7 @@ def test_create_multiple_creation_method_report_schedule_dashboards(self):
"crontab": "0 9 * * *",
"working_timeout": 3600,
"dashboard": dashboard.id,
"email_subject": "Subject",
}
uri = "api/v1/report/"
rv = self.post_assert_metric(uri, report_schedule_data, "post")
Expand Down

0 comments on commit 9a46987

Please sign in to comment.