From 9057c06361645c3e708042ffbb3ace10058390f0 Mon Sep 17 00:00:00 2001 From: Candace Park Date: Wed, 12 Feb 2020 14:26:25 -0500 Subject: [PATCH] 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 {