From 9aacfb3efdea8823663c7ca89af26ae5c91b2d39 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Tue, 14 Jan 2020 15:38:25 -0500 Subject: [PATCH 01/19] add columns w/ api call --- .../public/applications/endpoint/index.tsx | 11 +- .../applications/endpoint/management.tsx | 114 ++++++++++++++++++ 2 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/management.tsx diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index 9bea41126d296..6ec298ee1890a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -13,6 +13,7 @@ import { Provider } from 'react-redux'; import { Store } from 'redux'; import { appStoreFactory } from './store'; import { AlertIndex } from './view/alerts'; +import { EndpointList } from './management'; /** * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. @@ -54,15 +55,7 @@ const AppRoot: React.FunctionComponent = React.memo(({ basename, st render={() => { // FIXME: This is temporary. Will be removed in next PR for endpoint list store.dispatch({ type: 'userEnteredEndpointListPage' }); - - return ( -

- -

- ); + return ; }} /> diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/management.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/management.tsx new file mode 100644 index 0000000000000..df66684b0da82 --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/management.tsx @@ -0,0 +1,114 @@ +/* + * 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 React, { useState, useEffect } from 'react'; +import { + EuiPage, + EuiPageBody, + EuiPageContent, + EuiPageContentBody, + EuiPageContentHeader, + EuiPageContentHeaderSection, + EuiPageHeader, + EuiPageHeaderSection, + EuiTitle, + EuiBasicTable, +} from '@elastic/eui'; +import { CoreStart } from 'kibana/public'; + +export const EndpointList = ({ coreStart }: { coreStart: CoreStart }) => { + const [results, setResults] = useState([]); + const [wasFetched, setWasFetched] = useState(false); + + useEffect(() => { + async function fetchEndpointListData() { + const response = await coreStart.http.post('/api/endpoint/endpoints', { + query: {}, + }); + setResults(response.endpoints); + } + if (wasFetched === false) { + setWasFetched(true); + fetchEndpointListData(); + } + }, [coreStart, results, wasFetched]); + + const columns = [ + { + field: 'host.hostname', + name: 'Endpoint', + }, + { + field: 'host.os.name', + name: 'Operating System', + }, + { + field: 'endpoint.policy.name', + name: 'Policy', + }, + { + field: 'host.hostname', + name: 'Policy Status', + render: () => { + return Policy Status; + }, + }, + { + field: 'endpoint', + name: 'Alerts', + render: () => { + return 0; + }, + }, + { + field: 'endpoint.domain', + name: 'Domain', + }, + { + field: 'host.ip', + name: 'IP Address', + }, + { + field: 'endpoint.sensor', + name: 'Sensor Version', + render: () => { + return version; + }, + }, + { + field: 'host.hostname', + name: 'Last Active', + render: () => { + return xxxx; + }, + }, + ]; + + return ( + + + + + +

Endpoints

+
+
+
+ + + + +

Endpoints

+
+
+
+ + +
+
+
+ ); +}; From 79bfc46227f50fb9c4b6742ac0ada26ff42e49a1 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 22 Jan 2020 15:22:23 -0500 Subject: [PATCH 02/19] saga and hooks for endpoint list data --- .../endpoint/{ => components}/management.tsx | 26 +++++-------------- .../public/applications/endpoint/index.tsx | 2 +- .../applications/endpoint/store/hooks.ts | 17 ++++++++++++ 3 files changed, 25 insertions(+), 20 deletions(-) rename x-pack/plugins/endpoint/public/applications/endpoint/{ => components}/management.tsx (74%) create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/hooks.ts diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/management.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx similarity index 74% rename from x-pack/plugins/endpoint/public/applications/endpoint/management.tsx rename to x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx index df66684b0da82..0b8dd179f89ac 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/management.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx @@ -4,7 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import React, { useState, useEffect } from 'react'; +import React from 'react'; +import { useDispatch } from 'react-redux'; import { EuiPage, EuiPageBody, @@ -17,24 +18,11 @@ import { EuiTitle, EuiBasicTable, } from '@elastic/eui'; -import { CoreStart } from 'kibana/public'; +import { endpointListData } from '../store/endpoint_list/selectors'; +import { useEndpointListSelector } from '../store/hooks'; -export const EndpointList = ({ coreStart }: { coreStart: CoreStart }) => { - const [results, setResults] = useState([]); - const [wasFetched, setWasFetched] = useState(false); - - useEffect(() => { - async function fetchEndpointListData() { - const response = await coreStart.http.post('/api/endpoint/endpoints', { - query: {}, - }); - setResults(response.endpoints); - } - if (wasFetched === false) { - setWasFetched(true); - fetchEndpointListData(); - } - }, [coreStart, results, wasFetched]); +export const EndpointList = () => { + const endpointListResults = useEndpointListSelector(endpointListData); const columns = [ { @@ -105,7 +93,7 @@ export const EndpointList = ({ coreStart }: { coreStart: CoreStart }) => { - + diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index 6ec298ee1890a..7facfd563e1a8 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -11,9 +11,9 @@ import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; import { Route, BrowserRouter, Switch } from 'react-router-dom'; import { Provider } from 'react-redux'; import { Store } from 'redux'; +import { EndpointList } from './components/management'; import { appStoreFactory } from './store'; import { AlertIndex } from './view/alerts'; -import { EndpointList } from './management'; /** * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/hooks.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/hooks.ts new file mode 100644 index 0000000000000..32485fba2cbe3 --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/hooks.ts @@ -0,0 +1,17 @@ +/* + * 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 { useSelector } from 'react-redux'; +import { GlobalState } from './reducer'; +import { EndpointListState } from './endpoint_list'; + +export function useEndpointListSelector( + selector: (state: EndpointListState) => TSelected +) { + return useSelector(function(state: GlobalState) { + return selector(state.endpointList); + }); +} From 5c8c42ddbd286acc126e34b5cbce7e8307af460f Mon Sep 17 00:00:00 2001 From: Candace Park Date: Thu, 23 Jan 2020 18:04:07 -0500 Subject: [PATCH 03/19] added pagination be --- .../public/applications/endpoint/store/endpoint_list/saga.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts index cc156cfa88002..807adcc9a6a2a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts @@ -16,7 +16,9 @@ export const endpointListSaga = async ( for await (const { action } of actionsAndState()) { if (action.type === 'userEnteredEndpointListPage') { - const response = await httpPost('/api/endpoint/endpoints'); + const response = await httpPost('/api/endpoint/endpoints', { + body: JSON.stringify({ paging_properties: [{ page_index: 1 }, { page_size: 2 }] }), + }); dispatch({ type: 'serverReturnedEndpointList', payload: response, From 492aa37502e3b61a9b4713e3004245e3a647c303 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Mon, 27 Jan 2020 17:34:36 -0500 Subject: [PATCH 04/19] pagie backend --- .../endpoint/components/management.tsx | 40 +++++++++++++++++-- .../endpoint/store/endpoint_list/action.ts | 10 ++++- .../endpoint/store/endpoint_list/reducer.ts | 9 +++++ .../endpoint/store/endpoint_list/saga.ts | 14 +++++-- .../endpoint/store/endpoint_list/selectors.ts | 6 +++ .../endpoint/store/endpoint_list/types.ts | 5 +++ 6 files changed, 75 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx index 0b8dd179f89ac..93474ebe3415b 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx @@ -17,17 +17,44 @@ import { EuiPageHeaderSection, EuiTitle, EuiBasicTable, + EuiTableCriteria, } from '@elastic/eui'; -import { endpointListData } from '../store/endpoint_list/selectors'; import { useEndpointListSelector } from '../store/hooks'; +import { + endpointListData, + endpointListPageIndex, + endpointListPageSize, + endpointTotalHits, +} from '../store/endpoint_list/selectors'; +import { EndpointListAction } from '../store/endpoint_list/action'; export const EndpointList = () => { + const dispatch = useDispatch<(a: EndpointListAction) => void>(); const endpointListResults = useEndpointListSelector(endpointListData); + const pageIndex = useEndpointListSelector(endpointListPageIndex); + const pageSize = useEndpointListSelector(endpointListPageSize); + const totalItemCount = useEndpointListSelector(endpointTotalHits); + + const paginationSetup = { + pageIndex, + pageSize, + totalItemCount, + pageSizeOptions: [1, 2, 3], + hidePerPageOptions: false, + }; + + const onTableChange = ({ page }: { page: EuiTableCriteria }) => { + const { index, size } = page; + dispatch({ + type: 'userPaginatedEndpointListTable', + payload: { pageIndex: index, pageSize: size }, + }); + }; const columns = [ { field: 'host.hostname', - name: 'Endpoint', + name: 'Host', }, { field: 'host.os.name', @@ -89,11 +116,16 @@ export const EndpointList = () => { -

Endpoints

+

Hosts

- + diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts index 02ec0f9d09035..f5ea0128ecf48 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EndpointListData } from './types'; +import { EndpointListData, EndpointListPagination } from './types'; interface ServerReturnedEndpointList { type: 'serverReturnedEndpointList'; @@ -19,7 +19,13 @@ interface UserExitedEndpointListPage { type: 'userExitedEndpointListPage'; } +interface UserPaginatedEndpointListTable { + type: 'userPaginatedEndpointListTable'; + payload: EndpointListPagination; +} + export type EndpointListAction = | ServerReturnedEndpointList | UserEnteredEndpointListPage - | UserExitedEndpointListPage; + | UserExitedEndpointListPage + | UserPaginatedEndpointListTable; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts index e57d9683e4707..434a4b3796436 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts @@ -32,5 +32,14 @@ export const endpointListReducer: Reducer = ( return initialState(); } + if (action.type === 'userPaginatedEndpointListTable') { + const { pageIndex, pageSize } = action.payload; + return { + ...state, + request_page_size: pageSize, + request_index: pageIndex, + }; + } + return state; }; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts index 807adcc9a6a2a..ef9eb447c6e06 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts @@ -7,6 +7,7 @@ import { CoreStart } from 'kibana/public'; import { SagaContext } from '../../lib'; import { EndpointListAction } from './action'; +import { endpointListPageIndex, endpointListPageSize } from './selectors'; export const endpointListSaga = async ( { actionsAndState, dispatch }: SagaContext, @@ -14,10 +15,17 @@ export const endpointListSaga = async ( ) => { const { post: httpPost } = coreStart.http; - for await (const { action } of actionsAndState()) { - if (action.type === 'userEnteredEndpointListPage') { + for await (const { action, state } of actionsAndState()) { + if ( + action.type === 'userEnteredEndpointListPage' || + action.type === 'userPaginatedEndpointListTable' + ) { + const pageIndex = endpointListPageIndex(state.endpointList); + const pageSize = endpointListPageSize(state.endpointList); const response = await httpPost('/api/endpoint/endpoints', { - body: JSON.stringify({ paging_properties: [{ page_index: 1 }, { page_size: 2 }] }), + body: JSON.stringify({ + paging_properties: [{ page_index: pageIndex }, { page_size: pageSize }], + }), }); dispatch({ type: 'serverReturnedEndpointList', diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts index 6ffcebc3f41aa..74b12bb07b6bf 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts @@ -7,3 +7,9 @@ import { EndpointListState } from './types'; export const endpointListData = (state: EndpointListState) => state.endpoints; + +export const endpointListPageIndex = (state: EndpointListState) => state.request_index; + +export const endpointListPageSize = (state: EndpointListState) => state.request_page_size; + +export const endpointTotalHits = (state: EndpointListState) => state.total; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts index f2810dd89f857..0ac346bbfed12 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts @@ -52,3 +52,8 @@ export interface EndpointListData { } export type EndpointListState = EndpointListData; + +export interface EndpointListPagination { + pageIndex: number; + pageSize: number; +} From 2e82be84f64543597723543d3aaad2dca9715c94 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Tue, 28 Jan 2020 12:57:13 -0500 Subject: [PATCH 05/19] working pagination --- .../applications/endpoint/store/endpoint_list/reducer.ts | 4 ++-- .../public/applications/endpoint/store/endpoint_list/saga.ts | 2 ++ .../applications/endpoint/store/endpoint_list/selectors.ts | 2 +- .../public/applications/endpoint/store/endpoint_list/types.ts | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts index 434a4b3796436..1dd10938f9aa3 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts @@ -12,7 +12,7 @@ const initialState = (): EndpointListState => { return { endpoints: [], request_page_size: 10, - request_index: 0, + request_page_index: 0, total: 0, }; }; @@ -37,7 +37,7 @@ export const endpointListReducer: Reducer = ( return { ...state, request_page_size: pageSize, - request_index: pageIndex, + request_page_index: pageIndex, }; } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts index ef9eb447c6e06..c1fc361349edd 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts @@ -27,6 +27,8 @@ export const endpointListSaga = async ( paging_properties: [{ page_index: pageIndex }, { page_size: pageSize }], }), }); + // temp: request_page_index to reflect user request page index, not es page index + response.request_page_index = pageIndex; dispatch({ type: 'serverReturnedEndpointList', payload: response, diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts index 74b12bb07b6bf..8ace0b9d0ee37 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts @@ -8,7 +8,7 @@ import { EndpointListState } from './types'; export const endpointListData = (state: EndpointListState) => state.endpoints; -export const endpointListPageIndex = (state: EndpointListState) => state.request_index; +export const endpointListPageIndex = (state: EndpointListState) => state.request_page_index; export const endpointListPageSize = (state: EndpointListState) => state.request_page_size; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts index 0ac346bbfed12..73b64a1512f58 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts @@ -47,7 +47,7 @@ export interface EndpointData { export interface EndpointListData { endpoints: EndpointData[]; request_page_size: number; - request_index: number; + request_page_index: number; total: number; } From 275ab250e5914d8016e18ea5230d08f60bdf098f Mon Sep 17 00:00:00 2001 From: Candace Park Date: Tue, 28 Jan 2020 18:15:27 -0500 Subject: [PATCH 06/19] fixing errors --- .../applications/endpoint/components/management.tsx | 5 ++--- .../endpoint/store/endpoint_list/index.test.ts | 10 +++++----- .../endpoint/store/endpoint_list/saga.test.ts | 2 +- .../apps/endpoint/feature_controls/endpoint_spaces.ts | 3 ++- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx index 93474ebe3415b..02afb04007837 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx @@ -17,7 +17,6 @@ import { EuiPageHeaderSection, EuiTitle, EuiBasicTable, - EuiTableCriteria, } from '@elastic/eui'; import { useEndpointListSelector } from '../store/hooks'; import { @@ -39,11 +38,11 @@ export const EndpointList = () => { pageIndex, pageSize, totalItemCount, - pageSizeOptions: [1, 2, 3], + pageSizeOptions: [10, 20, 50], hidePerPageOptions: false, }; - const onTableChange = ({ page }: { page: EuiTableCriteria }) => { + const onTableChange = ({ page }: { page: { index: number; size: number } }) => { const { index, size } = page; dispatch({ type: 'userPaginatedEndpointListTable', diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts index a46653f82ee45..d4340e116ffe2 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts @@ -62,7 +62,7 @@ describe('endpoint_list store concerns', () => { payload: { endpoints: [generateEndpoint()], request_page_size: 1, - request_index: 1, + request_page_index: 1, total: 10, }, }); @@ -77,7 +77,7 @@ describe('endpoint_list store concerns', () => { expect(store.getState()).toEqual({ endpoints: [], request_page_size: 10, - request_index: 0, + request_page_index: 0, total: 0, }); }); @@ -86,7 +86,7 @@ describe('endpoint_list store concerns', () => { const payload = { endpoints: [generateEndpoint()], request_page_size: 1, - request_index: 1, + request_page_index: 1, total: 10, }; dispatch({ @@ -97,7 +97,7 @@ describe('endpoint_list store concerns', () => { const currentState = store.getState(); expect(currentState.endpoints).toEqual(payload.endpoints); expect(currentState.request_page_size).toEqual(payload.request_page_size); - expect(currentState.request_index).toEqual(payload.request_index); + expect(currentState.request_page_index).toEqual(payload.request_page_index); expect(currentState.total).toEqual(payload.total); }); @@ -108,7 +108,7 @@ describe('endpoint_list store concerns', () => { dispatch({ type: 'userExitedEndpointListPage' }); expect(store.getState().endpoints.length).toEqual(0); - expect(store.getState().request_index).toEqual(0); + expect(store.getState().request_page_index).toEqual(0); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts index 6bf946873e179..747e16b8a6c39 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts @@ -72,7 +72,7 @@ describe('endpoint list saga', () => { return { endpoints: [generateEndpoint()], request_page_size: 1, - request_index: 1, + request_page_index: 1, total: 10, }; }; diff --git a/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts b/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts index d8eb969b99b3b..002cf3b021025 100644 --- a/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts +++ b/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts @@ -41,7 +41,8 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await testSubjects.existOrFail('welcomeTitle'); }); - it(`endpoint management shows 'Manage Endpoints'`, async () => { + // TODO: refactor this test + it.skip(`endpoint management shows 'Manage Endpoints'`, async () => { await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/management', { basePath: '/s/custom_space', ensureCurrentUrl: false, From 78c0914f7b98f7ccf26e2835ab2efdfd8d1735c6 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Thu, 30 Jan 2020 14:57:24 -0500 Subject: [PATCH 07/19] organizing and fixing --- x-pack/plugins/endpoint/common/types.ts | 2 +- .../public/applications/endpoint/index.tsx | 11 +---- .../endpoint/store/endpoint_list/action.ts | 5 --- .../endpoint/store/endpoint_list/saga.test.ts | 44 +++++++------------ .../endpoint/store/endpoint_list/saga.ts | 6 +-- .../applications/endpoint/store/index.ts | 2 +- .../{store => view/managing}/hooks.ts | 4 +- .../managing/index.tsx} | 8 ++-- 8 files changed, 31 insertions(+), 51 deletions(-) rename x-pack/plugins/endpoint/public/applications/endpoint/{store => view/managing}/hooks.ts (82%) rename x-pack/plugins/endpoint/public/applications/endpoint/{components/management.tsx => view/managing/index.tsx} (92%) diff --git a/x-pack/plugins/endpoint/common/types.ts b/x-pack/plugins/endpoint/common/types.ts index 0128cd3dd6df7..0dc3fc29ca805 100644 --- a/x-pack/plugins/endpoint/common/types.ts +++ b/x-pack/plugins/endpoint/common/types.ts @@ -118,4 +118,4 @@ export interface EndpointMetadata { /** * The PageId type is used for the payload when firing userNavigatedToPage actions */ -export type PageId = 'alertsPage' | 'endpointListPage'; +export type PageId = 'alertsPage' | 'managementPage'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index 7facfd563e1a8..02fe261434a17 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -11,9 +11,9 @@ import { I18nProvider, FormattedMessage } from '@kbn/i18n/react'; import { Route, BrowserRouter, Switch } from 'react-router-dom'; import { Provider } from 'react-redux'; import { Store } from 'redux'; -import { EndpointList } from './components/management'; import { appStoreFactory } from './store'; import { AlertIndex } from './view/alerts'; +import { EndpointList } from './view/managing'; /** * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. @@ -50,14 +50,7 @@ const AppRoot: React.FunctionComponent = React.memo(({ basename, st )} /> - { - // FIXME: This is temporary. Will be removed in next PR for endpoint list - store.dispatch({ type: 'userEnteredEndpointListPage' }); - return ; - }} - /> + ( diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts index f5ea0128ecf48..a1efd16d0a66d 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts @@ -11,10 +11,6 @@ interface ServerReturnedEndpointList { payload: EndpointListData; } -interface UserEnteredEndpointListPage { - type: 'userEnteredEndpointListPage'; -} - interface UserExitedEndpointListPage { type: 'userExitedEndpointListPage'; } @@ -26,6 +22,5 @@ interface UserPaginatedEndpointListTable { export type EndpointListAction = | ServerReturnedEndpointList - | UserEnteredEndpointListPage | UserExitedEndpointListPage | UserPaginatedEndpointListTable; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts index 747e16b8a6c39..03e4d2109ac87 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts @@ -3,29 +3,24 @@ * 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 { applyMiddleware, combineReducers, createStore, Dispatch, Store } from 'redux'; import { createSagaMiddleware, SagaContext } from '../../lib'; import { endpointListSaga } from './saga'; import { coreMock } from '../../../../../../../../src/core/public/mocks'; -import { - EndpointData, - EndpointListAction, - EndpointListData, - endpointListReducer, - EndpointListState, -} from './index'; +import { EndpointData, EndpointListData, endpointListReducer, EndpointListState } from './index'; +import { AppAction } from '../action'; import { endpointListData } from './selectors'; - describe('endpoint list saga', () => { const sleep = (ms = 100) => new Promise(wakeup => setTimeout(wakeup, ms)); let fakeCoreStart: jest.Mocked; let fakeHttpServices: jest.Mocked; - let store: Store; - let dispatch: Dispatch; + let store: Store<{ endpointList: EndpointListState }>; + let dispatch: Dispatch; let stopSagas: () => void; - + const globalStoreReducer = combineReducers({ + endpointList: endpointListReducer, + }); // TODO: consolidate the below ++ helpers in `index.test.ts` into a `test_helpers.ts`?? const generateEndpoint = (): EndpointData => { return { @@ -76,7 +71,6 @@ describe('endpoint list saga', () => { total: 10, }; }; - const endpointListSagaFactory = () => { return async (sagaContext: SagaContext) => { await endpointListSaga(sagaContext, fakeCoreStart).catch((e: Error) => { @@ -86,33 +80,29 @@ describe('endpoint list saga', () => { }); }; }; - beforeEach(() => { fakeCoreStart = coreMock.createStart({ basePath: '/mock' }); fakeHttpServices = fakeCoreStart.http as jest.Mocked; - const sagaMiddleware = createSagaMiddleware(endpointListSagaFactory()); - store = createStore(endpointListReducer, applyMiddleware(sagaMiddleware)); - + store = createStore(globalStoreReducer, applyMiddleware(sagaMiddleware)); sagaMiddleware.start(); stopSagas = sagaMiddleware.stop; dispatch = store.dispatch; }); - afterEach(() => { stopSagas(); }); - - test('it handles `userEnteredEndpointListPage`', async () => { + test('it handles `userNavigatedToPage`', async () => { const apiResponse = getEndpointListApiResponse(); - fakeHttpServices.post.mockResolvedValue(apiResponse); expect(fakeHttpServices.post).not.toHaveBeenCalled(); - - dispatch({ type: 'userEnteredEndpointListPage' }); + dispatch({ type: 'userNavigatedToPage', payload: 'managementPage' }); await sleep(); - - expect(fakeHttpServices.post).toHaveBeenCalledWith('/api/endpoint/endpoints'); - expect(endpointListData(store.getState())).toEqual(apiResponse.endpoints); + expect(fakeHttpServices.post).toHaveBeenCalledWith('/api/endpoint/endpoints', { + body: JSON.stringify({ + paging_properties: [{ page_index: 0 }, { page_size: 10 }], + }), + }); + expect(endpointListData(store.getState().endpointList)).toEqual(apiResponse.endpoints); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts index c1fc361349edd..853733871f905 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts @@ -6,18 +6,18 @@ import { CoreStart } from 'kibana/public'; import { SagaContext } from '../../lib'; -import { EndpointListAction } from './action'; +import { AppAction } from '../action'; import { endpointListPageIndex, endpointListPageSize } from './selectors'; export const endpointListSaga = async ( - { actionsAndState, dispatch }: SagaContext, + { actionsAndState, dispatch }: SagaContext, coreStart: CoreStart ) => { const { post: httpPost } = coreStart.http; for await (const { action, state } of actionsAndState()) { if ( - action.type === 'userEnteredEndpointListPage' || + (action.type === 'userNavigatedToPage' && action.payload === 'managementPage') || action.type === 'userPaginatedEndpointListTable' ) { const pageIndex = endpointListPageIndex(state.endpointList); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts index a32f310392ca9..fe3422f80ab3b 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts @@ -19,7 +19,7 @@ export const appStoreFactory = (coreStart: CoreStart): [Store, () => void] => { const store = createStore( appReducer, composeWithReduxDevTools( - applyMiddleware(alertMiddlewareFactory(coreStart), appSagaFactory(coreStart)) + applyMiddleware(alertMiddlewareFactory(coreStart), sagaReduxMiddleware) ) ); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/hooks.ts b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts similarity index 82% rename from x-pack/plugins/endpoint/public/applications/endpoint/store/hooks.ts rename to x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts index 32485fba2cbe3..3a3f62d1b9715 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/hooks.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts @@ -5,8 +5,8 @@ */ import { useSelector } from 'react-redux'; -import { GlobalState } from './reducer'; -import { EndpointListState } from './endpoint_list'; +import { GlobalState } from '../../types'; +import { EndpointListState } from '../../store/endpoint_list'; export function useEndpointListSelector( selector: (state: EndpointListState) => TSelected diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx similarity index 92% rename from x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx rename to x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index 02afb04007837..db7af3e4aa693 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/components/management.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -18,16 +18,18 @@ import { EuiTitle, EuiBasicTable, } from '@elastic/eui'; -import { useEndpointListSelector } from '../store/hooks'; import { endpointListData, endpointListPageIndex, endpointListPageSize, endpointTotalHits, -} from '../store/endpoint_list/selectors'; -import { EndpointListAction } from '../store/endpoint_list/action'; +} from '../../store/endpoint_list/selectors'; +import { EndpointListAction } from '../../store/endpoint_list/action'; +import { useEndpointListSelector } from './hooks'; +import { usePageId } from '../use_page_id'; export const EndpointList = () => { + usePageId('managementPage'); const dispatch = useDispatch<(a: EndpointListAction) => void>(); const endpointListResults = useEndpointListSelector(endpointListData); const pageIndex = useEndpointListSelector(endpointListPageIndex); From 217731914c95e5d2b838b6f582909cd8d8e21eab Mon Sep 17 00:00:00 2001 From: Candace Park Date: Fri, 31 Jan 2020 15:39:42 -0500 Subject: [PATCH 08/19] fix, rename types and tests --- .../endpoint/store/endpoint_list/action.ts | 7 ++- .../store/endpoint_list/index.test.ts | 60 ++++++++----------- .../endpoint/store/endpoint_list/index.ts | 1 - .../endpoint/store/endpoint_list/reducer.ts | 25 +++++--- .../endpoint/store/endpoint_list/saga.test.ts | 56 +++++++---------- .../endpoint/store/endpoint_list/selectors.ts | 10 ++-- .../endpoint/store/endpoint_list/types.ts | 59 ------------------ .../public/applications/endpoint/types.ts | 16 ++++- .../endpoint/view/managing/hooks.ts | 5 +- .../endpoint/view/managing/index.tsx | 35 ++++++----- 10 files changed, 107 insertions(+), 167 deletions(-) delete mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts index a1efd16d0a66d..3893bc967bde8 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts @@ -4,11 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EndpointListData, EndpointListPagination } from './types'; +import { ManagementPagination } from '../../types'; +import { EndpointResultList } from '../../../../../common/types'; interface ServerReturnedEndpointList { type: 'serverReturnedEndpointList'; - payload: EndpointListData; + payload: EndpointResultList; } interface UserExitedEndpointListPage { @@ -17,7 +18,7 @@ interface UserExitedEndpointListPage { interface UserPaginatedEndpointListTable { type: 'userPaginatedEndpointListTable'; - payload: EndpointListPagination; + payload: ManagementPagination; } export type EndpointListAction = diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts index d4340e116ffe2..914ceb7ea947d 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts @@ -5,53 +5,41 @@ */ import { createStore, Dispatch, Store } from 'redux'; -import { EndpointListAction, EndpointData, endpointListReducer, EndpointListState } from './index'; +import { EndpointListAction, endpointListReducer } from './index'; +import { EndpointMetadata } from '../../../../../common/types'; +import { ManagementState } from '../../types'; import { endpointListData } from './selectors'; describe('endpoint_list store concerns', () => { - let store: Store; + let store: Store; let dispatch: Dispatch; const createTestStore = () => { store = createStore(endpointListReducer); dispatch = store.dispatch; }; - const generateEndpoint = (): EndpointData => { + const generateEndpoint = (): EndpointMetadata => { return { - machine_id: Math.random() - .toString(16) - .substr(2), - created_at: new Date(), - host: { - name: '', - hostname: '', - ip: '', - mac_address: '', - os: { - name: '', - full: '', - }, + event: { + created: new Date(), }, endpoint: { - domain: '', - is_base_image: true, - active_directory_distinguished_name: '', - active_directory_hostname: '', - upgrade: { - status: '', - updated_at: new Date(), - }, - isolation: { - status: false, - request_status: true, - updated_at: new Date(), - }, policy: { - name: '', id: '', }, - sensor: { - persistence: true, - status: {}, + }, + agent: { + version: '', + id: '', + }, + host: { + id: '', + hostname: '', + ip: [''], + mac: [''], + os: { + name: '', + full: '', + version: '', }, }, }; @@ -96,8 +84,8 @@ describe('endpoint_list store concerns', () => { const currentState = store.getState(); expect(currentState.endpoints).toEqual(payload.endpoints); - expect(currentState.request_page_size).toEqual(payload.request_page_size); - expect(currentState.request_page_index).toEqual(payload.request_page_index); + expect(currentState.pageSize).toEqual(payload.request_page_size); + expect(currentState.pageIndex).toEqual(payload.request_page_index); expect(currentState.total).toEqual(payload.total); }); @@ -108,7 +96,7 @@ describe('endpoint_list store concerns', () => { dispatch({ type: 'userExitedEndpointListPage' }); expect(store.getState().endpoints.length).toEqual(0); - expect(store.getState().request_page_index).toEqual(0); + expect(store.getState().pageIndex).toEqual(0); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts index bdf0708457bb0..102932e2d5a49 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts @@ -7,4 +7,3 @@ export { endpointListReducer } from './reducer'; export { EndpointListAction } from './action'; export { endpointListSaga } from './saga'; -export * from './types'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts index 1dd10938f9aa3..24cbcedbdc990 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts @@ -5,26 +5,35 @@ */ import { Reducer } from 'redux'; -import { EndpointListState } from './types'; +import { ManagementState } from '../../types'; import { AppAction } from '../action'; -const initialState = (): EndpointListState => { +const initialState = (): ManagementState => { return { endpoints: [], - request_page_size: 10, - request_page_index: 0, + pageSize: 10, + pageIndex: 0, total: 0, }; }; -export const endpointListReducer: Reducer = ( +export const endpointListReducer: Reducer = ( state = initialState(), action ) => { if (action.type === 'serverReturnedEndpointList') { + const { + endpoints, + total, + request_page_size: pageSize, + request_page_index: pageIndex, + } = action.payload; return { ...state, - ...action.payload, + endpoints, + total, + pageSize, + pageIndex, }; } @@ -33,11 +42,9 @@ export const endpointListReducer: Reducer = ( } if (action.type === 'userPaginatedEndpointListTable') { - const { pageIndex, pageSize } = action.payload; return { ...state, - request_page_size: pageSize, - request_page_index: pageIndex, + ...action.payload, }; } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts index 03e4d2109ac87..0b1bbc3c04efa 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts @@ -8,62 +8,50 @@ import { applyMiddleware, combineReducers, createStore, Dispatch, Store } from ' import { createSagaMiddleware, SagaContext } from '../../lib'; import { endpointListSaga } from './saga'; import { coreMock } from '../../../../../../../../src/core/public/mocks'; -import { EndpointData, EndpointListData, endpointListReducer, EndpointListState } from './index'; +import { endpointListReducer } from './index'; +import { EndpointMetadata, EndpointResultList } from '../../../../../common/types'; +import { ManagementState } from '../../types'; import { AppAction } from '../action'; import { endpointListData } from './selectors'; describe('endpoint list saga', () => { const sleep = (ms = 100) => new Promise(wakeup => setTimeout(wakeup, ms)); let fakeCoreStart: jest.Mocked; let fakeHttpServices: jest.Mocked; - let store: Store<{ endpointList: EndpointListState }>; + let store: Store<{ endpointList: ManagementState }>; let dispatch: Dispatch; let stopSagas: () => void; const globalStoreReducer = combineReducers({ endpointList: endpointListReducer, }); // TODO: consolidate the below ++ helpers in `index.test.ts` into a `test_helpers.ts`?? - const generateEndpoint = (): EndpointData => { + const generateEndpoint = (): EndpointMetadata => { return { - machine_id: Math.random() - .toString(16) - .substr(2), - created_at: new Date(), - host: { - name: '', - hostname: '', - ip: '', - mac_address: '', - os: { - name: '', - full: '', - }, + event: { + created: new Date(), }, endpoint: { - domain: '', - is_base_image: true, - active_directory_distinguished_name: '', - active_directory_hostname: '', - upgrade: { - status: '', - updated_at: new Date(), - }, - isolation: { - status: false, - request_status: true, - updated_at: new Date(), - }, policy: { - name: '', id: '', }, - sensor: { - persistence: true, - status: {}, + }, + agent: { + version: '', + id: '', + }, + host: { + id: '', + hostname: '', + ip: [''], + mac: [''], + os: { + name: '', + full: '', + version: '', }, }, }; }; - const getEndpointListApiResponse = (): EndpointListData => { + const getEndpointListApiResponse = (): EndpointResultList => { return { endpoints: [generateEndpoint()], request_page_size: 1, diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts index 8ace0b9d0ee37..f1c20f70a01c7 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts @@ -4,12 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EndpointListState } from './types'; +import { ManagementState } from '../../types'; -export const endpointListData = (state: EndpointListState) => state.endpoints; +export const endpointListData = (state: ManagementState) => state.endpoints; -export const endpointListPageIndex = (state: EndpointListState) => state.request_page_index; +export const endpointListPageIndex = (state: ManagementState) => state.pageIndex; -export const endpointListPageSize = (state: EndpointListState) => state.request_page_size; +export const endpointListPageSize = (state: ManagementState) => state.pageSize; -export const endpointTotalHits = (state: EndpointListState) => state.total; +export const endpointTotalHits = (state: ManagementState) => state.total; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts deleted file mode 100644 index 73b64a1512f58..0000000000000 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/types.ts +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - */ - -// FIXME: temporary until server defined `interface` is moved -export interface EndpointData { - machine_id: string; - created_at: Date; - host: { - name: string; - hostname: string; - ip: string; - mac_address: string; - os: { - name: string; - full: string; - }; - }; - endpoint: { - domain: string; - is_base_image: boolean; - active_directory_distinguished_name: string; - active_directory_hostname: string; - upgrade: { - status?: string; - updated_at?: Date; - }; - isolation: { - status: boolean; - request_status?: string | boolean; - updated_at?: Date; - }; - policy: { - name: string; - id: string; - }; - sensor: { - persistence: boolean; - status: object; - }; - }; -} - -// FIXME: temporary until server defined `interface` is moved to a module we can reference -export interface EndpointListData { - endpoints: EndpointData[]; - request_page_size: number; - request_page_index: number; - total: number; -} - -export type EndpointListState = EndpointListData; - -export interface EndpointListPagination { - pageIndex: number; - pageSize: number; -} diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index 5f02d36308053..d3e6b9a655320 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -6,7 +6,7 @@ import { Dispatch, MiddlewareAPI } from 'redux'; import { CoreStart } from 'kibana/public'; -import { EndpointListState } from './store/endpoint_list'; +import { EndpointMetadata } from '../../../common/types'; import { AppAction } from './store/action'; import { AlertResultList } from '../../../common/types'; @@ -16,8 +16,20 @@ export type MiddlewareFactory = ( api: MiddlewareAPI, GlobalState> ) => (next: Dispatch) => (action: AppAction) => unknown; +export interface ManagementState { + endpoints: EndpointMetadata[]; + total: number; + pageSize: number; + pageIndex: number; +} + +export interface ManagementPagination { + pageIndex: number; + pageSize: number; +} + export interface GlobalState { - readonly endpointList: EndpointListState; + readonly endpointList: ManagementState; readonly alertList: AlertListState; } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts index 3a3f62d1b9715..9c2e4687a1a54 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts @@ -5,11 +5,10 @@ */ import { useSelector } from 'react-redux'; -import { GlobalState } from '../../types'; -import { EndpointListState } from '../../store/endpoint_list'; +import { GlobalState, ManagementState } from '../../types'; export function useEndpointListSelector( - selector: (state: EndpointListState) => TSelected + selector: (state: ManagementState) => TSelected ) { return useSelector(function(state: GlobalState) { return selector(state.endpointList); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index db7af3e4aa693..46be9ca7b8a59 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import React from 'react'; +import React, { useMemo, useCallback } from 'react'; import { useDispatch } from 'react-redux'; import { EuiPage, @@ -36,21 +36,26 @@ export const EndpointList = () => { const pageSize = useEndpointListSelector(endpointListPageSize); const totalItemCount = useEndpointListSelector(endpointTotalHits); - const paginationSetup = { - pageIndex, - pageSize, - totalItemCount, - pageSizeOptions: [10, 20, 50], - hidePerPageOptions: false, - }; + const paginationSetup = useMemo(() => { + return { + pageIndex, + pageSize, + totalItemCount, + pageSizeOptions: [10, 20, 50], + hidePerPageOptions: false, + }; + }, [pageIndex, pageSize, totalItemCount]); - const onTableChange = ({ page }: { page: { index: number; size: number } }) => { - const { index, size } = page; - dispatch({ - type: 'userPaginatedEndpointListTable', - payload: { pageIndex: index, pageSize: size }, - }); - }; + const onTableChange = useCallback( + ({ page }: { page: { index: number; size: number } }) => { + const { index, size } = page; + dispatch({ + type: 'userPaginatedEndpointListTable', + payload: { pageIndex: index, pageSize: size }, + }); + }, + [dispatch] + ); const columns = [ { From 6f75ee32799dfc2f4db92581f68d20abe7a33549 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Mon, 3 Feb 2020 09:50:53 -0500 Subject: [PATCH 09/19] fix index test --- .../applications/endpoint/store/endpoint_list/index.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts index 914ceb7ea947d..5c45513069739 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts @@ -64,8 +64,8 @@ describe('endpoint_list store concerns', () => { test('it creates default state', () => { expect(store.getState()).toEqual({ endpoints: [], - request_page_size: 10, - request_page_index: 0, + pageSize: 10, + pageIndex: 0, total: 0, }); }); From b3c444cabfc453e16ad8147569523d6bc591e2c8 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Mon, 3 Feb 2020 11:53:24 -0500 Subject: [PATCH 10/19] added table loading --- .../applications/endpoint/store/endpoint_list/reducer.ts | 3 +++ .../applications/endpoint/store/endpoint_list/selectors.ts | 2 ++ x-pack/plugins/endpoint/public/applications/endpoint/types.ts | 1 + .../public/applications/endpoint/view/managing/index.tsx | 3 +++ 4 files changed, 9 insertions(+) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts index 24cbcedbdc990..5c572ffa30465 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts @@ -14,6 +14,7 @@ const initialState = (): ManagementState => { pageSize: 10, pageIndex: 0, total: 0, + loading: false, }; }; @@ -34,6 +35,7 @@ export const endpointListReducer: Reducer = ( total, pageSize, pageIndex, + loading: false, }; } @@ -45,6 +47,7 @@ export const endpointListReducer: Reducer = ( return { ...state, ...action.payload, + loading: true, }; } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts index f1c20f70a01c7..efd2d104bc813 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts @@ -13,3 +13,5 @@ export const endpointListPageIndex = (state: ManagementState) => state.pageIndex export const endpointListPageSize = (state: ManagementState) => state.pageSize; export const endpointTotalHits = (state: ManagementState) => state.total; + +export const isLoading = (state: ManagementState) => state.loading; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index d3e6b9a655320..24e00243f2ba8 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -21,6 +21,7 @@ export interface ManagementState { total: number; pageSize: number; pageIndex: number; + loading: boolean; } export interface ManagementPagination { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index 46be9ca7b8a59..d3c130ce91046 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -23,6 +23,7 @@ import { endpointListPageIndex, endpointListPageSize, endpointTotalHits, + isLoading, } from '../../store/endpoint_list/selectors'; import { EndpointListAction } from '../../store/endpoint_list/action'; import { useEndpointListSelector } from './hooks'; @@ -35,6 +36,7 @@ export const EndpointList = () => { const pageIndex = useEndpointListSelector(endpointListPageIndex); const pageSize = useEndpointListSelector(endpointListPageSize); const totalItemCount = useEndpointListSelector(endpointTotalHits); + const loading = useEndpointListSelector(isLoading); const paginationSetup = useMemo(() => { return { @@ -129,6 +131,7 @@ export const EndpointList = () => { From c497eeb0360cbfd686ada490649c065e2c681069 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Tue, 4 Feb 2020 14:10:01 -0500 Subject: [PATCH 11/19] i18n --- .../endpoint/view/managing/index.tsx | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index d3c130ce91046..a3308c21dfe71 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -18,6 +18,8 @@ import { EuiTitle, EuiBasicTable, } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import { endpointListData, endpointListPageIndex, @@ -62,48 +64,66 @@ export const EndpointList = () => { const columns = [ { field: 'host.hostname', - name: 'Host', + name: i18n.translate('management.list.host', { + defaultMessage: 'Host', + }), }, { field: 'host.os.name', - name: 'Operating System', + name: i18n.translate('management.list.os', { + defaultMessage: 'Operating System', + }), }, { field: 'endpoint.policy.name', - name: 'Policy', + name: i18n.translate('management.list.policy', { + defaultMessage: 'Policy', + }), }, { field: 'host.hostname', - name: 'Policy Status', + name: i18n.translate('management.list.policyStatus', { + defaultMessage: 'Policy Status', + }), render: () => { return Policy Status; }, }, { field: 'endpoint', - name: 'Alerts', + name: i18n.translate('management.list.alerts', { + defaultMessage: 'Alerts', + }), render: () => { return 0; }, }, { field: 'endpoint.domain', - name: 'Domain', + name: i18n.translate('management.list.domain', { + defaultMessage: 'Domain', + }), }, { field: 'host.ip', - name: 'IP Address', + name: i18n.translate('management.list.ip', { + defaultMessage: 'IP Address', + }), }, { field: 'endpoint.sensor', - name: 'Sensor Version', + name: i18n.translate('management.list.sensorVersion', { + defaultMessage: 'Sensor Version', + }), render: () => { return version; }, }, { field: 'host.hostname', - name: 'Last Active', + name: i18n.translate('management.list.lastActive', { + defaultMessage: 'Last Active', + }), render: () => { return xxxx; }, @@ -124,7 +144,9 @@ export const EndpointList = () => { -

Hosts

+

+ +

From bce08a3d7fa4428d8624f9e020666072d522b8c7 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 5 Feb 2020 11:15:18 -0500 Subject: [PATCH 12/19] internationalization try 2 + column reorg --- .../store/endpoint_list/index.test.ts | 1 + .../endpoint/view/managing/index.tsx | 36 +++++++++---------- .../feature_controls/endpoint_spaces.ts | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts index 5c45513069739..f41d744414dda 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts @@ -67,6 +67,7 @@ describe('endpoint_list store concerns', () => { pageSize: 10, pageIndex: 0, total: 0, + loading: false, }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index a3308c21dfe71..d32d55f1a7ed7 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -64,25 +64,19 @@ export const EndpointList = () => { const columns = [ { field: 'host.hostname', - name: i18n.translate('management.list.host', { - defaultMessage: 'Host', - }), - }, - { - field: 'host.os.name', - name: i18n.translate('management.list.os', { - defaultMessage: 'Operating System', + name: i18n.translate('xpack.endpoint.management.list.host', { + defaultMessage: 'Hostname', }), }, { field: 'endpoint.policy.name', - name: i18n.translate('management.list.policy', { + name: i18n.translate('xpack.endpoint.management.list.policy', { defaultMessage: 'Policy', }), }, { field: 'host.hostname', - name: i18n.translate('management.list.policyStatus', { + name: i18n.translate('xpack.endpoint.management.list.policyStatus', { defaultMessage: 'Policy Status', }), render: () => { @@ -91,7 +85,7 @@ export const EndpointList = () => { }, { field: 'endpoint', - name: i18n.translate('management.list.alerts', { + name: i18n.translate('xpack.endpoint.management.list.alerts', { defaultMessage: 'Alerts', }), render: () => { @@ -99,20 +93,20 @@ export const EndpointList = () => { }, }, { - field: 'endpoint.domain', - name: i18n.translate('management.list.domain', { - defaultMessage: 'Domain', + field: 'host.os.name', + name: i18n.translate('xpack.endpoint.management.list.os', { + defaultMessage: 'Operating System', }), }, { field: 'host.ip', - name: i18n.translate('management.list.ip', { + name: i18n.translate('xpack.endpoint.management.list.ip', { defaultMessage: 'IP Address', }), }, { field: 'endpoint.sensor', - name: i18n.translate('management.list.sensorVersion', { + name: i18n.translate('xpack.endpoint.management.list.sensorVersion', { defaultMessage: 'Sensor Version', }), render: () => { @@ -121,7 +115,7 @@ export const EndpointList = () => { }, { field: 'host.hostname', - name: i18n.translate('management.list.lastActive', { + name: i18n.translate('xpack.endpoint.management.list.lastActive', { defaultMessage: 'Last Active', }), render: () => { @@ -144,13 +138,17 @@ export const EndpointList = () => { -

- +

+

{ await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/management', { basePath: '/s/custom_space', From b01baf998464c74500e10956e6d648ebf05018ed Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 5 Feb 2020 11:20:07 -0500 Subject: [PATCH 13/19] put table in content body --- .../endpoint/view/managing/index.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index d32d55f1a7ed7..da83a295d1071 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -147,15 +147,16 @@ export const EndpointList = () => { - - + + + From 368796fd65adb9fc3b7bdf5e7f15fa1b4de24b0b Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 5 Feb 2020 14:59:48 -0500 Subject: [PATCH 14/19] createstructured selector, code reorg --- .../endpoint/store/endpoint_list/saga.ts | 13 +++-- .../endpoint/store/endpoint_list/selectors.ts | 8 +-- .../public/applications/endpoint/types.ts | 9 +++ .../endpoint/view/managing/index.tsx | 55 +++++++++---------- 4 files changed, 46 insertions(+), 39 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts index 853733871f905..c82608e6a851f 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts @@ -7,7 +7,7 @@ import { CoreStart } from 'kibana/public'; import { SagaContext } from '../../lib'; import { AppAction } from '../action'; -import { endpointListPageIndex, endpointListPageSize } from './selectors'; +import { pageIndex, pageSize } from './selectors'; export const endpointListSaga = async ( { actionsAndState, dispatch }: SagaContext, @@ -20,15 +20,18 @@ export const endpointListSaga = async ( (action.type === 'userNavigatedToPage' && action.payload === 'managementPage') || action.type === 'userPaginatedEndpointListTable' ) { - const pageIndex = endpointListPageIndex(state.endpointList); - const pageSize = endpointListPageSize(state.endpointList); + const managementPageIndex = pageIndex(state.endpointList); + const managementPageSize = pageSize(state.endpointList); const response = await httpPost('/api/endpoint/endpoints', { body: JSON.stringify({ - paging_properties: [{ page_index: pageIndex }, { page_size: pageSize }], + paging_properties: [ + { page_index: managementPageIndex }, + { page_size: managementPageSize }, + ], }), }); // temp: request_page_index to reflect user request page index, not es page index - response.request_page_index = pageIndex; + response.request_page_index = managementPageIndex; dispatch({ type: 'serverReturnedEndpointList', payload: response, diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts index efd2d104bc813..a8bd6ca3ccf04 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts @@ -6,12 +6,12 @@ import { ManagementState } from '../../types'; -export const endpointListData = (state: ManagementState) => state.endpoints; +export const listData = (state: ManagementState) => state.endpoints; -export const endpointListPageIndex = (state: ManagementState) => state.pageIndex; +export const pageIndex = (state: ManagementState) => state.pageIndex; -export const endpointListPageSize = (state: ManagementState) => state.pageSize; +export const pageSize = (state: ManagementState) => state.pageSize; -export const endpointTotalHits = (state: ManagementState) => state.total; +export const totalHits = (state: ManagementState) => state.total; export const isLoading = (state: ManagementState) => state.loading; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index 24e00243f2ba8..3ff9709b59a4d 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -36,3 +36,12 @@ export interface GlobalState { export type AlertListData = AlertResultList; export type AlertListState = AlertResultList; +export type CreateStructuredSelector = < + SelectorMap extends { [key: string]: (...args: never[]) => unknown } +>( + selectorMap: SelectorMap +) => ( + state: SelectorMap[keyof SelectorMap] extends (state: infer State) => unknown ? State : never +) => { + [Key in keyof SelectorMap]: ReturnType; +}; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index da83a295d1071..5fdfbdf54f96b 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -20,25 +20,24 @@ import { } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { - endpointListData, - endpointListPageIndex, - endpointListPageSize, - endpointTotalHits, - isLoading, -} from '../../store/endpoint_list/selectors'; +import { createStructuredSelector } from 'reselect'; +import * as selectors from '../../store/endpoint_list/selectors'; import { EndpointListAction } from '../../store/endpoint_list/action'; import { useEndpointListSelector } from './hooks'; import { usePageId } from '../use_page_id'; +import { CreateStructuredSelector } from '../../types'; +const selector = (createStructuredSelector as CreateStructuredSelector)(selectors); export const EndpointList = () => { usePageId('managementPage'); const dispatch = useDispatch<(a: EndpointListAction) => void>(); - const endpointListResults = useEndpointListSelector(endpointListData); - const pageIndex = useEndpointListSelector(endpointListPageIndex); - const pageSize = useEndpointListSelector(endpointListPageSize); - const totalItemCount = useEndpointListSelector(endpointTotalHits); - const loading = useEndpointListSelector(isLoading); + const { + listData, + pageIndex, + pageSize, + totalHits: totalItemCount, + isLoading, + } = useEndpointListSelector(selector); const paginationSetup = useMemo(() => { return { @@ -69,27 +68,30 @@ export const EndpointList = () => { }), }, { - field: 'endpoint.policy.name', + field: '', name: i18n.translate('xpack.endpoint.management.list.policy', { defaultMessage: 'Policy', }), + render: () => { + return 'Policy Name'; + }, }, { - field: 'host.hostname', + field: '', name: i18n.translate('xpack.endpoint.management.list.policyStatus', { defaultMessage: 'Policy Status', }), render: () => { - return Policy Status; + return 'Policy Status'; }, }, { - field: 'endpoint', + field: '', name: i18n.translate('xpack.endpoint.management.list.alerts', { defaultMessage: 'Alerts', }), render: () => { - return 0; + return '0'; }, }, { @@ -105,21 +107,21 @@ export const EndpointList = () => { }), }, { - field: 'endpoint.sensor', + field: '', name: i18n.translate('xpack.endpoint.management.list.sensorVersion', { defaultMessage: 'Sensor Version', }), render: () => { - return version; + return 'version'; }, }, { - field: 'host.hostname', + field: '', name: i18n.translate('xpack.endpoint.management.list.lastActive', { defaultMessage: 'Last Active', }), render: () => { - return xxxx; + return 'xxxx'; }, }, ]; @@ -127,13 +129,6 @@ export const EndpointList = () => { return ( - - - -

Endpoints

-
-
-
@@ -150,9 +145,9 @@ export const EndpointList = () => { From 88c4406703c3b88add687978e193c2fa86b862a2 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Mon, 10 Feb 2020 12:42:36 -0500 Subject: [PATCH 15/19] functional test working --- .../feature_controls/endpoint_spaces.ts | 5 +- x-pack/test/functional/apps/endpoint/index.ts | 1 + .../functional/apps/endpoint/management.ts | 47 +++++++++++++++++++ .../functional/page_objects/endpoint_page.ts | 5 ++ 4 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 x-pack/test/functional/apps/endpoint/management.ts diff --git a/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts b/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts index 64c4feb84b831..bda336e73c4f8 100644 --- a/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts +++ b/x-pack/test/functional/apps/endpoint/feature_controls/endpoint_spaces.ts @@ -41,14 +41,13 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { await testSubjects.existOrFail('welcomeTitle'); }); - // refactor this test - it.skip(`endpoint management shows 'Manage Endpoints'`, async () => { + it(`endpoint management shows 'Manage Endpoints'`, async () => { await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/management', { basePath: '/s/custom_space', ensureCurrentUrl: false, shouldLoginIfPrompted: false, }); - await testSubjects.existOrFail('endpointManagement'); + await testSubjects.existOrFail('managementViewTitle'); }); }); diff --git a/x-pack/test/functional/apps/endpoint/index.ts b/x-pack/test/functional/apps/endpoint/index.ts index e44a4cb846f2c..5fdf54b98cda6 100644 --- a/x-pack/test/functional/apps/endpoint/index.ts +++ b/x-pack/test/functional/apps/endpoint/index.ts @@ -11,5 +11,6 @@ export default function({ loadTestFile }: FtrProviderContext) { loadTestFile(require.resolve('./feature_controls')); loadTestFile(require.resolve('./landing_page')); + loadTestFile(require.resolve('./management')); }); } diff --git a/x-pack/test/functional/apps/endpoint/management.ts b/x-pack/test/functional/apps/endpoint/management.ts new file mode 100644 index 0000000000000..bac87f34ceb82 --- /dev/null +++ b/x-pack/test/functional/apps/endpoint/management.ts @@ -0,0 +1,47 @@ +/* + * 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 expect from '@kbn/expect'; +import { FtrProviderContext } from '../../ftr_provider_context'; + +export default ({ getPageObjects, getService }: FtrProviderContext) => { + const pageObjects = getPageObjects(['common', 'endpoint']); + const esArchiver = getService('esArchiver'); + const testSubjects = getService('testSubjects'); + + describe('Endpoint Management List', function() { + this.tags('ciGroup7'); + before(async () => { + await esArchiver.load('endpoint/endpoints/api_feature'); + await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/management'); + }); + + it('finds title', async () => { + const title = await testSubjects.getVisibleText('managementViewTitle'); + expect(title).to.equal('Hosts'); + }); + + it('displays table data', async () => { + const data = await pageObjects.endpoint.getManagementTableData(); + [ + 'Hostnamecadmann-4.example.com', + 'PolicyPolicy Name', + 'Policy StatusPolicy Status', + 'Alerts0', + 'Operating Systemwindows 10.0', + 'IP Address10.192.213.130, 10.70.28.129', + 'Sensor Versionversion', + 'Last Activexxxx', + ].forEach((cellValue, index) => { + expect(data[1][index]).to.equal(cellValue); + }); + }); + + after(async () => { + await esArchiver.unload('endpoint/endpoints/api_feature'); + }); + }); +}; diff --git a/x-pack/test/functional/page_objects/endpoint_page.ts b/x-pack/test/functional/page_objects/endpoint_page.ts index f02a899f6d37d..a306a855a83eb 100644 --- a/x-pack/test/functional/page_objects/endpoint_page.ts +++ b/x-pack/test/functional/page_objects/endpoint_page.ts @@ -8,10 +8,15 @@ import { FtrProviderContext } from '../ftr_provider_context'; export function EndpointPageProvider({ getService }: FtrProviderContext) { const testSubjects = getService('testSubjects'); + const table = getService('table'); return { async welcomeEndpointTitle() { return await testSubjects.getVisibleText('welcomeTitle'); }, + + async getManagementTableData() { + return await table.getDataFromTestSubj('managementListTable'); + }, }; } From 9d374eae59cde7638219b4962c489b115c4fd7c7 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Mon, 10 Feb 2020 15:54:04 -0500 Subject: [PATCH 16/19] fixing tests and adding total count --- .../endpoint/store/endpoint_list/index.test.ts | 4 ++-- .../endpoint/store/endpoint_list/saga.test.ts | 6 +++--- .../applications/endpoint/view/managing/index.tsx | 14 +++++++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts index f41d744414dda..57c8d0b7216c5 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts @@ -8,7 +8,7 @@ import { createStore, Dispatch, Store } from 'redux'; import { EndpointListAction, endpointListReducer } from './index'; import { EndpointMetadata } from '../../../../../common/types'; import { ManagementState } from '../../types'; -import { endpointListData } from './selectors'; +import { listData } from './selectors'; describe('endpoint_list store concerns', () => { let store: Store; @@ -109,7 +109,7 @@ describe('endpoint_list store concerns', () => { test('it selects `endpointListData`', () => { const currentState = store.getState(); - expect(endpointListData(currentState)).toEqual(currentState.endpoints); + expect(listData(currentState)).toEqual(currentState.endpoints); }); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts index 0b1bbc3c04efa..ac80dff2a3ae7 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts @@ -12,7 +12,7 @@ import { endpointListReducer } from './index'; import { EndpointMetadata, EndpointResultList } from '../../../../../common/types'; import { ManagementState } from '../../types'; import { AppAction } from '../action'; -import { endpointListData } from './selectors'; +import { listData } from './selectors'; describe('endpoint list saga', () => { const sleep = (ms = 100) => new Promise(wakeup => setTimeout(wakeup, ms)); let fakeCoreStart: jest.Mocked; @@ -23,7 +23,7 @@ describe('endpoint list saga', () => { const globalStoreReducer = combineReducers({ endpointList: endpointListReducer, }); - // TODO: consolidate the below ++ helpers in `index.test.ts` into a `test_helpers.ts`?? + // https://github.com/elastic/endpoint-app-team/issues/131 const generateEndpoint = (): EndpointMetadata => { return { event: { @@ -91,6 +91,6 @@ describe('endpoint list saga', () => { paging_properties: [{ page_index: 0 }, { page_size: 10 }], }), }); - expect(endpointListData(store.getState().endpointList)).toEqual(apiResponse.endpoints); + expect(listData(store.getState().endpointList)).toEqual(apiResponse.endpoints); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index 5fdfbdf54f96b..e6834170bb385 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -13,10 +13,9 @@ import { EuiPageContentBody, EuiPageContentHeader, EuiPageContentHeaderSection, - EuiPageHeader, - EuiPageHeaderSection, EuiTitle, EuiBasicTable, + EuiTextColor, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; @@ -135,11 +134,20 @@ export const EndpointList = () => {

+

+ + + +

From b5adfe15c835a90397e0833477d8ade258488763 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 12 Feb 2020 13:59:52 -0500 Subject: [PATCH 17/19] middleware stuff --- .../public/applications/endpoint/index.tsx | 3 +- .../endpoint/store/endpoint_list/index.ts | 2 +- .../store/endpoint_list/middleware.ts | 37 ++++++++++++++ .../endpoint/store/endpoint_list/saga.test.ts | 32 ++++--------- .../endpoint/store/endpoint_list/saga.ts | 1 - .../applications/endpoint/store/index.ts | 48 ++++++++++++++++--- 6 files changed, 90 insertions(+), 33 deletions(-) create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.ts diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index 02fe261434a17..c4f421a90feb6 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -21,13 +21,12 @@ import { EndpointList } from './view/managing'; 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(, element); return () => { ReactDOM.unmountComponentAtNode(element); - stopSagas(); }; } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts index 102932e2d5a49..d98793791d8e0 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts @@ -6,4 +6,4 @@ export { endpointListReducer } from './reducer'; export { EndpointListAction } from './action'; -export { endpointListSaga } from './saga'; +export { managementMiddlewareFactory } from './middleware'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.ts new file mode 100644 index 0000000000000..44208c9d4fb0b --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.ts @@ -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 = 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 }); + } + }; +}; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts index ac80dff2a3ae7..2c6eb9b708ece 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts @@ -4,11 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ import { CoreStart, HttpSetup } from 'kibana/public'; -import { applyMiddleware, combineReducers, createStore, Dispatch, Store } from 'redux'; -import { createSagaMiddleware, SagaContext } from '../../lib'; -import { endpointListSaga } from './saga'; +import { applyMiddleware, createStore, Dispatch, Store } from 'redux'; import { coreMock } from '../../../../../../../../src/core/public/mocks'; -import { endpointListReducer } from './index'; +import { endpointListReducer, managementMiddlewareFactory } from './index'; import { EndpointMetadata, EndpointResultList } from '../../../../../common/types'; import { ManagementState } from '../../types'; import { AppAction } from '../action'; @@ -17,12 +15,10 @@ describe('endpoint list saga', () => { const sleep = (ms = 100) => new Promise(wakeup => setTimeout(wakeup, ms)); let fakeCoreStart: jest.Mocked; let fakeHttpServices: jest.Mocked; - let store: Store<{ endpointList: ManagementState }>; + let store: Store; + let getState: typeof store['getState']; let dispatch: Dispatch; let stopSagas: () => void; - const globalStoreReducer = combineReducers({ - endpointList: endpointListReducer, - }); // https://github.com/elastic/endpoint-app-team/issues/131 const generateEndpoint = (): EndpointMetadata => { return { @@ -59,22 +55,14 @@ describe('endpoint list saga', () => { total: 10, }; }; - const endpointListSagaFactory = () => { - return async (sagaContext: SagaContext) => { - await endpointListSaga(sagaContext, fakeCoreStart).catch((e: Error) => { - // eslint-disable-next-line no-console - console.error(e); - return Promise.reject(e); - }); - }; - }; beforeEach(() => { fakeCoreStart = coreMock.createStart({ basePath: '/mock' }); fakeHttpServices = fakeCoreStart.http as jest.Mocked; - const sagaMiddleware = createSagaMiddleware(endpointListSagaFactory()); - store = createStore(globalStoreReducer, applyMiddleware(sagaMiddleware)); - sagaMiddleware.start(); - stopSagas = sagaMiddleware.stop; + store = createStore( + endpointListReducer, + applyMiddleware(managementMiddlewareFactory(fakeCoreStart)) + ); + getState = store.getState; dispatch = store.dispatch; }); afterEach(() => { @@ -91,6 +79,6 @@ describe('endpoint list saga', () => { paging_properties: [{ page_index: 0 }, { page_size: 10 }], }), }); - expect(listData(store.getState().endpointList)).toEqual(apiResponse.endpoints); + expect(listData(store.getState())).toEqual(apiResponse.endpoints); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts index c82608e6a851f..d700e18f7d52e 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts @@ -5,7 +5,6 @@ */ import { CoreStart } from 'kibana/public'; -import { SagaContext } from '../../lib'; import { AppAction } from '../action'; import { pageIndex, pageSize } from './selectors'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts index fe3422f80ab3b..4661f8595088e 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts @@ -4,25 +4,59 @@ * you may not use this file except in compliance with the Elastic License. */ -import { createStore, compose, applyMiddleware, Store } from 'redux'; +import { + createStore, + compose, + applyMiddleware, + Store, + MiddlewareAPI, + Dispatch, + Middleware, +} from 'redux'; import { CoreStart } from 'kibana/public'; -import { appSagaFactory } from './saga'; import { appReducer } from './reducer'; import { alertMiddlewareFactory } from './alerts/middleware'; +import { managementMiddlewareFactory } from './endpoint_list'; +import { GlobalState } from '../types'; +import { AppAction } from './action'; const composeWithReduxDevTools = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ name: 'EndpointApp' }) : compose; -export const appStoreFactory = (coreStart: CoreStart): [Store, () => void] => { - const sagaReduxMiddleware = appSagaFactory(coreStart); +export type Selector = (state: S) => R; + +/** + * Wrap Redux Middleware and adjust 'getState()' to return the namespace from 'GlobalState that applies to the given Middleware concern. + * + * @param selector + * @param middleware + */ +export const substateMiddlewareFactory = ( + selector: Selector, + middleware: Middleware<{}, Substate, Dispatch> +): Middleware<{}, GlobalState, Dispatch> => { + return api => { + const substateAPI: MiddlewareAPI, Substate> = { + ...api, + getState() { + return selector(api.getState()); + }, + }; + return middleware(substateAPI); + }; +}; + +export const appStoreFactory = (coreStart: CoreStart): Store => { const store = createStore( appReducer, composeWithReduxDevTools( - applyMiddleware(alertMiddlewareFactory(coreStart), sagaReduxMiddleware) + applyMiddleware( + alertMiddlewareFactory(coreStart), + substateMiddlewareFactory(s => s.endpointList, managementMiddlewareFactory(coreStart)) + ) ) ); - sagaReduxMiddleware.start(); - return [store, sagaReduxMiddleware.stop]; + return store; }; From 9057c06361645c3e708042ffbb3ace10058390f0 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 12 Feb 2020 14:26:25 -0500 Subject: [PATCH 18/19] fixes typies? beat davis! go --- .../store/endpoint_list/index.test.ts | 2 +- .../{saga.test.ts => middleware.test.ts} | 8 +--- .../endpoint/store/endpoint_list/saga.ts | 40 ------------------- .../applications/endpoint/store/index.ts | 5 ++- .../applications/endpoint/store/saga.ts | 18 --------- .../public/applications/endpoint/types.ts | 4 +- 6 files changed, 9 insertions(+), 68 deletions(-) rename x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/{saga.test.ts => middleware.test.ts} (93%) delete mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts delete mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/saga.ts diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts index 57c8d0b7216c5..7c3ce3cc57ca3 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts @@ -20,7 +20,7 @@ describe('endpoint_list store concerns', () => { const generateEndpoint = (): EndpointMetadata => { return { event: { - created: new Date(), + created: new Date(0), }, endpoint: { policy: { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.test.ts similarity index 93% rename from x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts rename to x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.test.ts index 2c6eb9b708ece..4417d299277d2 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.test.ts @@ -18,12 +18,11 @@ describe('endpoint list saga', () => { let store: Store; let getState: typeof store['getState']; let dispatch: Dispatch; - let stopSagas: () => void; // https://github.com/elastic/endpoint-app-team/issues/131 const generateEndpoint = (): EndpointMetadata => { return { event: { - created: new Date(), + created: new Date(0), }, endpoint: { policy: { @@ -65,9 +64,6 @@ describe('endpoint list saga', () => { getState = store.getState; dispatch = store.dispatch; }); - afterEach(() => { - stopSagas(); - }); test('it handles `userNavigatedToPage`', async () => { const apiResponse = getEndpointListApiResponse(); fakeHttpServices.post.mockResolvedValue(apiResponse); @@ -79,6 +75,6 @@ describe('endpoint list saga', () => { paging_properties: [{ page_index: 0 }, { page_size: 10 }], }), }); - expect(listData(store.getState())).toEqual(apiResponse.endpoints); + expect(listData(getState())).toEqual(apiResponse.endpoints); }); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts deleted file mode 100644 index d700e18f7d52e..0000000000000 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/saga.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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 } from 'kibana/public'; -import { AppAction } from '../action'; -import { pageIndex, pageSize } from './selectors'; - -export const endpointListSaga = async ( - { actionsAndState, dispatch }: SagaContext, - coreStart: CoreStart -) => { - const { post: httpPost } = coreStart.http; - - for await (const { action, state } of actionsAndState()) { - if ( - (action.type === 'userNavigatedToPage' && action.payload === 'managementPage') || - action.type === 'userPaginatedEndpointListTable' - ) { - const managementPageIndex = pageIndex(state.endpointList); - const managementPageSize = pageSize(state.endpointList); - const response = await httpPost('/api/endpoint/endpoints', { - body: JSON.stringify({ - paging_properties: [ - { page_index: managementPageIndex }, - { page_size: managementPageSize }, - ], - }), - }); - // temp: request_page_index to reflect user request page index, not es page index - response.request_page_index = managementPageIndex; - dispatch({ - type: 'serverReturnedEndpointList', - payload: response, - }); - } - } -}; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts index 4661f8595088e..3780fc7ca6922 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts @@ -53,7 +53,10 @@ export const appStoreFactory = (coreStart: CoreStart): Store => { composeWithReduxDevTools( applyMiddleware( alertMiddlewareFactory(coreStart), - substateMiddlewareFactory(s => s.endpointList, managementMiddlewareFactory(coreStart)) + substateMiddlewareFactory( + globalState => globalState.endpointList, + managementMiddlewareFactory(coreStart) + ) ) ) ); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/saga.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/saga.ts deleted file mode 100644 index 3b7de79d5443c..0000000000000 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/saga.ts +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 } from 'kibana/public'; -import { createSagaMiddleware, SagaContext } from '../lib'; -import { endpointListSaga } from './endpoint_list'; - -export const appSagaFactory = (coreStart: CoreStart) => { - return createSagaMiddleware(async (sagaContext: SagaContext) => { - await Promise.all([ - // Concerns specific sagas here - endpointListSaga(sagaContext, coreStart), - ]); - }); -}; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index 3ff9709b59a4d..9328fa3229416 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -10,10 +10,10 @@ import { EndpointMetadata } from '../../../common/types'; import { AppAction } from './store/action'; import { AlertResultList } from '../../../common/types'; -export type MiddlewareFactory = ( +export type MiddlewareFactory = ( coreStart: CoreStart ) => ( - api: MiddlewareAPI, GlobalState> + api: MiddlewareAPI, S> ) => (next: Dispatch) => (action: AppAction) => unknown; export interface ManagementState { From 9721e6aff63f2b61a937f8f928b2b8b10a4fa876 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 12 Feb 2020 17:01:07 -0500 Subject: [PATCH 19/19] renaming peluja whale --- .../public/applications/endpoint/index.tsx | 4 +-- .../applications/endpoint/store/action.ts | 4 +-- .../endpoint/store/endpoint_list/action.ts | 27 ------------------- .../endpoint/store/endpoint_list/selectors.ts | 17 ------------ .../applications/endpoint/store/index.ts | 4 +-- .../endpoint/store/managing/action.ts | 27 +++++++++++++++++++ .../{endpoint_list => managing}/index.test.ts | 22 +++++++-------- .../{endpoint_list => managing}/index.ts | 4 +-- .../middleware.test.ts | 8 +++--- .../{endpoint_list => managing}/middleware.ts | 9 +++---- .../{endpoint_list => managing}/reducer.ts | 12 ++++----- .../endpoint/store/managing/selectors.ts | 17 ++++++++++++ .../applications/endpoint/store/reducer.ts | 4 +-- .../public/applications/endpoint/types.ts | 6 ++--- .../endpoint/view/managing/hooks.ts | 8 +++--- .../endpoint/view/managing/index.tsx | 14 +++++----- 16 files changed, 93 insertions(+), 94 deletions(-) delete mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts delete mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/managing/action.ts rename x-pack/plugins/endpoint/public/applications/endpoint/store/{endpoint_list => managing}/index.test.ts (81%) rename x-pack/plugins/endpoint/public/applications/endpoint/store/{endpoint_list => managing}/index.ts (75%) rename x-pack/plugins/endpoint/public/applications/endpoint/store/{endpoint_list => managing}/middleware.test.ts (92%) rename x-pack/plugins/endpoint/public/applications/endpoint/store/{endpoint_list => managing}/middleware.ts (82%) rename x-pack/plugins/endpoint/public/applications/endpoint/store/{endpoint_list => managing}/reducer.ts (71%) create mode 100644 x-pack/plugins/endpoint/public/applications/endpoint/store/managing/selectors.ts diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx index c4f421a90feb6..a86c647e771d4 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/index.tsx @@ -13,7 +13,7 @@ import { Provider } from 'react-redux'; import { Store } from 'redux'; import { appStoreFactory } from './store'; import { AlertIndex } from './view/alerts'; -import { EndpointList } from './view/managing'; +import { ManagementList } from './view/managing'; /** * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. @@ -49,7 +49,7 @@ const AppRoot: React.FunctionComponent = React.memo(({ basename, st

)} /> - + ( diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/action.ts index 593041af75c05..04c6cf7fc4634 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/action.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/action.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { EndpointListAction } from './endpoint_list'; +import { ManagementAction } from './managing'; import { AlertAction } from './alerts'; import { RoutingAction } from './routing'; -export type AppAction = EndpointListAction | AlertAction | RoutingAction; +export type AppAction = ManagementAction | AlertAction | RoutingAction; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts deleted file mode 100644 index 3893bc967bde8..0000000000000 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/action.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * 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 { ManagementPagination } from '../../types'; -import { EndpointResultList } from '../../../../../common/types'; - -interface ServerReturnedEndpointList { - type: 'serverReturnedEndpointList'; - payload: EndpointResultList; -} - -interface UserExitedEndpointListPage { - type: 'userExitedEndpointListPage'; -} - -interface UserPaginatedEndpointListTable { - type: 'userPaginatedEndpointListTable'; - payload: ManagementPagination; -} - -export type EndpointListAction = - | ServerReturnedEndpointList - | UserExitedEndpointListPage - | UserPaginatedEndpointListTable; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts deleted file mode 100644 index a8bd6ca3ccf04..0000000000000 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/selectors.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * 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 { ManagementState } from '../../types'; - -export const listData = (state: ManagementState) => state.endpoints; - -export const pageIndex = (state: ManagementState) => state.pageIndex; - -export const pageSize = (state: ManagementState) => state.pageSize; - -export const totalHits = (state: ManagementState) => state.total; - -export const isLoading = (state: ManagementState) => state.loading; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts index 3780fc7ca6922..3bbcc3f25a6d8 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/index.ts @@ -16,7 +16,7 @@ import { import { CoreStart } from 'kibana/public'; import { appReducer } from './reducer'; import { alertMiddlewareFactory } from './alerts/middleware'; -import { managementMiddlewareFactory } from './endpoint_list'; +import { managementMiddlewareFactory } from './managing'; import { GlobalState } from '../types'; import { AppAction } from './action'; @@ -54,7 +54,7 @@ export const appStoreFactory = (coreStart: CoreStart): Store => { applyMiddleware( alertMiddlewareFactory(coreStart), substateMiddlewareFactory( - globalState => globalState.endpointList, + globalState => globalState.managementList, managementMiddlewareFactory(coreStart) ) ) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/action.ts new file mode 100644 index 0000000000000..e916dc66c59f0 --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/action.ts @@ -0,0 +1,27 @@ +/* + * 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 { ManagementListPagination } from '../../types'; +import { EndpointResultList } from '../../../../../common/types'; + +interface ServerReturnedManagementList { + type: 'serverReturnedManagementList'; + payload: EndpointResultList; +} + +interface UserExitedManagementList { + type: 'userExitedManagementList'; +} + +interface UserPaginatedManagementList { + type: 'userPaginatedManagementList'; + payload: ManagementListPagination; +} + +export type ManagementAction = + | ServerReturnedManagementList + | UserExitedManagementList + | UserPaginatedManagementList; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/index.test.ts similarity index 81% rename from x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts rename to x-pack/plugins/endpoint/public/applications/endpoint/store/managing/index.test.ts index 7c3ce3cc57ca3..dde0ba1e96a8a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/index.test.ts @@ -5,16 +5,16 @@ */ import { createStore, Dispatch, Store } from 'redux'; -import { EndpointListAction, endpointListReducer } from './index'; +import { ManagementAction, managementListReducer } from './index'; import { EndpointMetadata } from '../../../../../common/types'; -import { ManagementState } from '../../types'; +import { ManagementListState } from '../../types'; import { listData } from './selectors'; describe('endpoint_list store concerns', () => { - let store: Store; - let dispatch: Dispatch; + let store: Store; + let dispatch: Dispatch; const createTestStore = () => { - store = createStore(endpointListReducer); + store = createStore(managementListReducer); dispatch = store.dispatch; }; const generateEndpoint = (): EndpointMetadata => { @@ -46,7 +46,7 @@ describe('endpoint_list store concerns', () => { }; const loadDataToStore = () => { dispatch({ - type: 'serverReturnedEndpointList', + type: 'serverReturnedManagementList', payload: { endpoints: [generateEndpoint()], request_page_size: 1, @@ -71,7 +71,7 @@ describe('endpoint_list store concerns', () => { }); }); - test('it handles `serverReturnedEndpointList', () => { + test('it handles `serverReturnedManagementList', () => { const payload = { endpoints: [generateEndpoint()], request_page_size: 1, @@ -79,7 +79,7 @@ describe('endpoint_list store concerns', () => { total: 10, }; dispatch({ - type: 'serverReturnedEndpointList', + type: 'serverReturnedManagementList', payload, }); @@ -90,12 +90,12 @@ describe('endpoint_list store concerns', () => { expect(currentState.total).toEqual(payload.total); }); - test('it handles `userExitedEndpointListPage`', () => { + test('it handles `userExitedManagementListPage`', () => { loadDataToStore(); expect(store.getState().total).toEqual(10); - dispatch({ type: 'userExitedEndpointListPage' }); + dispatch({ type: 'userExitedManagementList' }); expect(store.getState().endpoints.length).toEqual(0); expect(store.getState().pageIndex).toEqual(0); }); @@ -107,7 +107,7 @@ describe('endpoint_list store concerns', () => { loadDataToStore(); }); - test('it selects `endpointListData`', () => { + test('it selects `managementListData`', () => { const currentState = store.getState(); expect(listData(currentState)).toEqual(currentState.endpoints); }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/index.ts similarity index 75% rename from x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts rename to x-pack/plugins/endpoint/public/applications/endpoint/store/managing/index.ts index d98793791d8e0..f0bfe27c9e30f 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/index.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/index.ts @@ -4,6 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -export { endpointListReducer } from './reducer'; -export { EndpointListAction } from './action'; +export { managementListReducer } from './reducer'; +export { ManagementAction } from './action'; export { managementMiddlewareFactory } from './middleware'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.test.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/middleware.test.ts similarity index 92% rename from x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.test.ts rename to x-pack/plugins/endpoint/public/applications/endpoint/store/managing/middleware.test.ts index 4417d299277d2..095e49a6c4306 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.test.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/middleware.test.ts @@ -6,16 +6,16 @@ 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 { managementListReducer, managementMiddlewareFactory } from './index'; import { EndpointMetadata, EndpointResultList } from '../../../../../common/types'; -import { ManagementState } from '../../types'; +import { ManagementListState } 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; let fakeHttpServices: jest.Mocked; - let store: Store; + let store: Store; let getState: typeof store['getState']; let dispatch: Dispatch; // https://github.com/elastic/endpoint-app-team/issues/131 @@ -58,7 +58,7 @@ describe('endpoint list saga', () => { fakeCoreStart = coreMock.createStart({ basePath: '/mock' }); fakeHttpServices = fakeCoreStart.http as jest.Mocked; store = createStore( - endpointListReducer, + managementListReducer, applyMiddleware(managementMiddlewareFactory(fakeCoreStart)) ); getState = store.getState; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/middleware.ts similarity index 82% rename from x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.ts rename to x-pack/plugins/endpoint/public/applications/endpoint/store/managing/middleware.ts index 44208c9d4fb0b..ae756caf5aa35 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/middleware.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/middleware.ts @@ -6,15 +6,15 @@ import { MiddlewareFactory } from '../../types'; import { pageIndex, pageSize } from './selectors'; -import { ManagementState } from '../../types'; +import { ManagementListState } from '../../types'; import { AppAction } from '../action'; -export const managementMiddlewareFactory: MiddlewareFactory = coreStart => { +export const managementMiddlewareFactory: MiddlewareFactory = coreStart => { return ({ getState, dispatch }) => next => async (action: AppAction) => { next(action); if ( (action.type === 'userNavigatedToPage' && action.payload === 'managementPage') || - action.type === 'userPaginatedEndpointListTable' + action.type === 'userPaginatedManagementList' ) { const managementPageIndex = pageIndex(getState()); const managementPageSize = pageSize(getState()); @@ -28,10 +28,9 @@ export const managementMiddlewareFactory: MiddlewareFactory = c }); response.request_page_index = managementPageIndex; dispatch({ - type: 'serverReturnedEndpointList', + type: 'serverReturnedManagementList', payload: response, }); - dispatch({ type: 'serverReturnedAlertsData', payload: response }); } }; }; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/reducer.ts similarity index 71% rename from x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts rename to x-pack/plugins/endpoint/public/applications/endpoint/store/managing/reducer.ts index 5c572ffa30465..bbbbdc4d17ce6 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/endpoint_list/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/reducer.ts @@ -5,10 +5,10 @@ */ import { Reducer } from 'redux'; -import { ManagementState } from '../../types'; +import { ManagementListState } from '../../types'; import { AppAction } from '../action'; -const initialState = (): ManagementState => { +const initialState = (): ManagementListState => { return { endpoints: [], pageSize: 10, @@ -18,11 +18,11 @@ const initialState = (): ManagementState => { }; }; -export const endpointListReducer: Reducer = ( +export const managementListReducer: Reducer = ( state = initialState(), action ) => { - if (action.type === 'serverReturnedEndpointList') { + if (action.type === 'serverReturnedManagementList') { const { endpoints, total, @@ -39,11 +39,11 @@ export const endpointListReducer: Reducer = ( }; } - if (action.type === 'userExitedEndpointListPage') { + if (action.type === 'userExitedManagementList') { return initialState(); } - if (action.type === 'userPaginatedEndpointListTable') { + if (action.type === 'userPaginatedManagementList') { return { ...state, ...action.payload, diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/selectors.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/selectors.ts new file mode 100644 index 0000000000000..3dcb144c2bade --- /dev/null +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/managing/selectors.ts @@ -0,0 +1,17 @@ +/* + * 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 { ManagementListState } from '../../types'; + +export const listData = (state: ManagementListState) => state.endpoints; + +export const pageIndex = (state: ManagementListState) => state.pageIndex; + +export const pageSize = (state: ManagementListState) => state.pageSize; + +export const totalHits = (state: ManagementListState) => state.total; + +export const isLoading = (state: ManagementListState) => state.loading; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/reducer.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/reducer.ts index a9cf6d9980519..7d738c266fae0 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/reducer.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/reducer.ts @@ -4,12 +4,12 @@ * you may not use this file except in compliance with the Elastic License. */ import { combineReducers, Reducer } from 'redux'; -import { endpointListReducer } from './endpoint_list'; +import { managementListReducer } from './managing'; import { AppAction } from './action'; import { alertListReducer } from './alerts'; import { GlobalState } from '../types'; export const appReducer: Reducer = combineReducers({ - endpointList: endpointListReducer, + managementList: managementListReducer, alertList: alertListReducer, }); diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index 9328fa3229416..02a7793fc38b0 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -16,7 +16,7 @@ export type MiddlewareFactory = ( api: MiddlewareAPI, S> ) => (next: Dispatch) => (action: AppAction) => unknown; -export interface ManagementState { +export interface ManagementListState { endpoints: EndpointMetadata[]; total: number; pageSize: number; @@ -24,13 +24,13 @@ export interface ManagementState { loading: boolean; } -export interface ManagementPagination { +export interface ManagementListPagination { pageIndex: number; pageSize: number; } export interface GlobalState { - readonly endpointList: ManagementState; + readonly managementList: ManagementListState; readonly alertList: AlertListState; } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts index 9c2e4687a1a54..a0720fbd8aeeb 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/hooks.ts @@ -5,12 +5,12 @@ */ import { useSelector } from 'react-redux'; -import { GlobalState, ManagementState } from '../../types'; +import { GlobalState, ManagementListState } from '../../types'; -export function useEndpointListSelector( - selector: (state: ManagementState) => TSelected +export function useManagementListSelector( + selector: (state: ManagementListState) => TSelected ) { return useSelector(function(state: GlobalState) { - return selector(state.endpointList); + return selector(state.managementList); }); } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx index e6834170bb385..44b08f25c7653 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/managing/index.tsx @@ -20,23 +20,23 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { createStructuredSelector } from 'reselect'; -import * as selectors from '../../store/endpoint_list/selectors'; -import { EndpointListAction } from '../../store/endpoint_list/action'; -import { useEndpointListSelector } from './hooks'; +import * as selectors from '../../store/managing/selectors'; +import { ManagementAction } from '../../store/managing/action'; +import { useManagementListSelector } from './hooks'; import { usePageId } from '../use_page_id'; import { CreateStructuredSelector } from '../../types'; const selector = (createStructuredSelector as CreateStructuredSelector)(selectors); -export const EndpointList = () => { +export const ManagementList = () => { usePageId('managementPage'); - const dispatch = useDispatch<(a: EndpointListAction) => void>(); + const dispatch = useDispatch<(a: ManagementAction) => void>(); const { listData, pageIndex, pageSize, totalHits: totalItemCount, isLoading, - } = useEndpointListSelector(selector); + } = useManagementListSelector(selector); const paginationSetup = useMemo(() => { return { @@ -52,7 +52,7 @@ export const EndpointList = () => { ({ page }: { page: { index: number; size: number } }) => { const { index, size } = page; dispatch({ - type: 'userPaginatedEndpointListTable', + type: 'userPaginatedManagementList', payload: { pageIndex: index, pageSize: size }, }); },