-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Endpoint] Task/basic endpoint list #55623
Changes from 18 commits
9aacfb3
79bfc46
5c8c42d
492aa37
2e82be8
275ab25
78c0914
2177319
6f75ee3
b3c444c
c497eeb
bce08a3
b01baf9
368796f
88c4406
9d374ea
b5adfe1
9057c06
9721e6a
a6782a4
594d036
bf678f3
a9c6b2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,20 +13,20 @@ import { Provider } from 'react-redux'; | |
import { Store } from 'redux'; | ||
import { appStoreFactory } from './store'; | ||
import { AlertIndex } from './view/alerts'; | ||
import { EndpointList } from './view/managing'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably should rename it to |
||
|
||
/** | ||
* This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. | ||
*/ | ||
export function renderApp(coreStart: CoreStart, { appBasePath, element }: AppMountParameters) { | ||
coreStart.http.get('/api/endpoint/hello-world'); | ||
|
||
const [store, stopSagas] = appStoreFactory(coreStart); | ||
const store = appStoreFactory(coreStart); | ||
|
||
ReactDOM.render(<AppRoot basename={appBasePath} store={store} />, element); | ||
|
||
return () => { | ||
ReactDOM.unmountComponentAtNode(element); | ||
stopSagas(); | ||
}; | ||
} | ||
|
||
|
@@ -49,22 +49,7 @@ const AppRoot: React.FunctionComponent<RouterProps> = React.memo(({ basename, st | |
</h1> | ||
)} | ||
/> | ||
<Route | ||
path="/management" | ||
render={() => { | ||
// FIXME: This is temporary. Will be removed in next PR for endpoint list | ||
store.dispatch({ type: 'userEnteredEndpointListPage' }); | ||
|
||
return ( | ||
<h1 data-test-subj="endpointManagement"> | ||
<FormattedMessage | ||
id="xpack.endpoint.endpointManagement" | ||
defaultMessage="Manage Endpoints" | ||
/> | ||
</h1> | ||
); | ||
}} | ||
/> | ||
<Route path="/management" component={EndpointList} /> | ||
<Route path="/alerts" component={AlertIndex} /> | ||
<Route | ||
render={() => ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,22 +4,24 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { EndpointListData } from './types'; | ||
import { ManagementPagination } from '../../types'; | ||
import { EndpointResultList } from '../../../../../common/types'; | ||
|
||
interface ServerReturnedEndpointList { | ||
type: 'serverReturnedEndpointList'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should rename this for consistency |
||
payload: EndpointListData; | ||
} | ||
|
||
interface UserEnteredEndpointListPage { | ||
type: 'userEnteredEndpointListPage'; | ||
payload: EndpointResultList; | ||
} | ||
|
||
interface UserExitedEndpointListPage { | ||
type: 'userExitedEndpointListPage'; | ||
} | ||
|
||
interface UserPaginatedEndpointListTable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should rename this for consistency |
||
type: 'userPaginatedEndpointListTable'; | ||
payload: ManagementPagination; | ||
} | ||
|
||
export type EndpointListAction = | ||
| ServerReturnedEndpointList | ||
| UserEnteredEndpointListPage | ||
| UserExitedEndpointListPage; | ||
| UserExitedEndpointListPage | ||
| UserPaginatedEndpointListTable; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* 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 { CoreStart, HttpSetup } from 'kibana/public'; | ||
import { applyMiddleware, createStore, Dispatch, Store } from 'redux'; | ||
import { coreMock } from '../../../../../../../../src/core/public/mocks'; | ||
import { endpointListReducer, managementMiddlewareFactory } from './index'; | ||
import { EndpointMetadata, EndpointResultList } from '../../../../../common/types'; | ||
import { ManagementState } from '../../types'; | ||
import { AppAction } from '../action'; | ||
import { listData } from './selectors'; | ||
describe('endpoint list saga', () => { | ||
const sleep = (ms = 100) => new Promise(wakeup => setTimeout(wakeup, ms)); | ||
let fakeCoreStart: jest.Mocked<CoreStart>; | ||
let fakeHttpServices: jest.Mocked<HttpSetup>; | ||
let store: Store<ManagementState>; | ||
let getState: typeof store['getState']; | ||
let dispatch: Dispatch<AppAction>; | ||
// https://github.com/elastic/endpoint-app-team/issues/131 | ||
const generateEndpoint = (): EndpointMetadata => { | ||
return { | ||
event: { | ||
created: new Date(0), | ||
}, | ||
endpoint: { | ||
policy: { | ||
id: '', | ||
}, | ||
}, | ||
agent: { | ||
version: '', | ||
id: '', | ||
}, | ||
host: { | ||
id: '', | ||
hostname: '', | ||
ip: [''], | ||
mac: [''], | ||
os: { | ||
name: '', | ||
full: '', | ||
version: '', | ||
}, | ||
}, | ||
}; | ||
}; | ||
const getEndpointListApiResponse = (): EndpointResultList => { | ||
return { | ||
endpoints: [generateEndpoint()], | ||
request_page_size: 1, | ||
request_page_index: 1, | ||
total: 10, | ||
}; | ||
}; | ||
beforeEach(() => { | ||
fakeCoreStart = coreMock.createStart({ basePath: '/mock' }); | ||
fakeHttpServices = fakeCoreStart.http as jest.Mocked<HttpSetup>; | ||
store = createStore( | ||
endpointListReducer, | ||
applyMiddleware(managementMiddlewareFactory(fakeCoreStart)) | ||
); | ||
getState = store.getState; | ||
dispatch = store.dispatch; | ||
}); | ||
test('it handles `userNavigatedToPage`', async () => { | ||
const apiResponse = getEndpointListApiResponse(); | ||
fakeHttpServices.post.mockResolvedValue(apiResponse); | ||
expect(fakeHttpServices.post).not.toHaveBeenCalled(); | ||
dispatch({ type: 'userNavigatedToPage', payload: 'managementPage' }); | ||
await sleep(); | ||
expect(fakeHttpServices.post).toHaveBeenCalledWith('/api/endpoint/endpoints', { | ||
body: JSON.stringify({ | ||
paging_properties: [{ page_index: 0 }, { page_size: 10 }], | ||
}), | ||
}); | ||
expect(listData(getState())).toEqual(apiResponse.endpoints); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 { MiddlewareFactory } from '../../types'; | ||
import { pageIndex, pageSize } from './selectors'; | ||
import { ManagementState } from '../../types'; | ||
import { AppAction } from '../action'; | ||
|
||
export const managementMiddlewareFactory: MiddlewareFactory<ManagementState> = coreStart => { | ||
return ({ getState, dispatch }) => next => async (action: AppAction) => { | ||
next(action); | ||
if ( | ||
(action.type === 'userNavigatedToPage' && action.payload === 'managementPage') || | ||
action.type === 'userPaginatedEndpointListTable' | ||
) { | ||
const managementPageIndex = pageIndex(getState()); | ||
const managementPageSize = pageSize(getState()); | ||
const response = await coreStart.http.post('/api/endpoint/endpoints', { | ||
body: JSON.stringify({ | ||
paging_properties: [ | ||
{ page_index: managementPageIndex }, | ||
{ page_size: managementPageSize }, | ||
], | ||
}), | ||
}); | ||
response.request_page_index = managementPageIndex; | ||
dispatch({ | ||
type: 'serverReturnedEndpointList', | ||
payload: response, | ||
}); | ||
dispatch({ type: 'serverReturnedAlertsData', payload: response }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this looks like a bad "copy-and-paste" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it should not be there |
||
} | ||
}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❔
endpointListPage
was more descriptive - just curious why it was changed?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're trying to move away from the smp usage of the word endpoint and move toward what will be more consistent in kibana. smp endpoint --> management, and smp sensor --> endpoint