From 1e7a3be95c6f88bad950384afb660e183366c3ce Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 13 Apr 2020 11:02:37 -0400 Subject: [PATCH 1/4] Added REST Response types to datasouces --- .../common/types/rest_spec/datasource.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/x-pack/plugins/ingest_manager/common/types/rest_spec/datasource.ts b/x-pack/plugins/ingest_manager/common/types/rest_spec/datasource.ts index f630602503f0a..6576d20dd99b9 100644 --- a/x-pack/plugins/ingest_manager/common/types/rest_spec/datasource.ts +++ b/x-pack/plugins/ingest_manager/common/types/rest_spec/datasource.ts @@ -10,12 +10,25 @@ export interface GetDatasourcesRequest { query: ListWithKuery; } +export interface GetDatasourcesResponse { + items: Datasource[]; + total: number; + page: number; + perPage: number; + success: boolean; +} + export interface GetOneDatasourceRequest { params: { datasourceId: string; }; } +export interface GetOneDatasourceResponse { + item: Datasource; + success: boolean; +} + export interface CreateDatasourceRequest { body: NewDatasource; } @@ -29,6 +42,8 @@ export type UpdateDatasourceRequest = GetOneDatasourceRequest & { body: NewDatasource; }; +export type UpdateDatasourceResponse = CreateDatasourceResponse; + export interface DeleteDatasourcesRequest { body: { datasourceIds: string[]; From 60c6ae3088e8f5281c9b1aced1e4423278498ed6 Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 13 Apr 2020 12:18:30 -0400 Subject: [PATCH 2/4] Adjust Types in Endpoint to reference those from Ingest --- .../store/policy_details/middleware.ts | 4 ++-- .../endpoint/store/policy_list/middleware.ts | 4 ++-- .../store/policy_list/services/ingest.ts | 14 ++++++------ .../public/applications/endpoint/types.ts | 22 +++++++++---------- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/middleware.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/middleware.ts index a00ce255cbac4..2581ab37f5677 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/middleware.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_details/middleware.ts @@ -8,7 +8,7 @@ import { MiddlewareFactory, PolicyData, PolicyDetailsState, - UpdateDatasourceResponse, + UpdatePolicyResponse, } from '../../types'; import { policyIdFromParams, isOnPolicyDetailsPage, policyDetails } from './selectors'; import { generatePolicy } from '../../models/policy'; @@ -77,7 +77,7 @@ export const policyDetailsMiddlewareFactory: MiddlewareFactory = coreStart => { @@ -29,7 +29,7 @@ export const policyListMiddlewareFactory: MiddlewareFactory = c pageIndex = state.pageIndex; } - let response: GetDatasourcesResponse; + let response: GetPolicyListResponse; try { response = await sendGetEndpointSpecificDatasources(http, { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/services/ingest.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/services/ingest.ts index 16c885f26f0a4..bdda0b367ee2f 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/services/ingest.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/services/ingest.ts @@ -11,9 +11,9 @@ import { } from '../../../../../../../ingest_manager/common'; import { NewPolicyData, - GetDatasourcesResponse, - GetDatasourceResponse, - UpdateDatasourceResponse, + GetPolicyListResponse, + GetPolicyResponse, + UpdatePolicyResponse, } from '../../../types'; const INGEST_API_ROOT = `/api/ingest_manager`; @@ -30,8 +30,8 @@ const INGEST_API_FLEET_AGENT_STATUS = `${INGEST_API_FLEET}/agent-status`; export const sendGetEndpointSpecificDatasources = ( http: HttpStart, options: HttpFetchOptions & Partial = {} -): Promise => { - return http.get(INGEST_API_DATASOURCES, { +): Promise => { + return http.get(INGEST_API_DATASOURCES, { ...options, query: { ...options.query, @@ -53,7 +53,7 @@ export const sendGetDatasource = ( datasourceId: string, options?: HttpFetchOptions ) => { - return http.get(`${INGEST_API_DATASOURCES}/${datasourceId}`, options); + return http.get(`${INGEST_API_DATASOURCES}/${datasourceId}`, options); }; /** @@ -69,7 +69,7 @@ export const sendPutDatasource = ( datasourceId: string, datasource: NewPolicyData, options: Exclude = {} -): Promise => { +): Promise => { return http.put(`${INGEST_API_DATASOURCES}/${datasourceId}`, { ...options, body: JSON.stringify(datasource), diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index f9ad8f6708f6b..0e9f0a5363b26 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -17,11 +17,14 @@ import { import { EndpointPluginStartDependencies } from '../../plugin'; import { AppAction } from './store/action'; import { CoreStart } from '../../../../../../src/core/public'; -import { Datasource, NewDatasource } from '../../../../ingest_manager/common/types/models'; import { + Datasource, + NewDatasource, GetAgentStatusResponse, - CreateDatasourceResponse, -} from '../../../../ingest_manager/common/types/rest_spec'; + GetDatasourcesResponse, + GetOneDatasourceResponse, + UpdateDatasourceResponse, +} from '../../../../ingest_manager/common'; export { AppAction }; export type MiddlewareFactory = ( @@ -321,22 +324,17 @@ export interface AlertingIndexUIQueryParams { filters?: string; } -export interface GetDatasourcesResponse { +export interface GetPolicyListResponse extends GetDatasourcesResponse { items: PolicyData[]; - total: number; - page: number; - perPage: number; - success: boolean; } -export interface GetDatasourceResponse { +export interface GetPolicyResponse extends GetOneDatasourceResponse { item: PolicyData; - success: boolean; } -export type UpdateDatasourceResponse = CreateDatasourceResponse & { +export interface UpdatePolicyResponse extends UpdateDatasourceResponse { item: PolicyData; -}; +} /** * The PageId type is used for the payload when firing userNavigatedToPage actions From c25bf055fe98d9a3e6e7a876a7461b01296ffdaf Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 13 Apr 2020 18:47:58 -0400 Subject: [PATCH 3/4] Fix types --- .../applications/endpoint/store/policy_list/middleware.ts | 4 ++-- .../endpoint/store/policy_list/test_mock_utils.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/middleware.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/middleware.ts index 063eff585cb83..cc771a4619e78 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/middleware.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/middleware.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { MiddlewareFactory, PolicyListState, GetPolicyListResponse } from '../../types'; +import { GetPolicyListResponse, MiddlewareFactory, PolicyListState } from '../../types'; import { sendGetEndpointSpecificDatasources } from './services/ingest'; import { isOnPolicyListPage, urlSearchParams } from './selectors'; @@ -18,7 +18,7 @@ export const policyListMiddlewareFactory: MiddlewareFactory = c if (action.type === 'userChangedUrl' && isOnPolicyListPage(state)) { const { page_index: pageIndex, page_size: pageSize } = urlSearchParams(state); - let response: GetDatasourcesResponse; + let response: GetPolicyListResponse; try { response = await sendGetEndpointSpecificDatasources(http, { diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/test_mock_utils.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/test_mock_utils.ts index 0d41ae0d76da4..20d5a637182d2 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/test_mock_utils.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/policy_list/test_mock_utils.ts @@ -8,7 +8,7 @@ import { HttpStart } from 'kibana/public'; import { Dispatch } from 'redux'; import { INGEST_API_DATASOURCES } from './services/ingest'; import { EndpointDocGenerator } from '../../../../../common/generate_data'; -import { AppAction, GetDatasourcesResponse, GlobalState, MiddlewareFactory } from '../../types'; +import { AppAction, GetPolicyListResponse, GlobalState, MiddlewareFactory } from '../../types'; const generator = new EndpointDocGenerator('policy-list'); @@ -19,13 +19,13 @@ const generator = new EndpointDocGenerator('policy-list'); */ export const setPolicyListApiMockImplementation = ( mockedHttpService: jest.Mocked, - responseItems: GetDatasourcesResponse['items'] = [generator.generatePolicyDatasource()] + responseItems: GetPolicyListResponse['items'] = [generator.generatePolicyDatasource()] ): void => { mockedHttpService.get.mockImplementation((...args) => { const [path] = args; if (typeof path === 'string') { if (path === INGEST_API_DATASOURCES) { - return Promise.resolve({ + return Promise.resolve({ items: responseItems, total: 10, page: 1, From 5400b4220d8c7e7756558e294b14d027818e84de Mon Sep 17 00:00:00 2001 From: Paul Tavares Date: Mon, 13 Apr 2020 18:49:09 -0400 Subject: [PATCH 4/4] Remove un-used endpoing type (bad upstream merge) --- .../plugins/endpoint/public/applications/endpoint/types.ts | 5 ----- 1 file changed, 5 deletions(-) diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts index ed2e3e6b23d62..ce794735a14eb 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/types.ts @@ -345,8 +345,3 @@ export interface GetPolicyResponse extends GetOneDatasourceResponse { export interface UpdatePolicyResponse extends UpdateDatasourceResponse { item: PolicyData; } - -/** - * The PageId type is used for the payload when firing userNavigatedToPage actions - */ -export type PageId = 'alertsPage' | 'managementPage' | 'policyListPage';