From f08224c853912e15d280970def5b1849c2e06ab8 Mon Sep 17 00:00:00 2001 From: Philippe Oberti Date: Wed, 27 Nov 2024 11:59:01 -0600 Subject: [PATCH] [Security Solution][Expandable flyout] - remove unused code (#201477) ## Summary Some code was added in [this PR](https://github.com/elastic/kibana/pull/189633) to allow the expandable flyout to be used in the OneDiscover context. Later on, [this PR](https://github.com/elastic/kibana/pull/198294) reverted most of the changes, but some files remained. This PR cleans up all the files (that I could find) that are now unnecessary and unused (cherry picked from commit 7ebd1506ff23828095f6bd3b131a22577ad960fe) --- .../kbn-expandable-flyout/__mocks__/index.tsx | 29 ------------------ packages/kbn-expandable-flyout/index.ts | 1 - .../src/with_provider.test.tsx | 30 ------------------- .../src/with_provider.tsx | 26 ---------------- .../public/common/mock/expandable_flyout.tsx | 16 ---------- .../table_field_value_cell.test.tsx | 5 ---- .../shared/components/preview_link.test.tsx | 5 ---- 7 files changed, 112 deletions(-) delete mode 100644 packages/kbn-expandable-flyout/src/with_provider.test.tsx delete mode 100644 packages/kbn-expandable-flyout/src/with_provider.tsx diff --git a/packages/kbn-expandable-flyout/__mocks__/index.tsx b/packages/kbn-expandable-flyout/__mocks__/index.tsx index 37d8975351e55..75da56c9eb814 100644 --- a/packages/kbn-expandable-flyout/__mocks__/index.tsx +++ b/packages/kbn-expandable-flyout/__mocks__/index.tsx @@ -7,37 +7,8 @@ * License v3.0 only", or the "Server Side Public License, v 1". */ -import React from 'react'; import type { IStorage } from '@kbn/kibana-utils-plugin/public'; -export const useExpandableFlyoutApi = jest.fn(() => ({ - openFlyout: jest.fn(), - closeFlyout: jest.fn(), - openPanels: jest.fn(), - openRightPanel: jest.fn(), - openLeftPanel: jest.fn(), - openPreviewPanel: jest.fn(), - closeRightPanel: jest.fn(), - closeLeftPanel: jest.fn(), - closePreviewPanel: jest.fn(), - closePanels: jest.fn(), - previousPreviewPanel: jest.fn(), -})); - -export const useExpandableFlyoutState = jest.fn(); - -export const ExpandableFlyoutProvider = jest.fn(({ children }: React.PropsWithChildren<{}>) => { - return <>{children}; -}); - -export const withExpandableFlyoutProvider = ( - Component: React.ComponentType -) => { - return (props: T) => { - return ; - }; -}; - export const ExpandableFlyout = jest.fn(); export const localStorageMock = (): IStorage => { diff --git a/packages/kbn-expandable-flyout/index.ts b/packages/kbn-expandable-flyout/index.ts index a619717258870..48478334b6590 100644 --- a/packages/kbn-expandable-flyout/index.ts +++ b/packages/kbn-expandable-flyout/index.ts @@ -16,7 +16,6 @@ export { useExpandableFlyoutHistory } from './src/hooks/use_expandable_flyout_hi export { type FlyoutPanels as ExpandableFlyoutState } from './src/store/state'; export { ExpandableFlyoutProvider } from './src/provider'; -export { withExpandableFlyoutProvider } from './src/with_provider'; export type { ExpandableFlyoutProps } from './src'; export type { FlyoutPanelProps, PanelPath, ExpandableFlyoutApi } from './src/types'; diff --git a/packages/kbn-expandable-flyout/src/with_provider.test.tsx b/packages/kbn-expandable-flyout/src/with_provider.test.tsx deleted file mode 100644 index de9f831a5db8f..0000000000000 --- a/packages/kbn-expandable-flyout/src/with_provider.test.tsx +++ /dev/null @@ -1,30 +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", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import { render } from '@testing-library/react'; -import { useExpandableFlyoutApi } from './hooks/use_expandable_flyout_api'; -import React from 'react'; -import { withExpandableFlyoutProvider } from './with_provider'; - -const TestComponent = () => { - useExpandableFlyoutApi(); - - return
; -}; - -describe('withExpandableFlyoutProvider', () => { - it('should throw when rendered without Expandable Provider', () => { - expect(() => render()).toThrow(); - }); - - it('should not throw when rendered with Expandable Provider', () => { - const TestComponentWithProvider = withExpandableFlyoutProvider(TestComponent); - expect(() => render()).not.toThrow(); - }); -}); diff --git a/packages/kbn-expandable-flyout/src/with_provider.tsx b/packages/kbn-expandable-flyout/src/with_provider.tsx deleted file mode 100644 index d4fcca19d1bac..0000000000000 --- a/packages/kbn-expandable-flyout/src/with_provider.tsx +++ /dev/null @@ -1,26 +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", the "GNU Affero General Public License v3.0 only", and the "Server Side - * Public License v 1"; you may not use this file except in compliance with, at - * your election, the "Elastic License 2.0", the "GNU Affero General Public - * License v3.0 only", or the "Server Side Public License, v 1". - */ - -import React from 'react'; -import { ComponentType } from 'react'; -import { ExpandableFlyoutContextProviderProps } from './context'; -import { ExpandableFlyoutProvider } from './provider'; - -export const withExpandableFlyoutProvider = ( - Component: ComponentType, - expandableProviderProps?: ExpandableFlyoutContextProviderProps -) => { - return (props: Props) => { - return ( - - - - ); - }; -}; diff --git a/x-pack/plugins/security_solution/public/common/mock/expandable_flyout.tsx b/x-pack/plugins/security_solution/public/common/mock/expandable_flyout.tsx index a987e99a67d0e..69cd24e4ff453 100644 --- a/x-pack/plugins/security_solution/public/common/mock/expandable_flyout.tsx +++ b/x-pack/plugins/security_solution/public/common/mock/expandable_flyout.tsx @@ -5,8 +5,6 @@ * 2.0. */ -import React from 'react'; - export const createExpandableFlyoutApiMock = () => ({ closeFlyout: jest.fn(), closeLeftPanel: jest.fn(), @@ -18,17 +16,3 @@ export const createExpandableFlyoutApiMock = () => ({ openPreviewPanel: jest.fn(), openRightPanel: jest.fn(), }); - -export const createExpandableFlyoutMock = () => { - return { - useExpandableFlyoutApi: jest.fn().mockReturnValue(createExpandableFlyoutApiMock()), - useExpandableFlyoutState: jest.fn(), - ExpandableFlyoutProvider: ({ children }: React.PropsWithChildren<{}>) => <>{children}, - withExpandableFlyoutProvider: (Component: React.ComponentType) => { - return (props: T) => { - return ; - }; - }, - ExpandableFlyout: jest.fn(), - }; -}; diff --git a/x-pack/plugins/security_solution/public/flyout/document_details/right/components/table_field_value_cell.test.tsx b/x-pack/plugins/security_solution/public/flyout/document_details/right/components/table_field_value_cell.test.tsx index 2b7b2ec5b88ff..eec53dbe3d262 100644 --- a/x-pack/plugins/security_solution/public/flyout/document_details/right/components/table_field_value_cell.test.tsx +++ b/x-pack/plugins/security_solution/public/flyout/document_details/right/components/table_field_value_cell.test.tsx @@ -22,11 +22,6 @@ import { createTelemetryServiceMock } from '../../../../common/lib/telemetry/tel jest.mock('@kbn/expandable-flyout', () => ({ useExpandableFlyoutApi: jest.fn(), ExpandableFlyoutProvider: ({ children }: React.PropsWithChildren<{}>) => <>{children}, - withExpandableFlyoutProvider: (Component: React.ComponentType) => { - return (props: T) => { - return ; - }; - }, })); const mockedTelemetry = createTelemetryServiceMock(); diff --git a/x-pack/plugins/security_solution/public/flyout/shared/components/preview_link.test.tsx b/x-pack/plugins/security_solution/public/flyout/shared/components/preview_link.test.tsx index e08b1586caf97..0dcda8d523392 100644 --- a/x-pack/plugins/security_solution/public/flyout/shared/components/preview_link.test.tsx +++ b/x-pack/plugins/security_solution/public/flyout/shared/components/preview_link.test.tsx @@ -34,11 +34,6 @@ jest.mock('../../../common/lib/kibana', () => { jest.mock('@kbn/expandable-flyout', () => ({ useExpandableFlyoutApi: jest.fn(), ExpandableFlyoutProvider: ({ children }: React.PropsWithChildren<{}>) => <>{children}, - withExpandableFlyoutProvider: (Component: React.ComponentType) => { - return (props: T) => { - return ; - }; - }, })); const renderPreviewLink = (field: string, value: string, dataTestSuj?: string) =>