diff --git a/x-pack/plugins/triggers_actions_ui/public/application/constants/index.ts b/x-pack/plugins/triggers_actions_ui/public/application/constants/index.ts index 265cfddab4c06..db2edda5e16e4 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/constants/index.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/constants/index.ts @@ -6,6 +6,7 @@ export { BASE_ALERT_API_PATH } from '../../../../alerting/common'; export { BASE_ACTION_API_PATH } from '../../../../actions/common'; +export { BASE_EVENT_LOG_API_PATH } from '../../../../event_log/common'; export const BASE_PATH = '/management/insightsAndAlerting/triggersActions'; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.ts b/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.ts index 2176f978822ca..f2ab7c6607513 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.ts +++ b/x-pack/plugins/triggers_actions_ui/public/application/lib/alert_api.ts @@ -10,7 +10,7 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { fold } from 'fp-ts/lib/Either'; import { pick } from 'lodash'; import { alertStateSchema, AlertingFrameworkHealth } from '../../../../alerting/common'; -import { BASE_ALERT_API_PATH } from '../constants'; +import { BASE_ALERT_API_PATH, BASE_EVENT_LOG_API_PATH } from '../constants'; import { Alert, AlertType, AlertWithoutId, AlertTaskState } from '../../types'; export async function loadAlertTypes({ http }: { http: HttpSetup }): Promise { @@ -220,3 +220,17 @@ export async function unmuteAlerts({ export async function health({ http }: { http: HttpSetup }): Promise { return await http.get(`${BASE_ALERT_API_PATH}/_health`); } + +export async function getEvents({ id, http }: { id: string; http: HttpSetup }): Promise { + // per_page: schema.number({ defaultValue: 10, min: 0 }), + // page: schema.number({ defaultValue: 1, min: 1 }), + // start: optionalDateFieldSchema, + // end: optionalDateFieldSchema, + + return await http.get(`${BASE_EVENT_LOG_API_PATH}/alert/${id}`, { + query: { + per_page: 1000, + page: 1, + }, + }); +} diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.tsx index 9deeeb96124c8..e84a52eedbee7 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances.tsx @@ -21,6 +21,7 @@ import { DEFAULT_SEARCH_PAGE_SIZE } from '../../../constants'; type AlertInstancesProps = { alert: Alert; alertState: AlertTaskState; + // events: unknown; requestRefresh: () => Promise; durationEpoch?: number; } & Pick; diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.tsx index a02b44523e26c..4bd1a225154b9 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/alert_details/components/alert_instances_route.tsx @@ -19,24 +19,32 @@ import { AlertInstancesWithApi as AlertInstances } from './alert_instances'; type WithAlertStateProps = { alert: Alert; requestRefresh: () => Promise; -} & Pick; +} & Pick; export const AlertInstancesRoute: React.FunctionComponent = ({ alert, requestRefresh, loadAlertState, + // getEvents, }) => { const { toastNotifications } = useAppDependencies(); const [alertState, setAlertState] = useState(null); + // const [events, setEvents] = useState(null); useEffect(() => { + // TODO get events here getAlertState(alert.id, loadAlertState, setAlertState, toastNotifications); // eslint-disable-next-line react-hooks/exhaustive-deps }, [alert]); - return alertState ? ( - + return alertState /* && events */ ? ( + ) : (
>, +// toastNotifications: Pick +// ) { +// } + export const AlertInstancesRouteWithApi = withBulkAlertOperations(AlertInstancesRoute); diff --git a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_bulk_alert_api_operations.tsx b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_bulk_alert_api_operations.tsx index 0c6f71120cc2e..1c692bbb75e5f 100644 --- a/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_bulk_alert_api_operations.tsx +++ b/x-pack/plugins/triggers_actions_ui/public/application/sections/common/components/with_bulk_alert_api_operations.tsx @@ -24,6 +24,7 @@ import { loadAlertState, loadAlertTypes, health, + // getEvents, } from '../../../lib/alert_api'; export interface ComponentOpts { @@ -53,6 +54,7 @@ export interface ComponentOpts { loadAlertState: (id: Alert['id']) => Promise; loadAlertTypes: () => Promise; getHealth: () => Promise; + // getEvents: () => Promise; } export type PropsWithOptionalApiHandlers = Omit & Partial; @@ -121,6 +123,7 @@ export function withBulkAlertOperations( loadAlertState={async (alertId: Alert['id']) => loadAlertState({ http, alertId })} loadAlertTypes={async () => loadAlertTypes({ http })} getHealth={async () => health({ http })} + // getEvents={async (alertId: Alert['id']) => getEvents({ http, id: alertId })} /> ); };