From 8bcb5505e059a6c47055b9df36208fda3c6007fd Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:12:38 -0400 Subject: [PATCH] [8.11] [Infra UI] Fix process charts after refactoring (#168159) (#168210) # Backport This will backport the following commits from `main` to `8.11`: - [[Infra UI] Fix process charts after refactoring (#168159)](https://github.com/elastic/kibana/pull/168159) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) Co-authored-by: jennypavlova --- .../tabs/processes/processes.tsx | 6 +- .../inventory_view/hooks/use_process_list.ts | 79 ------------------- .../hooks/use_process_list_row_chart.ts | 55 ------------- 3 files changed, 1 insertion(+), 139 deletions(-) delete mode 100644 x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list.ts delete mode 100644 x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts diff --git a/x-pack/plugins/infra/public/components/asset_details/tabs/processes/processes.tsx b/x-pack/plugins/infra/public/components/asset_details/tabs/processes/processes.tsx index 52bad6238c103..973ff681ab570 100644 --- a/x-pack/plugins/infra/public/components/asset_details/tabs/processes/processes.tsx +++ b/x-pack/plugins/infra/public/components/asset_details/tabs/processes/processes.tsx @@ -23,11 +23,7 @@ import { parseSearchString } from './parse_search_string'; import { ProcessesTable } from './processes_table'; import { STATE_NAMES } from './states'; import { SummaryTable } from './summary_table'; -import { - SortBy, - useProcessList, - ProcessListContextProvider, -} from '../../../../pages/metrics/inventory_view/hooks/use_process_list'; +import { SortBy, useProcessList, ProcessListContextProvider } from '../../hooks/use_process_list'; import { getFieldByType } from '../../../../../common/inventory_models'; import { useAssetDetailsRenderPropsContext } from '../../hooks/use_asset_details_render_props'; import { useDateRangeProviderContext } from '../../hooks/use_date_range'; diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list.ts b/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list.ts deleted file mode 100644 index 532195ba32cc0..0000000000000 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list.ts +++ /dev/null @@ -1,79 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import createContainter from 'constate'; -import { fold } from 'fp-ts/lib/Either'; -import { identity } from 'fp-ts/lib/function'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { useEffect } from 'react'; -import { ProcessListAPIResponse, ProcessListAPIResponseRT } from '../../../../../common/http_api'; -import { throwErrors, createPlainError } from '../../../../../common/runtime_types'; -import { useHTTPRequest } from '../../../../hooks/use_http_request'; -import { useSourceContext } from '../../../../containers/metrics_source'; - -export interface SortBy { - name: string; - isAscending: boolean; -} - -export function useProcessList( - hostTerm: Record, - to: number, - sortBy: SortBy, - searchFilter: object -) { - const { createDerivedIndexPattern } = useSourceContext(); - const indexPattern = createDerivedIndexPattern().title; - - const decodeResponse = (response: any) => { - return pipe( - ProcessListAPIResponseRT.decode(response), - fold(throwErrors(createPlainError), identity) - ); - }; - - const parsedSortBy = - sortBy.name === 'runtimeLength' - ? { - ...sortBy, - name: 'startTime', - } - : sortBy; - - const { error, loading, response, makeRequest } = useHTTPRequest( - '/api/metrics/process_list', - 'POST', - JSON.stringify({ - hostTerm, - indexPattern, - to, - sortBy: parsedSortBy, - searchFilter, - }), - decodeResponse - ); - - useEffect(() => { - makeRequest(); - }, [makeRequest]); - - return { - error: (error && error.message) || null, - loading, - response, - makeRequest, - }; -} - -function useProcessListParams(props: { hostTerm: Record; to: number }) { - const { hostTerm, to } = props; - const { createDerivedIndexPattern } = useSourceContext(); - const indexPattern = createDerivedIndexPattern().title; - return { hostTerm, indexPattern, to }; -} -const ProcessListContext = createContainter(useProcessListParams); -export const [ProcessListContextProvider, useProcessListContext] = ProcessListContext; diff --git a/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts b/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts deleted file mode 100644 index 0d718ffbe210c..0000000000000 --- a/x-pack/plugins/infra/public/pages/metrics/inventory_view/hooks/use_process_list_row_chart.ts +++ /dev/null @@ -1,55 +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 - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { fold } from 'fp-ts/lib/Either'; -import { identity } from 'fp-ts/lib/function'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { useEffect, useState } from 'react'; -import { - ProcessListAPIChartResponse, - ProcessListAPIChartResponseRT, -} from '../../../../../common/http_api'; -import { throwErrors, createPlainError } from '../../../../../common/runtime_types'; -import { useHTTPRequest } from '../../../../hooks/use_http_request'; -import { useProcessListContext } from './use_process_list'; - -export function useProcessListRowChart(command: string) { - const [inErrorState, setInErrorState] = useState(false); - const decodeResponse = (response: any) => { - return pipe( - ProcessListAPIChartResponseRT.decode(response), - fold(throwErrors(createPlainError), identity) - ); - }; - const { hostTerm, indexPattern, to } = useProcessListContext(); - - const { error, loading, response, makeRequest } = useHTTPRequest( - '/api/metrics/process_list/chart', - 'POST', - JSON.stringify({ - hostTerm, - indexPattern, - to, - command, - }), - decodeResponse - ); - - useEffect(() => setInErrorState(true), [error]); - useEffect(() => setInErrorState(false), [loading]); - - useEffect(() => { - makeRequest(); - }, [makeRequest]); - - return { - error: inErrorState, - loading, - response, - makeRequest, - }; -}