-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…115589) * transform alert flyout * fetch alerting rules * show alerting rules indicators * filter continuous transforms * add alert rules to the expanded row * edit alert rule from the list * fix ts issues * fix types * update texts * refactor using context, wip create alert from the list * update unit test * fix ts issue * privilege check Co-authored-by: Dima Arnautov <[email protected]>
- Loading branch information
1 parent
f1467bd
commit 5f38cac
Showing
33 changed files
with
539 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
x-pack/plugins/transform/public/alerting/transform_alerting_flyout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { createContext, FC, useContext, useMemo } from 'react'; | ||
import { memoize } from 'lodash'; | ||
import { BehaviorSubject, Observable } from 'rxjs'; | ||
import { pluck } from 'rxjs/operators'; | ||
import useObservable from 'react-use/lib/useObservable'; | ||
import { useAppDependencies } from '../app/app_dependencies'; | ||
import { TransformHealthAlertRule, TransformHealthRuleParams } from '../../common/types/alerting'; | ||
import { TRANSFORM_RULE_TYPE } from '../../common'; | ||
|
||
interface TransformAlertFlyoutProps { | ||
initialAlert?: TransformHealthAlertRule | null; | ||
ruleParams?: TransformHealthRuleParams | null; | ||
onSave?: () => void; | ||
onCloseFlyout: () => void; | ||
} | ||
|
||
export const TransformAlertFlyout: FC<TransformAlertFlyoutProps> = ({ | ||
initialAlert, | ||
ruleParams, | ||
onCloseFlyout, | ||
onSave, | ||
}) => { | ||
const { triggersActionsUi } = useAppDependencies(); | ||
|
||
const AlertFlyout = useMemo(() => { | ||
if (!triggersActionsUi) return; | ||
|
||
const commonProps = { | ||
onClose: () => { | ||
onCloseFlyout(); | ||
}, | ||
onSave: async () => { | ||
if (onSave) { | ||
onSave(); | ||
} | ||
}, | ||
}; | ||
|
||
if (initialAlert) { | ||
return triggersActionsUi.getEditAlertFlyout({ | ||
...commonProps, | ||
initialAlert, | ||
}); | ||
} | ||
|
||
return triggersActionsUi.getAddAlertFlyout({ | ||
...commonProps, | ||
consumer: 'stackAlerts', | ||
canChangeTrigger: false, | ||
alertTypeId: TRANSFORM_RULE_TYPE.TRANSFORM_HEALTH, | ||
metadata: {}, | ||
initialValues: { | ||
params: ruleParams!, | ||
}, | ||
}); | ||
// deps on id to avoid re-rendering on auto-refresh | ||
}, [triggersActionsUi, initialAlert, ruleParams, onCloseFlyout, onSave]); | ||
|
||
return <>{AlertFlyout}</>; | ||
}; | ||
|
||
interface AlertRulesManage { | ||
editAlertRule$: Observable<TransformHealthAlertRule | null>; | ||
createAlertRule$: Observable<TransformHealthRuleParams | null>; | ||
setEditAlertRule: (alertRule: TransformHealthAlertRule) => void; | ||
setCreateAlertRule: (transformId: string) => void; | ||
hideAlertFlyout: () => void; | ||
} | ||
|
||
export const getAlertRuleManageContext = memoize(function (): AlertRulesManage { | ||
const ruleState$ = new BehaviorSubject<{ | ||
editAlertRule: null | TransformHealthAlertRule; | ||
createAlertRule: null | TransformHealthRuleParams; | ||
}>({ | ||
editAlertRule: null, | ||
createAlertRule: null, | ||
}); | ||
return { | ||
editAlertRule$: ruleState$.pipe(pluck('editAlertRule')), | ||
createAlertRule$: ruleState$.pipe(pluck('createAlertRule')), | ||
setEditAlertRule: (initialRule) => { | ||
ruleState$.next({ | ||
createAlertRule: null, | ||
editAlertRule: initialRule, | ||
}); | ||
}, | ||
setCreateAlertRule: (transformId: string) => { | ||
ruleState$.next({ | ||
createAlertRule: { includeTransforms: [transformId] }, | ||
editAlertRule: null, | ||
}); | ||
}, | ||
hideAlertFlyout: () => { | ||
ruleState$.next({ | ||
createAlertRule: null, | ||
editAlertRule: null, | ||
}); | ||
}, | ||
}; | ||
}); | ||
|
||
export const AlertRulesManageContext = createContext<AlertRulesManage>(getAlertRuleManageContext()); | ||
|
||
export function useAlertRuleFlyout(): AlertRulesManage { | ||
return useContext(AlertRulesManageContext); | ||
} | ||
|
||
export const TransformAlertFlyoutWrapper = () => { | ||
const { editAlertRule$, createAlertRule$, hideAlertFlyout } = useAlertRuleFlyout(); | ||
const editAlertRule = useObservable(editAlertRule$); | ||
const createAlertRule = useObservable(createAlertRule$); | ||
|
||
return editAlertRule || createAlertRule ? ( | ||
<TransformAlertFlyout | ||
initialAlert={editAlertRule} | ||
ruleParams={createAlertRule!} | ||
onCloseFlyout={hideAlertFlyout} | ||
/> | ||
) : null; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.