Merge pull request #6458 from jakemcdermott/6435-fix-notification-toggle-disable

Limit disable-on-load to single notifications

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
softwarefactory-project-zuul[bot] 2020-03-27 17:59:46 +00:00 committed by GitHub
commit 5f62426684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,7 +25,7 @@ class NotificationList extends Component {
contentError: null,
hasContentLoading: true,
toggleError: false,
toggleLoading: false,
loadingToggleIds: [],
itemCount: 0,
notifications: [],
startedTemplateIds: [],
@ -147,7 +147,9 @@ class NotificationList extends Component {
});
}
this.setState({ toggleLoading: true });
this.setState(({ loadingToggleIds }) => ({
loadingToggleIds: loadingToggleIds.concat([notificationId]),
}));
try {
if (isCurrentlyOn) {
await apiModel.disassociateNotificationTemplate(
@ -166,7 +168,11 @@ class NotificationList extends Component {
} catch (err) {
this.setState({ toggleError: err });
} finally {
this.setState({ toggleLoading: false });
this.setState(({ loadingToggleIds }) => ({
loadingToggleIds: loadingToggleIds.filter(
item => item !== notificationId
),
}));
}
}
@ -180,7 +186,7 @@ class NotificationList extends Component {
contentError,
hasContentLoading,
toggleError,
toggleLoading,
loadingToggleIds,
itemCount,
notifications,
startedTemplateIds,
@ -240,7 +246,10 @@ class NotificationList extends Component {
key={notification.id}
notification={notification}
detailUrl={`/notifications/${notification.id}`}
canToggleNotifications={canToggleNotifications && !toggleLoading}
canToggleNotifications={
canToggleNotifications &&
!loadingToggleIds.includes(notification.id)
}
toggleNotification={this.handleNotificationToggle}
errorTurnedOn={errorTemplateIds.includes(notification.id)}
startedTurnedOn={startedTemplateIds.includes(notification.id)}
@ -252,7 +261,7 @@ class NotificationList extends Component {
<AlertModal
variant="error"
title={i18n._(t`Error!`)}
isOpen={toggleError && !toggleLoading}
isOpen={toggleError && loadingToggleIds.length === 0}
onClose={this.handleNotificationErrorClose}
>
{i18n._(t`Failed to toggle notification.`)}