Skip to content

Commit

Permalink
Resolved merge conflicts with the alerting team's PR
Browse files Browse the repository at this point in the history
  • Loading branch information
igoristic committed Dec 8, 2020
1 parent d7612f3 commit b225580
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/public/alerts/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const AlertsBadge: React.FC<Props> = (props: Props) => {
const { stateFilter = () => true } = props;
const [showPopover, setShowPopover] = React.useState<AlertSeverity | boolean | null>(null);
const inSetupMode = isInSetupMode(React.useContext(SetupModeContext));
const alerts = Object.values(props.alerts).filter(Boolean);
const alerts = Object.values(props.alerts).filter((alertItem) => Boolean(alertItem?.rawAlert));

if (alerts.length === 0) {
return null;
Expand Down
29 changes: 13 additions & 16 deletions x-pack/plugins/monitoring/public/alerts/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,24 @@ import { SetupModeContext } from '../components/setup_mode/setup_mode_context';
interface Props {
alert: CommonAlertStatus;
alertState?: CommonAlertState;
nextStepsFilter: (nextStep: AlertMessage) => boolean;
}
export const AlertPanel: React.FC<Props> = (props: Props) => {
const {
alert: { alert },
alert: { rawAlert },
alertState,
nextStepsFilter = () => true,
} = props;

const [showFlyout, setShowFlyout] = React.useState(false);
const [isEnabled, setIsEnabled] = React.useState(alert.rawAlert.enabled);
const [isMuted, setIsMuted] = React.useState(alert.rawAlert.muteAll);
const [isEnabled, setIsEnabled] = React.useState(rawAlert?.enabled);
const [isMuted, setIsMuted] = React.useState(rawAlert?.muteAll);
const [isSaving, setIsSaving] = React.useState(false);
const inSetupMode = isInSetupMode(React.useContext(SetupModeContext));

const flyoutUi = useMemo(
() =>
showFlyout &&
Legacy.shims.triggersActionsUi.getEditAlertFlyout({
initialAlert: alert.rawAlert,
initialAlert: rawAlert,
onClose: () => {
setShowFlyout(false);
showBottomBar();
Expand All @@ -56,14 +55,14 @@ export const AlertPanel: React.FC<Props> = (props: Props) => {
[showFlyout]
);

if (!alert.rawAlert) {
if (!rawAlert) {
return null;
}

async function disableAlert() {
setIsSaving(true);
try {
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${alert.rawAlert.id}/_disable`);
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${rawAlert.id}/_disable`);
} catch (err) {
Legacy.shims.toastNotifications.addDanger({
title: i18n.translate('xpack.monitoring.alerts.panel.disableAlert.errorTitle', {
Expand All @@ -77,7 +76,7 @@ export const AlertPanel: React.FC<Props> = (props: Props) => {
async function enableAlert() {
setIsSaving(true);
try {
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${alert.rawAlert.id}/_enable`);
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${rawAlert.id}/_enable`);
} catch (err) {
Legacy.shims.toastNotifications.addDanger({
title: i18n.translate('xpack.monitoring.alerts.panel.enableAlert.errorTitle', {
Expand All @@ -91,7 +90,7 @@ export const AlertPanel: React.FC<Props> = (props: Props) => {
async function muteAlert() {
setIsSaving(true);
try {
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${alert.rawAlert.id}/_mute_all`);
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${rawAlert.id}/_mute_all`);
} catch (err) {
Legacy.shims.toastNotifications.addDanger({
title: i18n.translate('xpack.monitoring.alerts.panel.muteAlert.errorTitle', {
Expand All @@ -105,7 +104,7 @@ export const AlertPanel: React.FC<Props> = (props: Props) => {
async function unmuteAlert() {
setIsSaving(true);
try {
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${alert.rawAlert.id}/_unmute_all`);
await Legacy.shims.http.post(`${BASE_ALERT_API_PATH}/alert/${rawAlert.id}/_unmute_all`);
} catch (err) {
Legacy.shims.toastNotifications.addDanger({
title: i18n.translate('xpack.monitoring.alerts.panel.ummuteAlert.errorTitle', {
Expand Down Expand Up @@ -189,11 +188,9 @@ export const AlertPanel: React.FC<Props> = (props: Props) => {
const nextStepsUi =
alertState.state.ui.message.nextSteps && alertState.state.ui.message.nextSteps.length ? (
<EuiListGroup>
{alertState.state.ui.message.nextSteps
.filter(nextStepsFilter)
.map((step: AlertMessage, index: number) => (
<EuiListGroupItem size="s" key={index} label={replaceTokens(step)} />
))}
{alertState.state.ui.message.nextSteps.map((step: AlertMessage, index: number) => (
<EuiListGroupItem size="s" key={index} label={replaceTokens(step)} />
))}
</EuiListGroup>
) : null;

Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/monitoring/server/alerts/alerts_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export class AlertsFactory {

if (!alertClientAlerts.total || !alertClientAlerts.data?.length) {
return;
// return new alertCls() as BaseAlert;
}

const [rawAlert] = alertClientAlerts.data as [Alert];
Expand Down

0 comments on commit b225580

Please sign in to comment.