-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic Functionality Alert List (#55800)
* sets up initial grid and data type * data feeds in from backend but doesnt update * sample data feeding in correctly * Fix combineReducers issue by importing Redux type from 'redux' package * Add usePageId hook that fires action when user navigates to page * Strict typing for middleware * addresses comments and uses better types * move types to common/types.ts * Move types to endpoint/types.ts, address PR comments blah 2 Co-authored-by: Pedro Jaramillo <peluja1012@gmail.com>
- Loading branch information
1 parent
0d2ac94
commit 1ca013a
Showing
22 changed files
with
11,716 additions
and
16 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
11 changes: 11 additions & 0 deletions
11
x-pack/plugins/endpoint/public/applications/endpoint/store/action.ts
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,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EndpointListAction } from './endpoint_list'; | ||
import { AlertAction } from './alerts'; | ||
import { RoutingAction } from './routing'; | ||
|
||
export type AppAction = EndpointListAction | AlertAction | RoutingAction; |
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/action.ts
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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { AlertData, Immutable } from '../../../../../common/types'; | ||
|
||
type ServerReturnedAlertsData = Immutable<{ | ||
type: 'serverReturnedAlertsData'; | ||
payload: AlertData[]; | ||
}>; | ||
|
||
export type AlertAction = ServerReturnedAlertsData; |
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
19 changes: 19 additions & 0 deletions
19
x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts
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,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { AlertData, ImmutableArray } from '../../../../../common/types'; | ||
import { AppAction } from '../action'; | ||
import { MiddlewareFactory } from '../../types'; | ||
|
||
export const alertMiddlewareFactory: MiddlewareFactory = coreStart => { | ||
return api => next => async (action: AppAction) => { | ||
next(action); | ||
if (action.type === 'userNavigatedToPage' && action.payload === 'alertsPage') { | ||
const response: ImmutableArray<AlertData> = await coreStart.http.get('/api/endpoint/alerts'); | ||
api.dispatch({ type: 'serverReturnedAlertsData', payload: response }); | ||
} | ||
}; | ||
}; |
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/reducer.ts
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,29 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Reducer } from 'redux'; | ||
import { AlertListState } from '../../types'; | ||
import { AppAction } from '../action'; | ||
|
||
const initialState = (): AlertListState => { | ||
return { | ||
alerts: [], | ||
}; | ||
}; | ||
|
||
export const alertListReducer: Reducer<AlertListState, AppAction> = ( | ||
state = initialState(), | ||
action | ||
) => { | ||
if (action.type === 'serverReturnedAlertsData') { | ||
return { | ||
...state, | ||
alerts: action.payload, | ||
}; | ||
} | ||
|
||
return state; | ||
}; |
9 changes: 9 additions & 0 deletions
9
x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/selectors.ts
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,9 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { AlertListState } from '../../types'; | ||
|
||
export const alertListData = (state: AlertListState) => state.alerts; |
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
14 changes: 14 additions & 0 deletions
14
x-pack/plugins/endpoint/public/applications/endpoint/store/routing/action.ts
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,14 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { PageId } from '../../../../../common/types'; | ||
|
||
interface UserNavigatedToPage { | ||
readonly type: 'userNavigatedToPage'; | ||
readonly payload: PageId; | ||
} | ||
|
||
export type RoutingAction = UserNavigatedToPage; |
7 changes: 7 additions & 0 deletions
7
x-pack/plugins/endpoint/public/applications/endpoint/store/routing/index.ts
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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { RoutingAction } from './action'; |
31 changes: 31 additions & 0 deletions
31
x-pack/plugins/endpoint/public/applications/endpoint/store/selectors.ts
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,31 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { GlobalState } from '../types'; | ||
import * as alertListSelectors from './alerts/selectors'; | ||
|
||
export const alertListData = composeSelectors( | ||
alertListStateSelector, | ||
alertListSelectors.alertListData | ||
); | ||
|
||
/** | ||
* Returns the alert list state from within Global State | ||
*/ | ||
function alertListStateSelector(state: GlobalState) { | ||
return state.alertList; | ||
} | ||
|
||
/** | ||
* Calls the `secondSelector` with the result of the `selector`. Use this when re-exporting a | ||
* concern-specific selector. `selector` should return the concern-specific state. | ||
*/ | ||
function composeSelectors<OuterState, InnerState, ReturnValue>( | ||
selector: (state: OuterState) => InnerState, | ||
secondSelector: (state: InnerState) => ReturnValue | ||
): (state: OuterState) => ReturnValue { | ||
return state => secondSelector(selector(state)); | ||
} |
26 changes: 26 additions & 0 deletions
26
x-pack/plugins/endpoint/public/applications/endpoint/types.ts
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,26 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Dispatch, MiddlewareAPI } from 'redux'; | ||
import { CoreStart } from 'kibana/public'; | ||
import { Immutable, AlertData } from '../../../common/types'; | ||
import { EndpointListState } from './store/endpoint_list'; | ||
import { AppAction } from './store/action'; | ||
|
||
export type MiddlewareFactory = ( | ||
coreStart: CoreStart | ||
) => ( | ||
api: MiddlewareAPI<Dispatch<AppAction>, GlobalState> | ||
) => (next: Dispatch<AppAction>) => (action: AppAction) => unknown; | ||
|
||
export type AlertListState = Immutable<{ | ||
alerts: AlertData[]; | ||
}>; | ||
|
||
export interface GlobalState { | ||
readonly endpointList: EndpointListState; | ||
readonly alertList: AlertListState; | ||
} |
Oops, something went wrong.