From fd6584e3a49d966a17a0f882697d08c2f1714756 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Fri, 15 Mar 2024 18:12:00 -0300 Subject: [PATCH] Separate upgrade service in two services --- .../endpoints-summary/services/index.tsx | 1 + .../services/paginated-agents-request.tsx | 2 +- .../services/upgrade-agent.tsx | 11 +++++++++++ .../services/upgrade-agents.tsx | 18 +++++------------- .../table/actions/upgrade-agent-modal.test.tsx | 4 ++-- .../table/actions/upgrade-agent-modal.tsx | 4 ++-- .../global-actions/upgrade/upgrade-modal.tsx | 2 +- 7 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 plugins/main/public/components/endpoints-summary/services/upgrade-agent.tsx diff --git a/plugins/main/public/components/endpoints-summary/services/index.tsx b/plugins/main/public/components/endpoints-summary/services/index.tsx index 17910f7e44..11f86cff42 100644 --- a/plugins/main/public/components/endpoints-summary/services/index.tsx +++ b/plugins/main/public/components/endpoints-summary/services/index.tsx @@ -4,6 +4,7 @@ export { removeAgentsFromGroupService } from './remove-agents-from-group'; export { addAgentToGroupService } from './add-agent-to-group'; export { addAgentsToGroupService } from './add-agents-to-group'; export { getGroupsService } from './get-groups'; +export { upgradeAgentService } from './upgrade-agent'; export { upgradeAgentsService } from './upgrade-agents'; export { getOutdatedAgents } from './get-outdated-agents'; export { getTasks } from './get-tasks'; diff --git a/plugins/main/public/components/endpoints-summary/services/paginated-agents-request.tsx b/plugins/main/public/components/endpoints-summary/services/paginated-agents-request.tsx index 0f8020ea89..734a2afece 100644 --- a/plugins/main/public/components/endpoints-summary/services/paginated-agents-request.tsx +++ b/plugins/main/public/components/endpoints-summary/services/paginated-agents-request.tsx @@ -22,7 +22,7 @@ export const paginatedAgentsRequestService = async ({ agentIds: string[]; groupId?: string; pageSize?: number; -}): Promise> => { +}): Promise> => { let offset = 0; let requestAgentIds: string[] = []; let allAffectedItems: string[] = []; diff --git a/plugins/main/public/components/endpoints-summary/services/upgrade-agent.tsx b/plugins/main/public/components/endpoints-summary/services/upgrade-agent.tsx new file mode 100644 index 0000000000..6eb0de5d3b --- /dev/null +++ b/plugins/main/public/components/endpoints-summary/services/upgrade-agent.tsx @@ -0,0 +1,11 @@ +import IApiResponse from '../../../react-services/interfaces/api-response.interface'; +import { WzRequest } from '../../../react-services/wz-request'; +import { ResponseUpgradeAgents } from '../types'; + +export const upgradeAgentService = async (agentId: string) => + (await WzRequest.apiReq('PUT', '/agents/upgrade', { + params: { + agents_list: agentId, + wait_for_complete: true, + }, + })) as IApiResponse; diff --git a/plugins/main/public/components/endpoints-summary/services/upgrade-agents.tsx b/plugins/main/public/components/endpoints-summary/services/upgrade-agents.tsx index e20a1d5ef4..2fc0a1c807 100644 --- a/plugins/main/public/components/endpoints-summary/services/upgrade-agents.tsx +++ b/plugins/main/public/components/endpoints-summary/services/upgrade-agents.tsx @@ -1,5 +1,4 @@ import IApiResponse from '../../../react-services/interfaces/api-response.interface'; -import { WzRequest } from '../../../react-services/wz-request'; import { ResponseUpgradeAgents } from '../types'; import { paginatedAgentsRequestService } from './paginated-agents-request'; @@ -8,15 +7,8 @@ export const upgradeAgentsService = async ({ }: { agentIds: string[]; }) => - (agentIds.length === 1 - ? await WzRequest.apiReq('PUT', '/agents/upgrade', { - params: { - agents_list: agentIds.join(','), - wait_for_complete: true, - }, - }) - : await paginatedAgentsRequestService({ - method: 'PUT', - url: '/agents/upgrade', - agentIds, - })) as IApiResponse; + (await paginatedAgentsRequestService({ + method: 'PUT', + url: '/agents/upgrade', + agentIds, + })) as IApiResponse; diff --git a/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.test.tsx b/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.test.tsx index 8fc361a0a1..dff25feca7 100644 --- a/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.test.tsx +++ b/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.test.tsx @@ -1,10 +1,10 @@ import React from 'react'; -import { render, fireEvent, waitFor, act } from '@testing-library/react'; +import { render, fireEvent, act } from '@testing-library/react'; import '@testing-library/jest-dom'; import { UpgradeAgentModal } from './upgrade-agent-modal'; jest.mock('../../services', () => ({ - upgradeAgentsService: jest.fn(), + upgradeAgentService: jest.fn(), })); jest.mock('../../../../react-services/common-services', () => ({ diff --git a/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.tsx b/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.tsx index ca22be1686..1b217dcbcf 100644 --- a/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.tsx +++ b/plugins/main/public/components/endpoints-summary/table/actions/upgrade-agent-modal.tsx @@ -5,7 +5,7 @@ import { withErrorBoundary, withReduxProvider } from '../../../common/hocs'; import { UI_LOGGER_LEVELS } from '../../../../../common/constants'; import { UI_ERROR_SEVERITIES } from '../../../../react-services/error-orchestrator/types'; import { getErrorOrchestrator } from '../../../../react-services/common-services'; -import { upgradeAgentsService } from '../../services'; +import { upgradeAgentService } from '../../services'; import { Agent } from '../../types'; import { getToasts } from '../../../../kibana-services'; @@ -45,7 +45,7 @@ export const UpgradeAgentModal = compose( setIsLoading(true); try { - await upgradeAgentsService({ agentIds: [agent.id] }); + await upgradeAgentService(agent.id); showToast('success', 'Upgrade agent', 'Upgrade task in progress'); reloadAgents(); setIsUpgradePanelClosed(false); diff --git a/plugins/main/public/components/endpoints-summary/table/global-actions/upgrade/upgrade-modal.tsx b/plugins/main/public/components/endpoints-summary/table/global-actions/upgrade/upgrade-modal.tsx index df3b2d392f..36ffd83276 100644 --- a/plugins/main/public/components/endpoints-summary/table/global-actions/upgrade/upgrade-modal.tsx +++ b/plugins/main/public/components/endpoints-summary/table/global-actions/upgrade/upgrade-modal.tsx @@ -19,8 +19,8 @@ import { UI_ERROR_SEVERITIES } from '../../../../../react-services/error-orchest import { getErrorOrchestrator } from '../../../../../react-services/common-services'; import { getAgentsService, upgradeAgentsService } from '../../../services'; import { Agent, ResponseUpgradeAgents } from '../../../types'; -import { ErrorAgent } from '../../../services/paginated-agents-group'; import { UpgradeAgentsModalResult } from './result'; +import { ErrorAgent } from '../../../services/paginated-agents-request'; export type Result = { successAgents?: ResponseUpgradeAgents[];