Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Alerting UI] Added visual indicator when enable switched click is processed on the server side. #107272

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
* 2.0.
*/

import { asyncScheduler } from 'rxjs';
import React, { useEffect, useState } from 'react';
import { EuiSwitch } from '@elastic/eui';
import React, { useState } from 'react';
import { EuiSwitch, EuiLoadingSpinner } from '@elastic/eui';

import { Alert, AlertTableItem } from '../../../../types';

Expand All @@ -24,31 +23,32 @@ export const RuleEnabledSwitch: React.FunctionComponent<ComponentOpts> = ({
disableAlert,
enableAlert,
}: ComponentOpts) => {
const [isEnabled, setIsEnabled] = useState<boolean>(!item.enabled);
useEffect(() => {
setIsEnabled(item.enabled);
}, [item.enabled]);
const [isEnabled, setIsEnabled] = useState<boolean>(item.enabled);
const [isUpdating, setIsUpdating] = useState<boolean>(false);

return (
const res = isUpdating ? (
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
<EuiLoadingSpinner size="m" />
) : (
<EuiSwitch
name="enable"
disabled={!item.isEditable || !item.enabledInLicense}
compressed
checked={isEnabled}
data-test-subj="enableSwitch"
onChange={async () => {
const enabled = isEnabled;
asyncScheduler.schedule(async () => {
if (enabled) {
await disableAlert({ ...item, enabled });
} else {
await enableAlert({ ...item, enabled });
}
onAlertChanged();
}, 10);
setIsUpdating(true);
const enabled = item.enabled;
if (enabled) {
await disableAlert({ ...item, enabled });
} else {
await enableAlert({ ...item, enabled });
}
setIsEnabled(!isEnabled);
setIsUpdating(false);
onAlertChanged();
}}
label=""
/>
);
return res;
};