From ae0f4e53d891742d4a33dbb44bd6f963c1d67068 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 08:10:42 -0700 Subject: [PATCH 01/19] Fix public mocks --- .../__mocks__/mount_with_context.mock.tsx | 4 ++-- .../applications/__mocks__/shallow_with_i18n.mock.tsx | 11 +++++------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx b/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx index 7d0716ce0cdd0..dfcda544459d4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/__mocks__/mount_with_context.mock.tsx @@ -22,7 +22,7 @@ import { mockLicenseContext } from './license_context.mock'; * * const wrapper = mountWithContext(, { enterpriseSearchUrl: 'someOverride', license: {} }); */ -export const mountWithContext = (children, context) => { +export const mountWithContext = (children: React.ReactNode, context?: object) => { return mount( @@ -40,7 +40,7 @@ export const mountWithContext = (children, context) => { * * Same usage/override functionality as mountWithContext */ -export const mountWithKibanaContext = (children, context) => { +export const mountWithKibanaContext = (children: React.ReactNode, context?: object) => { return mount( {children} diff --git a/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_with_i18n.mock.tsx b/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_with_i18n.mock.tsx index 7815bb71fa50e..ae7d0b09f9872 100644 --- a/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_with_i18n.mock.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/__mocks__/shallow_with_i18n.mock.tsx @@ -20,12 +20,11 @@ const { intl } = intlProvider.getChildContext(); * * const wrapper = shallowWithIntl(); */ -export const shallowWithIntl = (children) => { - return shallow({children}, { - context: { intl }, - childContextTypes: { intl }, - }) +export const shallowWithIntl = (children: React.ReactNode) => { + const context = { context: { intl } }; + + return shallow({children}, context) .childAt(0) - .dive() + .dive(context) .shallow(); }; From ce70c8731bebe59f2983b3149e6a9b748957b731 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 08:14:27 -0700 Subject: [PATCH 02/19] Fix empty states types --- .../app_search/components/empty_states/empty_state.tsx | 2 +- .../app_search/components/empty_states/empty_states.test.tsx | 5 +++-- .../app_search/components/empty_states/error_state.tsx | 2 +- .../app_search/components/empty_states/loading_state.tsx | 2 +- .../app_search/components/empty_states/no_user_state.tsx | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_state.tsx index f83030f0f557c..6419c8629035e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_state.tsx @@ -16,7 +16,7 @@ import { EngineOverviewHeader } from '../engine_overview_header'; import './empty_states.scss'; -export const EmptyState: React.FC<> = () => { +export const EmptyState: React.FC = () => { const { enterpriseSearchUrl, http } = useContext(KibanaContext) as IKibanaContext; const buttonProps = { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx index bb37229998ed2..2d2f92c2f7b1f 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/empty_states.test.tsx @@ -39,7 +39,8 @@ describe('NoUserState', () => { }); it('renders with username', () => { - getUserName.mockImplementationOnce(() => 'dolores-abernathy'); + (getUserName as jest.Mock).mockImplementationOnce(() => 'dolores-abernathy'); + const wrapper = shallowWithIntl(); const prompt = wrapper.find(EuiEmptyPrompt).dive(); const description1 = prompt.find(FormattedMessage).at(1).dive(); @@ -62,7 +63,7 @@ describe('EmptyState', () => { button.simulate('click'); expect(sendTelemetry).toHaveBeenCalled(); - sendTelemetry.mockClear(); + (sendTelemetry as jest.Mock).mockClear(); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx index 486c7d8e8b4c7..142570d79f1ff 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/error_state.tsx @@ -16,7 +16,7 @@ import { EngineOverviewHeader } from '../engine_overview_header'; import './empty_states.scss'; -export const ErrorState: ReactFC<> = () => { +export const ErrorState: React.FC = () => { const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext; return ( diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/loading_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/loading_state.tsx index 5c1d0c744f743..3d69fe6126273 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/loading_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/loading_state.tsx @@ -12,7 +12,7 @@ import { EngineOverviewHeader } from '../engine_overview_header'; import './empty_states.scss'; -export const LoadingState: React.FC<> = () => { +export const LoadingState: React.FC = () => { return ( diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/no_user_state.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/no_user_state.tsx index 2993688a53132..8bf4a0c9deb55 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/no_user_state.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/no_user_state.tsx @@ -15,7 +15,7 @@ import { getUserName } from '../../utils/get_username'; import './empty_states.scss'; -export const NoUserState: React.FC<> = () => { +export const NoUserState: React.FC = () => { const username = getUserName(); return ( From bba99b172286eb5e3f5d7cacf2ce28bc486f6534 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 08:19:33 -0700 Subject: [PATCH 03/19] Fix engine table component errors --- .../engine_overview/engine_table.test.tsx | 4 +- .../engine_overview/engine_table.tsx | 50 ++++++++++--------- 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.test.tsx index 1665726251bd6..46b6e61e352de 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.test.tsx @@ -72,9 +72,9 @@ describe('EngineTable', () => { it('handles empty data', () => { const emptyWrapper = mountWithContext( - + {} }} /> ); - const emptyTable = wrapper.find(EuiBasicTable); + const emptyTable = emptyWrapper.find(EuiBasicTable); expect(emptyTable.prop('pagination').pageIndex).toEqual(0); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx index 534a1bdd57a10..6539241c4b6ac 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx @@ -5,7 +5,7 @@ */ import React, { useContext } from 'react'; -import { EuiBasicTable, EuiLink } from '@elastic/eui'; +import { EuiBasicTable, EuiBasicTableColumn, EuiLink } from '@elastic/eui'; import { FormattedMessage, FormattedDate, FormattedNumber } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; @@ -14,31 +14,33 @@ import { KibanaContext, IKibanaContext } from '../../../index'; import { ENGINES_PAGE_SIZE } from '../../../../../common/constants'; -interface IEngineTableProps { - data: Array<{ - name: string; - created_at: string; - document_count: number; - field_count: number; - }>; - pagination: { - totalEngines: number; - pageIndex: number; - onPaginate(pageIndex: number); - }; +export interface IEngineTableData { + name: string; + created_at: string; + document_count: number; + field_count: number; +} +export interface IEngineTablePagination { + totalEngines: number; + pageIndex: number; + onPaginate(pageIndex: number): void; +} +export interface IEngineTableProps { + data: IEngineTableData[]; + pagination: IEngineTablePagination; } -interface IOnChange { +export interface IOnChange { page: { index: number; }; } -export const EngineTable: ReactFC = ({ +export const EngineTable: React.FC = ({ data, pagination: { totalEngines, pageIndex = 0, onPaginate }, }) => { const { enterpriseSearchUrl, http } = useContext(KibanaContext) as IKibanaContext; - const engineLinkProps = (name) => ({ + const engineLinkProps = (name: string) => ({ href: `${enterpriseSearchUrl}/as/engines/${name}`, target: '_blank', onClick: () => @@ -50,13 +52,13 @@ export const EngineTable: ReactFC = ({ }), }); - const columns = [ + const columns: Array> = [ { field: 'name', name: i18n.translate('xpack.appSearch.enginesOverview.table.column.name', { defaultMessage: 'Name', }), - render: (name) => ( + render: (name: string) => ( {name} @@ -65,6 +67,8 @@ export const EngineTable: ReactFC = ({ truncateText: true, mobileOptions: { header: true, + // Note: the below props are valid props per https://elastic.github.io/eui/#/tabular-content/tables (Responsive tables), but EUI's types have a bug reporting it as an error + // @ts-ignore enlarge: true, fullWidth: true, truncateText: false, @@ -76,7 +80,7 @@ export const EngineTable: ReactFC = ({ defaultMessage: 'Created At', }), dataType: 'string', - render: (dateString) => ( + render: (dateString: string) => ( // e.g., January 1, 1970 ), @@ -87,7 +91,7 @@ export const EngineTable: ReactFC = ({ defaultMessage: 'Document Count', }), dataType: 'number', - render: (number) => , + render: (number: number) => , truncateText: true, }, { @@ -96,7 +100,7 @@ export const EngineTable: ReactFC = ({ defaultMessage: 'Field Count', }), dataType: 'number', - render: (number) => , + render: (number: number) => , truncateText: true, }, { @@ -105,7 +109,7 @@ export const EngineTable: ReactFC = ({ defaultMessage: 'Actions', }), dataType: 'string', - render: (name) => ( + render: (name: string) => ( = ({ totalItemCount: totalEngines, hidePerPageOptions: true, }} - onChange={({ page }): IOnChange => { + onChange={({ page }: IOnChange) => { const { index } = page; onPaginate(index + 1); // Note on paging - App Search's API pages start at 1, EuiBasicTables' pages start at 0 }} From be1de63b1c298e1ec4c2293fa05d8128ff30a9fb Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 08:23:24 -0700 Subject: [PATCH 04/19] Fix engine overview component errors --- .../engine_overview/engine_overview.test.tsx | 23 +++++++++++-------- .../engine_overview/engine_overview.tsx | 19 ++++++++++++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx index a9670163e76b8..18cf3dade2056 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx @@ -8,7 +8,7 @@ import '../../../__mocks__/react_router_history.mock'; import React from 'react'; import { act } from 'react-dom/test-utils'; -import { render } from 'enzyme'; +import { render, ReactWrapper } from 'enzyme'; import { I18nProvider } from '@kbn/i18n/react'; import { KibanaContext } from '../../../'; @@ -16,7 +16,7 @@ import { LicenseContext } from '../../../shared/licensing'; import { mountWithContext, mockKibanaContext } from '../../../__mocks__'; import { EmptyState, ErrorState, NoUserState } from '../empty_states'; -import { EngineTable } from './engine_table'; +import { EngineTable, IEngineTablePagination } from './engine_table'; import { EngineOverview } from './'; @@ -25,7 +25,7 @@ describe('EngineOverview', () => { it('isLoading', () => { // We use render() instead of mount() here to not trigger lifecycle methods (i.e., useEffect) // TODO: Consider pulling this out to a renderWithContext mock/helper - const wrapper = render( + const wrapper: Cheerio = render( @@ -85,7 +85,7 @@ describe('EngineOverview', () => { }, }; const mockApi = jest.fn(() => mockedApiResponse); - let wrapper; + let wrapper: ReactWrapper; beforeAll(async () => { wrapper = await mountWithApiMock({ get: mockApi }); @@ -105,7 +105,8 @@ describe('EngineOverview', () => { }); describe('pagination', () => { - const getTablePagination = () => wrapper.find(EngineTable).first().prop('pagination'); + const getTablePagination: () => IEngineTablePagination = () => + wrapper.find(EngineTable).first().prop('pagination'); it('passes down page data from the API', () => { const pagination = getTablePagination(); @@ -156,8 +157,8 @@ describe('EngineOverview', () => { * Test helpers */ - const mountWithApiMock = async ({ get, license }) => { - let wrapper; + const mountWithApiMock = async ({ get, license }: { get(): any; license?: object }) => { + let wrapper: ReactWrapper | undefined; const httpMock = { ...mockKibanaContext.http, get }; // We get a lot of act() warning/errors in the terminal without this. @@ -166,8 +167,12 @@ describe('EngineOverview', () => { await act(async () => { wrapper = mountWithContext(, { http: httpMock, license }); }); - wrapper.update(); // This seems to be required for the DOM to actually update + if (wrapper) { + wrapper.update(); // This seems to be required for the DOM to actually update - return wrapper; + return wrapper; + } else { + throw new Error('Could not mount wrapper'); + } }; }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx index 8676f738a412a..18f4f7a7ae13f 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx @@ -30,7 +30,7 @@ import { EngineTable } from './engine_table'; import './engine_overview.scss'; -export const EngineOverview: ReactFC<> = () => { +export const EngineOverview: React.FC = () => { const { http } = useContext(KibanaContext) as IKibanaContext; const { license } = useContext(LicenseContext) as ILicenseContext; @@ -45,12 +45,12 @@ export const EngineOverview: ReactFC<> = () => { const [metaEnginesPage, setMetaEnginesPage] = useState(1); const [metaEnginesTotal, setMetaEnginesTotal] = useState(0); - const getEnginesData = async ({ type, pageIndex }) => { + const getEnginesData = async ({ type, pageIndex }: IGetEnginesParams) => { return await http.get('/api/app_search/engines', { query: { type, pageIndex }, }); }; - const setEnginesData = async (params, callbacks) => { + const setEnginesData = async (params: IGetEnginesParams, callbacks: ISetEnginesCallbacks) => { try { const response = await getEnginesData(params); @@ -150,3 +150,16 @@ export const EngineOverview: ReactFC<> = () => { ); }; + +/** + * Type definitions + */ + +interface IGetEnginesParams { + type: string; + pageIndex: number; +} +interface ISetEnginesCallbacks { + setResults: React.Dispatch>; + setResultsTotal: React.Dispatch>; +} From 6942284528200846d8609b2d3120b1c13168ccee Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 09:22:24 -0700 Subject: [PATCH 05/19] Fix setup guide component errors - SetBreadcrumbs will be fixed in a separate commit --- .../app_search/components/setup_guide/setup_guide.tsx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/setup_guide/setup_guide.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/setup_guide/setup_guide.tsx index 4943994a94b9a..ab39c68bb245b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/setup_guide/setup_guide.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/setup_guide/setup_guide.tsx @@ -15,7 +15,6 @@ import { EuiFlexItem, EuiTitle, EuiText, - EuiImage, EuiIcon, EuiSteps, EuiCode, @@ -32,7 +31,7 @@ import { SendAppSearchTelemetry as SendTelemetry } from '../../../shared/telemet import GettingStarted from '../../assets/getting_started.png'; import './setup_guide.scss'; -export const SetupGuide: React.FC<> = () => { +export const SetupGuide: React.FC = () => { return ( From a6b347e3093f5c197464083116ea60af411d6077 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 09:24:27 -0700 Subject: [PATCH 06/19] Fix App Search index errors --- .../public/applications/app_search/index.test.tsx | 6 ++++-- .../public/applications/app_search/index.tsx | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx index d11c47475089d..45e318ca0f9d9 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/index.test.tsx @@ -18,7 +18,7 @@ import { AppSearch } from './'; describe('App Search Routes', () => { describe('/', () => { it('redirects to Setup Guide when enterpriseSearchUrl is not set', () => { - useContext.mockImplementationOnce(() => ({ enterpriseSearchUrl: '' })); + (useContext as jest.Mock).mockImplementationOnce(() => ({ enterpriseSearchUrl: '' })); const wrapper = shallow(); expect(wrapper.find(Redirect)).toHaveLength(1); @@ -26,7 +26,9 @@ describe('App Search Routes', () => { }); it('renders Engine Overview when enterpriseSearchUrl is set', () => { - useContext.mockImplementationOnce(() => ({ enterpriseSearchUrl: 'https://foo.bar' })); + (useContext as jest.Mock).mockImplementationOnce(() => ({ + enterpriseSearchUrl: 'https://foo.bar', + })); const wrapper = shallow(); expect(wrapper.find(EngineOverview)).toHaveLength(1); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx index 9afc3c9fd9761..8f7142f1631a9 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/index.tsx @@ -12,7 +12,7 @@ import { KibanaContext, IKibanaContext } from '../index'; import { SetupGuide } from './components/setup_guide'; import { EngineOverview } from './components/engine_overview'; -export const AppSearch: React.FC<> = () => { +export const AppSearch: React.FC = () => { const { enterpriseSearchUrl } = useContext(KibanaContext) as IKibanaContext; return ( From 5e0e2755ec4d53f105de36052926db5082ab4e80 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 11:27:09 -0700 Subject: [PATCH 07/19] Fix engine overview header component errors --- .../engine_overview_header.test.tsx | 8 ++++---- .../engine_overview_header/engine_overview_header.tsx | 2 +- .../shared/react_router_helpers/eui_link.test.tsx | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx index 9663eb4ef61af..2e49540270ef0 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.test.tsx @@ -24,8 +24,8 @@ describe('EngineOverviewHeader', () => { const wrapper = shallow(); const button = wrapper.find('[data-test-subj="launchButton"]'); - expect(button.props().href).toBe('http://localhost:3002/as'); - expect(button.props().isDisabled).toBeFalsy(); + expect(button.prop('href')).toBe('http://localhost:3002/as'); + expect(button.prop('isDisabled')).toBeFalsy(); button.simulate('click'); expect(sendTelemetry).toHaveBeenCalled(); @@ -35,7 +35,7 @@ describe('EngineOverviewHeader', () => { const wrapper = shallow(); const button = wrapper.find('[data-test-subj="launchButton"]'); - expect(button.props().isDisabled).toBe(true); - expect(button.props().href).toBeUndefined(); + expect(button.prop('isDisabled')).toBe(true); + expect(button.prop('href')).toBeUndefined(); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx index bc8caaaf7bc19..64da9192c9140 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx @@ -24,7 +24,7 @@ export const EngineOverviewHeader: React.FC = ({ fill: true, iconType: 'popout', 'data-test-subj': 'launchButton', - }; + } as any; if (isButtonDisabled) { buttonProps.isDisabled = true; } else { diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx index eb9b9f3e35e06..4179e0b4711ae 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx @@ -33,10 +33,10 @@ describe('EUI & React Router Component Helpers', () => { }); it('passes down all ...rest props', () => { - const wrapper = shallow(); + const wrapper = shallow(); const link = wrapper.find(EuiLink); - expect(link.prop('disabled')).toEqual(true); + expect(link.prop('external')).toEqual(true); expect(link.prop('data-test-subj')).toEqual('foo'); }); From 30cb1ddf8731f13e1ba15cf11b2dae53465a9ad5 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 12:46:44 -0700 Subject: [PATCH 08/19] Fix applications context index errors --- .../public/applications/index.test.tsx | 4 ++-- .../public/applications/index.tsx | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/index.test.tsx b/x-pack/plugins/enterprise_search/public/applications/index.test.tsx index fd88fc32ff4ae..ef69ba7e40cf3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/index.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/index.test.tsx @@ -18,14 +18,14 @@ describe('renderApp', () => { const config = {}; const plugins = { licensing: licensingMock.createSetup(), - }; + } as any; beforeEach(() => { jest.clearAllMocks(); }); it('mounts and unmounts UI', () => { - const MockApp: React.FC = () =>
Hello world!
; + const MockApp = () =>
Hello world!
; const unmount = renderApp(MockApp, core, params, config, plugins); expect(params.element.querySelector('.hello-world')).not.toBeNull(); diff --git a/x-pack/plugins/enterprise_search/public/applications/index.tsx b/x-pack/plugins/enterprise_search/public/applications/index.tsx index ac6d01f886175..b73128c701a41 100644 --- a/x-pack/plugins/enterprise_search/public/applications/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/index.tsx @@ -6,23 +6,23 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import { Router, Route, Redirect } from 'react-router-dom'; +import { Router } from 'react-router-dom'; +import { Observable } from 'rxjs'; import { I18nProvider } from '@kbn/i18n/react'; -import { CoreStart, AppMountParams, HttpHandler } from 'src/core/public'; +import { CoreStart, AppMountParameters, HttpSetup, ChromeBreadcrumb } from 'src/core/public'; import { ClientConfigType, PluginsSetup } from '../plugin'; -import { TSetBreadcrumbs } from './shared/kibana_breadcrumbs'; -import { ILicense } from '../../../../licensing/public'; +import { ILicense } from '../../../licensing/public'; import { LicenseProvider } from './shared/licensing'; export interface IKibanaContext { enterpriseSearchUrl?: string; - http(): HttpHandler; - setBreadCrumbs(): TSetBreadcrumbs; + http: HttpSetup; + setBreadcrumbs(crumbs: ChromeBreadcrumb[]): void; license$: Observable; } -export const KibanaContext = React.createContext(); +export const KibanaContext = React.createContext({}); /** * This file serves as a reusable wrapper to share Kibana-level context and other helpers @@ -31,9 +31,9 @@ export const KibanaContext = React.createContext(); */ export const renderApp = ( - App: React.Element, + App: React.FC, core: CoreStart, - params: AppMountParams, + params: AppMountParameters, config: ClientConfigType, plugins: PluginsSetup ) => { From caa808e33a9f9c11dbacf77819605c736ac20dc8 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 12:49:51 -0700 Subject: [PATCH 09/19] Fix kibana breadcrumb helper errors --- .../generate_breadcrumbs.test.ts | 25 ++++++++++--------- .../generate_breadcrumbs.ts | 8 +++--- .../set_breadcrumbs.test.tsx | 6 ++--- .../kibana_breadcrumbs/set_breadcrumbs.tsx | 17 +++++++++---- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts index b07aacf443abb..5a5cce6ec23b6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.test.ts @@ -7,7 +7,8 @@ import { generateBreadcrumb } from './generate_breadcrumbs'; import { appSearchBreadcrumbs, enterpriseSearchBreadcrumbs } from './'; -import { mockHistory } from '../../__mocks__'; +import { mockHistory as mockHistoryUntyped } from '../../__mocks__'; +const mockHistory = mockHistoryUntyped as any; jest.mock('../react_router_helpers', () => ({ letBrowserHandleEvent: jest.fn(() => false) })); import { letBrowserHandleEvent } from '../react_router_helpers'; @@ -31,7 +32,7 @@ describe('generateBreadcrumb', () => { }); it('prevents default navigation and uses React Router history on click', () => { - const breadcrumb = generateBreadcrumb({ text: '', path: '/', history: mockHistory }); + const breadcrumb = generateBreadcrumb({ text: '', path: '/', history: mockHistory }) as any; const event = { preventDefault: jest.fn() }; breadcrumb.onClick(event); @@ -40,9 +41,9 @@ describe('generateBreadcrumb', () => { }); it('does not prevents default browser behavior on new tab/window clicks', () => { - const breadcrumb = generateBreadcrumb({ text: '', path: '/', history: mockHistory }); + const breadcrumb = generateBreadcrumb({ text: '', path: '/', history: mockHistory }) as any; - letBrowserHandleEvent.mockImplementationOnce(() => true); + (letBrowserHandleEvent as jest.Mock).mockImplementationOnce(() => true); breadcrumb.onClick(); expect(mockHistory.push).not.toHaveBeenCalled(); @@ -103,19 +104,19 @@ describe('enterpriseSearchBreadcrumbs', () => { describe('links', () => { const eventMock = { preventDefault: jest.fn(), - }; + } as any; it('has Enterprise Search text first', () => { expect(subject()[0].onClick).toBeUndefined(); }); it('has a link to page 1 second', () => { - subject()[1].onClick(eventMock); + (subject()[1] as any).onClick(eventMock); expect(mockHistory.push).toHaveBeenCalledWith('/page1'); }); it('has a link to page 2 last', () => { - subject()[2].onClick(eventMock); + (subject()[2] as any).onClick(eventMock); expect(mockHistory.push).toHaveBeenCalledWith('/page2'); }); }); @@ -136,7 +137,7 @@ describe('appSearchBreadcrumbs', () => { beforeEach(() => { jest.clearAllMocks(); mockHistory.createHref.mockImplementation( - ({ pathname }) => `/enterprise_search/app_search${pathname}` + ({ pathname }: any) => `/enterprise_search/app_search${pathname}` ); }); @@ -181,24 +182,24 @@ describe('appSearchBreadcrumbs', () => { describe('links', () => { const eventMock = { preventDefault: jest.fn(), - }; + } as any; it('has Enterprise Search text first', () => { expect(subject()[0].onClick).toBeUndefined(); }); it('has a link to App Search second', () => { - subject()[1].onClick(eventMock); + (subject()[1] as any).onClick(eventMock); expect(mockHistory.push).toHaveBeenCalledWith('/'); }); it('has a link to page 1 third', () => { - subject()[2].onClick(eventMock); + (subject()[2] as any).onClick(eventMock); expect(mockHistory.push).toHaveBeenCalledWith('/page1'); }); it('has a link to page 2 last', () => { - subject()[3].onClick(eventMock); + (subject()[3] as any).onClick(eventMock); expect(mockHistory.push).toHaveBeenCalledWith('/page2'); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts index 659a113dc31de..0e1bb796cbf2e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/generate_breadcrumbs.ts @@ -21,7 +21,7 @@ interface IGenerateBreadcrumbProps { } export const generateBreadcrumb = ({ text, path, history }: IGenerateBreadcrumbProps) => { - const breadcrumb = { text }; + const breadcrumb = { text } as EuiBreadcrumb; if (path && history) { breadcrumb.href = history.createHref({ pathname: path }); @@ -39,13 +39,15 @@ export const generateBreadcrumb = ({ text, path, history }: IGenerateBreadcrumbP * Product-specific breadcrumb helpers */ -type TBreadcrumbs = EuiBreadcrumb[] | []; +export type TBreadcrumbs = IGenerateBreadcrumbProps[]; export const enterpriseSearchBreadcrumbs = (history: History) => ( breadcrumbs: TBreadcrumbs = [] ) => [ generateBreadcrumb({ text: 'Enterprise Search' }), - ...breadcrumbs.map(({ text, path }) => generateBreadcrumb({ text, path, history })), + ...breadcrumbs.map(({ text, path }: IGenerateBreadcrumbProps) => + generateBreadcrumb({ text, path, history }) + ), ]; export const appSearchBreadcrumbs = (history: History) => (breadcrumbs: TBreadcrumbs = []) => diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx index aeaa38a5ad38f..974ca54277c51 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.test.tsx @@ -14,16 +14,16 @@ import { appSearchBreadcrumbs, SetAppSearchBreadcrumbs } from './'; describe('SetAppSearchBreadcrumbs', () => { const setBreadcrumbs = jest.fn(); - const builtBreadcrumbs = []; + const builtBreadcrumbs = [] as any; const appSearchBreadCrumbsInnerCall = jest.fn().mockReturnValue(builtBreadcrumbs); const appSearchBreadCrumbsOuterCall = jest.fn().mockReturnValue(appSearchBreadCrumbsInnerCall); - appSearchBreadcrumbs.mockImplementation(appSearchBreadCrumbsOuterCall); + (appSearchBreadcrumbs as jest.Mock).mockImplementation(appSearchBreadCrumbsOuterCall); afterEach(() => { jest.clearAllMocks(); }); - const mountSetAppSearchBreadcrumbs = (props) => { + const mountSetAppSearchBreadcrumbs = (props: any) => { return mountWithKibanaContext(, { http: {}, enterpriseSearchUrl: 'http://localhost:3002', diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx index aaa54febcc20b..941ff91712a44 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx @@ -8,7 +8,7 @@ import React, { useContext, useEffect } from 'react'; import { useHistory } from 'react-router-dom'; import { Breadcrumb as EuiBreadcrumb } from '@elastic/eui'; import { KibanaContext, IKibanaContext } from '../../index'; -import { appSearchBreadcrumbs } from './generate_breadcrumbs'; +import { appSearchBreadcrumbs, TBreadcrumbs } from './generate_breadcrumbs'; /** * Small on-mount helper for setting Kibana's chrome breadcrumbs on any App Search view @@ -17,19 +17,26 @@ import { appSearchBreadcrumbs } from './generate_breadcrumbs'; export type TSetBreadcrumbs = (breadcrumbs: EuiBreadcrumb[]) => void; -interface ISetBreadcrumbsProps { +interface IBreadcrumbProps { text: string; - isRoot?: boolean; + isRoot?: never; +} +interface IRootBreadcrumbProps { + isRoot: true; + text?: never; } -export const SetAppSearchBreadcrumbs: React.FC = ({ text, isRoot }) => { +export const SetAppSearchBreadcrumbs: React.FC = ({ + text, + isRoot, +}) => { const history = useHistory(); const { setBreadcrumbs } = useContext(KibanaContext) as IKibanaContext; const crumb = isRoot ? [] : [{ text, path: history.location.pathname }]; useEffect(() => { - setBreadcrumbs(appSearchBreadcrumbs(history)(crumb)); + setBreadcrumbs(appSearchBreadcrumbs(history)(crumb as TBreadcrumbs | [])); }, []); // eslint-disable-line react-hooks/exhaustive-deps return null; From 143f2803a72494ffdd53977cbf5c0fa98a7e10c7 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 12:50:54 -0700 Subject: [PATCH 10/19] Fix license helper errors --- .../shared/licensing/license_checks.test.ts | 18 +++++++++--------- .../shared/licensing/license_checks.ts | 6 +++--- .../shared/licensing/license_context.test.tsx | 4 ++-- .../shared/licensing/license_context.tsx | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.test.ts index e21bf004b39a2..ad134e7d36b10 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.test.ts @@ -8,26 +8,26 @@ import { hasPlatinumLicense } from './license_checks'; describe('hasPlatinumLicense', () => { it('is true for platinum licenses', () => { - expect(hasPlatinumLicense({ isActive: true, type: 'platinum' })).toEqual(true); + expect(hasPlatinumLicense({ isActive: true, type: 'platinum' } as any)).toEqual(true); }); it('is true for enterprise licenses', () => { - expect(hasPlatinumLicense({ isActive: true, type: 'enterprise' })).toEqual(true); + expect(hasPlatinumLicense({ isActive: true, type: 'enterprise' } as any)).toEqual(true); }); it('is true for trial licenses', () => { - expect(hasPlatinumLicense({ isActive: true, type: 'platinum' })).toEqual(true); + expect(hasPlatinumLicense({ isActive: true, type: 'platinum' } as any)).toEqual(true); }); it('is false if the current license is expired', () => { - expect(hasPlatinumLicense({ isActive: false, type: 'platinum' })).toEqual(false); - expect(hasPlatinumLicense({ isActive: false, type: 'enterprise' })).toEqual(false); - expect(hasPlatinumLicense({ isActive: false, type: 'trial' })).toEqual(false); + expect(hasPlatinumLicense({ isActive: false, type: 'platinum' } as any)).toEqual(false); + expect(hasPlatinumLicense({ isActive: false, type: 'enterprise' } as any)).toEqual(false); + expect(hasPlatinumLicense({ isActive: false, type: 'trial' } as any)).toEqual(false); }); it('is false for licenses below platinum', () => { - expect(hasPlatinumLicense({ isActive: true, type: 'basic' })).toEqual(false); - expect(hasPlatinumLicense({ isActive: false, type: 'standard' })).toEqual(false); - expect(hasPlatinumLicense({ isActive: true, type: 'gold' })).toEqual(false); + expect(hasPlatinumLicense({ isActive: true, type: 'basic' } as any)).toEqual(false); + expect(hasPlatinumLicense({ isActive: false, type: 'standard' } as any)).toEqual(false); + expect(hasPlatinumLicense({ isActive: true, type: 'gold' } as any)).toEqual(false); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.ts b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.ts index 7d0de8a093b31..363ae39ab0da4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_checks.ts @@ -4,8 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { ILicense } from '../../../../../../licensing/public'; +import { ILicense } from '../../../../../licensing/public'; -export const hasPlatinumLicense = (license: ILicenseContext) => { - return license?.isActive && ['platinum', 'enterprise', 'trial'].includes(license?.type); +export const hasPlatinumLicense = (license: ILicense) => { + return license?.isActive && ['platinum', 'enterprise', 'trial'].includes(license?.type as string); }; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.test.tsx index 01d976bf49c19..c65474ec1f590 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.test.tsx @@ -10,9 +10,9 @@ import { mountWithContext } from '../../__mocks__'; import { LicenseContext, ILicenseContext } from './'; describe('LicenseProvider', () => { - const MockComponent: React.FC<> = () => { + const MockComponent: React.FC = () => { const { license } = useContext(LicenseContext) as ILicenseContext; - return
{license.type}
; + return
{license?.type}
; }; it('renders children', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.tsx index c8295196aedb5..dec9cdac892f6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/licensing/license_context.tsx @@ -9,15 +9,15 @@ import useObservable from 'react-use/lib/useObservable'; import { KibanaContext, IKibanaContext } from '../../'; -import { ILicense } from '../../../../licensing/public'; +import { ILicense } from '../../../../../licensing/public'; export interface ILicenseContext { - license?: ILicense; + license: ILicense; } -export const LicenseContext = React.createContext(); +export const LicenseContext = React.createContext({}); -export const LicenseProvider: React.FC<> = ({ children }) => { +export const LicenseProvider: React.FC = ({ children }) => { // Listen for changes to license subscription const { license$ } = useContext(KibanaContext) as IKibanaContext; const license = useObservable(license$); From ffa46c5f3cef32fc168ec2440a82ee8e7d7d3eb6 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 12:53:48 -0700 Subject: [PATCH 11/19] :exclamation: Refactor React Router EUI link/button helpers - in order to fix typescript errors - this changes the component logic significantly to a react render prop, so that the Link and Button components can have different types - however, end behavior should still remain the same --- .../react_router_helpers/eui_link.test.tsx | 12 ++++----- .../shared/react_router_helpers/eui_link.tsx | 26 +++++++++++++------ .../react_router_helpers/link_events.test.ts | 4 +-- .../react_router_helpers/link_events.ts | 7 ++--- 4 files changed, 29 insertions(+), 20 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx index 4179e0b4711ae..7d4c068b21155 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.test.tsx @@ -5,7 +5,7 @@ */ import React from 'react'; -import { shallow } from 'enzyme'; +import { shallow, mount } from 'enzyme'; import { EuiLink, EuiButton } from '@elastic/eui'; import '../../__mocks__/react_router_history.mock'; @@ -25,9 +25,7 @@ describe('EUI & React Router Component Helpers', () => { }); it('renders an EuiButton', () => { - const wrapper = shallow() - .find(EuiReactRouterLink) - .dive(); + const wrapper = shallow(); expect(wrapper.find(EuiButton)).toHaveLength(1); }); @@ -41,7 +39,7 @@ describe('EUI & React Router Component Helpers', () => { }); it('renders with the correct href and onClick props', () => { - const wrapper = shallow(); + const wrapper = mount(); const link = wrapper.find(EuiLink); expect(link.prop('onClick')).toBeInstanceOf(Function); @@ -51,7 +49,7 @@ describe('EUI & React Router Component Helpers', () => { describe('onClick', () => { it('prevents default navigation and uses React Router history', () => { - const wrapper = shallow(); + const wrapper = mount(); const simulatedEvent = { button: 0, @@ -65,7 +63,7 @@ describe('EUI & React Router Component Helpers', () => { }); it('does not prevent default browser behavior on new tab/window clicks', () => { - const wrapper = shallow(); + const wrapper = mount(); const simulatedEvent = { shiftKey: true, diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.tsx index 3c410584cc49d..f486e432bae76 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/eui_link.tsx @@ -6,7 +6,7 @@ import React from 'react'; import { useHistory } from 'react-router-dom'; -import { EuiLink, EuiButton } from '@elastic/eui'; +import { EuiLink, EuiButton, EuiButtonProps, EuiLinkAnchorProps } from '@elastic/eui'; import { letBrowserHandleEvent } from './link_events'; @@ -19,13 +19,12 @@ import { letBrowserHandleEvent } from './link_events'; interface IEuiReactRouterProps { to: string; - isButton?: boolean; } -export const EuiReactRouterLink: React.FC = ({ to, isButton, ...rest }) => { +export const EuiReactRouterHelper: React.FC = ({ to, children }) => { const history = useHistory(); - const onClick = (event) => { + const onClick = (event: React.MouseEvent) => { if (letBrowserHandleEvent(event)) return; // Prevent regular link behavior, which causes a browser refresh. @@ -38,10 +37,21 @@ export const EuiReactRouterLink: React.FC = ({ to, isButto // Generate the correct link href (with basename etc. accounted for) const href = history.createHref({ pathname: to }); - const props = { ...rest, href, onClick }; - return isButton ? : ; + const reactRouterProps = { href, onClick }; + return React.cloneElement(children as React.ReactElement, reactRouterProps); }; -export const EuiReactRouterButton: React.FC = (props) => ( - +type TEuiReactRouterLinkProps = EuiLinkAnchorProps & IEuiReactRouterProps; +type TEuiReactRouterButtonProps = EuiButtonProps & IEuiReactRouterProps; + +export const EuiReactRouterLink: React.FC = ({ to, ...rest }) => ( + + + +); + +export const EuiReactRouterButton: React.FC = ({ to, ...rest }) => ( + + + ); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts index 0845e5562776b..3682946b63a13 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.test.ts @@ -17,7 +17,7 @@ describe('letBrowserHandleEvent', () => { target: { getAttribute: () => '_self', }, - }; + } as any; describe('the browser should handle the link when', () => { it('default is prevented', () => { @@ -95,7 +95,7 @@ describe('letBrowserHandleEvent', () => { }); }); -const targetValue = (value) => { +const targetValue = (value: string | null) => { return { getAttribute: () => value, }; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.ts b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.ts index 67e987623c2c1..93da2ab71d952 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/react_router_helpers/link_events.ts @@ -4,14 +4,14 @@ * you may not use this file except in compliance with the Elastic License. */ -import { SyntheticEvent } from 'react'; +import { MouseEvent } from 'react'; /** * Helper functions for determining which events we should * let browsers handle natively, e.g. new tabs/windows */ -type THandleEvent = (event: SyntheticEvent) => boolean; +type THandleEvent = (event: MouseEvent) => boolean; export const letBrowserHandleEvent: THandleEvent = (event) => event.defaultPrevented || @@ -25,6 +25,7 @@ const isModifiedEvent: THandleEvent = (event) => const isLeftClickEvent: THandleEvent = (event) => event.button === 0; const isTargetBlank: THandleEvent = (event) => { - const target = event.target.getAttribute('target'); + const element = event.target as HTMLElement; + const target = element.getAttribute('target'); return !!target && target !== '_self'; }; From 0f66185b163a04041d0e3e17eb31ae122f23903f Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 12:55:03 -0700 Subject: [PATCH 12/19] Fix telemetry helper errors --- .../shared/telemetry/send_telemetry.test.tsx | 13 +++++++------ .../shared/telemetry/send_telemetry.tsx | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx index 7f4a0d3f19074..341c7100cb062 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.test.tsx @@ -33,18 +33,19 @@ describe('Shared Telemetry Helpers', () => { }); it('throws an error if the telemetry endpoint fails', () => { - const httpRejectMock = { put: () => Promise.reject() }; + const httpRejectMock = sendTelemetry({ + http: { put: () => Promise.reject() }, + } as any); - expect(sendTelemetry({ http: httpRejectMock })).rejects.toThrow('Unable to send telemetry'); + expect(httpRejectMock).rejects.toThrow('Unable to send telemetry'); }); }); describe('React component helpers', () => { it('SendAppSearchTelemetry component', () => { - const wrapper = mountWithKibanaContext( - , - { http: httpMock } - ); + mountWithKibanaContext(, { + http: httpMock, + }); expect(httpMock.put).toHaveBeenCalledWith('/api/app_search/telemetry', { headers: { 'content-type': 'application/json' }, diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx index 33ef0d7d14b95..6797cde1f14b4 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/telemetry/send_telemetry.tsx @@ -6,7 +6,7 @@ import React, { useContext, useEffect } from 'react'; -import { HttpHandler } from 'src/core/public'; +import { HttpSetup } from 'src/core/public'; import { KibanaContext, IKibanaContext } from '../../index'; interface ISendTelemetryProps { @@ -15,7 +15,7 @@ interface ISendTelemetryProps { } interface ISendTelemetry extends ISendTelemetryProps { - http(): HttpHandler; + http: HttpSetup; product: 'app_search' | 'workplace_search' | 'enterprise_search'; } From fc6c7ae75d2b41f8ddfc53cc5667f06197a83511 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 14:42:31 -0700 Subject: [PATCH 13/19] Minor unused var cleanup in plugin files --- x-pack/plugins/enterprise_search/public/plugin.ts | 2 +- x-pack/plugins/enterprise_search/server/plugin.ts | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/plugin.ts b/x-pack/plugins/enterprise_search/public/plugin.ts index 5863df5ccba25..1ebfdd779a791 100644 --- a/x-pack/plugins/enterprise_search/public/plugin.ts +++ b/x-pack/plugins/enterprise_search/public/plugin.ts @@ -32,7 +32,7 @@ export interface PluginsSetup { export class EnterpriseSearchPlugin implements Plugin { private config: ClientConfigType; - constructor(private readonly initializerContext: PluginInitializerContext) { + constructor(initializerContext: PluginInitializerContext) { this.config = initializerContext.config.get(); } diff --git a/x-pack/plugins/enterprise_search/server/plugin.ts b/x-pack/plugins/enterprise_search/server/plugin.ts index 077d900a8d8cf..4449f4cc0356d 100644 --- a/x-pack/plugins/enterprise_search/server/plugin.ts +++ b/x-pack/plugins/enterprise_search/server/plugin.ts @@ -31,7 +31,6 @@ export interface ServerConfigType { export class EnterpriseSearchPlugin implements Plugin { private config: Observable; private logger: Logger; - private savedObjects?: SavedObjectsServiceStart; constructor(initializerContext: PluginInitializerContext) { this.config = initializerContext.config.create(); From dc02e93875113cf9a89956cbeea2b5425e174dc4 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 14:44:42 -0700 Subject: [PATCH 14/19] Fix telemetry collector/savedobjects errors --- .../server/collectors/app_search/telemetry.test.ts | 6 +++--- .../server/collectors/app_search/telemetry.ts | 8 ++++++-- .../server/saved_objects/app_search/telemetry.ts | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts index 4be2c220024bc..3afe6efbaa5d4 100644 --- a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts +++ b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.test.ts @@ -17,7 +17,7 @@ describe('App Search Telemetry Usage Collector', () => { const usageCollectionMock = { makeUsageCollector: makeUsageCollectorStub, registerCollector: registerStub, - }; + } as any; const savedObjectsRepoStub = { get: () => ({ @@ -35,7 +35,7 @@ describe('App Search Telemetry Usage Collector', () => { }; const savedObjectsMock = { createInternalRepository: jest.fn(() => savedObjectsRepoStub), - }; + } as any; beforeEach(() => { jest.clearAllMocks(); @@ -74,7 +74,7 @@ describe('App Search Telemetry Usage Collector', () => { }); it('should not error & should return a default telemetry object if no saved data exists', async () => { - const emptySavedObjectsMock = { createInternalRepository: () => ({}) }; + const emptySavedObjectsMock = { createInternalRepository: () => ({}) } as any; registerTelemetryUsageCollector(usageCollectionMock, emptySavedObjectsMock); const savedObjectsCounts = await makeUsageCollectorStub.mock.calls[0][0].fetch(); diff --git a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts index 12b5a165bf1ac..6ea883566b2bb 100644 --- a/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts +++ b/x-pack/plugins/enterprise_search/server/collectors/app_search/telemetry.ts @@ -21,6 +21,7 @@ export const registerTelemetryUsageCollector = ( const telemetryUsageCollector = usageCollection.makeUsageCollector({ type: 'app_search', fetch: async () => fetchTelemetryMetrics(savedObjects), + isReady: () => true, }); usageCollection.registerCollector(telemetryUsageCollector); }; @@ -71,9 +72,12 @@ const fetchTelemetryMetrics = async (savedObjects: SavedObjectsServiceStart) => interface ISavedObjectAttributes { [key: string]: any; } - -const getSavedObjectAttributesFromRepo = async ( +type TGetSavedObjectAttributes = ( savedObjectsRepository: ISavedObjectsRepository +) => ISavedObjectAttributes; + +const getSavedObjectAttributesFromRepo: TGetSavedObjectAttributes = async ( + savedObjectsRepository ) => { try { return (await savedObjectsRepository.get(AS_TELEMETRY_NAME, AS_TELEMETRY_NAME)).attributes; diff --git a/x-pack/plugins/enterprise_search/server/saved_objects/app_search/telemetry.ts b/x-pack/plugins/enterprise_search/server/saved_objects/app_search/telemetry.ts index 20c03b6aece8a..02bfe450ce7eb 100644 --- a/x-pack/plugins/enterprise_search/server/saved_objects/app_search/telemetry.ts +++ b/x-pack/plugins/enterprise_search/server/saved_objects/app_search/telemetry.ts @@ -27,7 +27,7 @@ export interface ITelemetrySavedObject { export const appSearchTelemetryType: SavedObjectsType = { name: AS_TELEMETRY_NAME, hidden: false, - namespaceAgnostic: true, + namespaceType: 'single', mappings: { properties: { ui_viewed: { From b6bde5e6690c68e279d1979a8d5c3328c0ed8d63 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 14:50:40 -0700 Subject: [PATCH 15/19] Fix MockRouter type errors and add IRouteDependencies export - routes will use IRouteDependencies in the next few commits --- .../enterprise_search/server/plugin.ts | 8 ++++ .../server/routes/__mocks__/router.mock.ts | 39 ++++++++++++++----- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/plugin.ts b/x-pack/plugins/enterprise_search/server/plugin.ts index 4449f4cc0356d..a8430ad8f56af 100644 --- a/x-pack/plugins/enterprise_search/server/plugin.ts +++ b/x-pack/plugins/enterprise_search/server/plugin.ts @@ -12,6 +12,7 @@ import { CoreSetup, Logger, SavedObjectsServiceStart, + IRouter, } from 'src/core/server'; import { UsageCollectionSetup } from 'src/plugins/usage_collection/server'; @@ -28,6 +29,13 @@ export interface ServerConfigType { host?: string; } +export interface IRouteDependencies { + router: IRouter; + config: ServerConfigType; + log: Logger; + getSavedObjectsService?(): SavedObjectsServiceStart; +} + export class EnterpriseSearchPlugin implements Plugin { private config: Observable; private logger: Logger; diff --git a/x-pack/plugins/enterprise_search/server/routes/__mocks__/router.mock.ts b/x-pack/plugins/enterprise_search/server/routes/__mocks__/router.mock.ts index 1cec5da055140..332d1ad1062f2 100644 --- a/x-pack/plugins/enterprise_search/server/routes/__mocks__/router.mock.ts +++ b/x-pack/plugins/enterprise_search/server/routes/__mocks__/router.mock.ts @@ -5,7 +5,12 @@ */ import { httpServiceMock, httpServerMock } from 'src/core/server/mocks'; -import { IRouter, RequestHandlerContext, RouteValidatorConfig } from 'src/core/server'; +import { + IRouter, + KibanaRequest, + RequestHandlerContext, + RouteValidatorConfig, +} from 'src/core/server'; /** * Test helper that mocks Kibana's router and DRYs out various helper (callRoute, schema validation) @@ -14,13 +19,24 @@ import { IRouter, RequestHandlerContext, RouteValidatorConfig } from 'src/core/s type methodType = 'get' | 'post' | 'put' | 'patch' | 'delete'; type payloadType = 'params' | 'query' | 'body'; +interface IMockRouterProps { + method: methodType; + payload: payloadType; +} +interface IMockRouterRequest { + body?: object; + query?: object; + params?: object; +} +type TMockRouterRequest = KibanaRequest | IMockRouterRequest; + export class MockRouter { - public router: jest.Mocked; + public router!: jest.Mocked; public method: methodType; public payload: payloadType; public response = httpServerMock.createResponseFactory(); - private constructor({ method, payload }) { + constructor({ method, payload }: IMockRouterProps) { this.createRouter(); this.method = method; this.payload = payload; @@ -30,29 +46,32 @@ export class MockRouter { this.router = httpServiceMock.createRouter(); }; - public callRoute = async (request) => { - const [_, handler] = this.router[this.method].mock.calls[0]; + public callRoute = async (request: TMockRouterRequest) => { + const [, handler] = this.router[this.method].mock.calls[0]; const context = {} as jest.Mocked; - await handler(context, httpServerMock.createKibanaRequest(request), this.response); + await handler(context, httpServerMock.createKibanaRequest(request as any), this.response); }; /** * Schema validation helpers */ - public validateRoute = (request) => { + public validateRoute = (request: TMockRouterRequest) => { const [config] = this.router[this.method].mock.calls[0]; const validate = config.validate as RouteValidatorConfig<{}, {}, {}>; - validate[this.payload].validate(request[this.payload]); + const payloadValidation = validate[this.payload] as { validate(request: KibanaRequest): void }; + const payloadRequest = request[this.payload] as KibanaRequest; + + payloadValidation.validate(payloadRequest); }; - public shouldValidate = (request) => { + public shouldValidate = (request: TMockRouterRequest) => { expect(() => this.validateRoute(request)).not.toThrow(); }; - public shouldThrow = (request) => { + public shouldThrow = (request: TMockRouterRequest) => { expect(() => this.validateRoute(request)).toThrow(); }; } From 9f0a123ab89e962edfef15d4e5fc875efc1c643c Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 14:51:43 -0700 Subject: [PATCH 16/19] Fix engines route errors --- .../server/routes/app_search/engines.test.ts | 4 ++-- .../server/routes/app_search/engines.ts | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts index 722ad0d9269d3..7eab94940f0d1 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.test.ts @@ -172,7 +172,7 @@ describe('engine routes', () => { return Promise.resolve(new Response(JSON.stringify(response))); }); }, - andReturnInvalidData(response: object) { + andReturnInvalidData() { fetchMock.mockImplementation((url: string, params: object) => { expect(url).toEqual(expectedUrl); expect(params).toEqual(expectedParams); @@ -180,7 +180,7 @@ describe('engine routes', () => { return Promise.resolve(new Response(JSON.stringify({ foo: 'bar' }))); }); }, - andReturnError(response: object) { + andReturnError() { fetchMock.mockImplementation((url: string, params: object) => { expect(url).toEqual(expectedUrl); expect(params).toEqual(expectedParams); diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts index ebe2252b24eef..ffc7a0228454f 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/engines.ts @@ -8,9 +8,10 @@ import fetch from 'node-fetch'; import querystring from 'querystring'; import { schema } from '@kbn/config-schema'; +import { IRouteDependencies } from '../../plugin'; import { ENGINES_PAGE_SIZE } from '../../../common/constants'; -export function registerEnginesRoute({ router, config, log }) { +export function registerEnginesRoute({ router, config, log }: IRouteDependencies) { router.get( { path: '/api/app_search/engines', @@ -23,7 +24,7 @@ export function registerEnginesRoute({ router, config, log }) { }, async (context, request, response) => { try { - const appSearchUrl = config.host; + const appSearchUrl = config.host as string; const { type, pageIndex } = request.query; const params = querystring.stringify({ @@ -34,7 +35,7 @@ export function registerEnginesRoute({ router, config, log }) { const url = `${encodeURI(appSearchUrl)}/as/engines/collection?${params}`; const enginesResponse = await fetch(url, { - headers: { Authorization: request.headers.authorization }, + headers: { Authorization: request.headers.authorization as string }, }); if (enginesResponse.url.endsWith('/login')) { @@ -58,7 +59,7 @@ export function registerEnginesRoute({ router, config, log }) { } } catch (e) { log.error(`Cannot connect to App Search: ${e.toString()}`); - if (e instanceof Error) log.debug(e.stack); + if (e instanceof Error) log.debug(e.stack as string); return response.notFound({ body: 'cannot-connect' }); } From 6c6ce2159f8a45dd745852c01b3a5ea2b8504a84 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 14:52:15 -0700 Subject: [PATCH 17/19] Fix telemetry route errors --- .../server/routes/app_search/telemetry.test.ts | 6 +++--- .../server/routes/app_search/telemetry.ts | 9 ++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.test.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.test.ts index 7644f3019de80..5774c7bcc3ebb 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.test.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.test.ts @@ -26,13 +26,13 @@ describe('App Search Telemetry API', () => { router: mockRouter.router, getSavedObjectsService: () => savedObjectsServiceMock.create(), log: mockLogger, - }); + } as any); }); describe('PUT /api/app_search/telemetry', () => { it('increments the saved objects counter', async () => { const successResponse = { success: true }; - incrementUICounter.mockImplementation(jest.fn(() => successResponse)); + (incrementUICounter as jest.Mock).mockImplementation(jest.fn(() => successResponse)); await mockRouter.callRoute({ body: { action: 'viewed', metric: 'setup_guide' } }); @@ -45,7 +45,7 @@ describe('App Search Telemetry API', () => { }); it('throws an error when incrementing fails', async () => { - incrementUICounter.mockImplementation(jest.fn(() => Promise.reject('Failed'))); + (incrementUICounter as jest.Mock).mockImplementation(jest.fn(() => Promise.reject('Failed'))); await mockRouter.callRoute({ body: { action: 'error', metric: 'error' } }); diff --git a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.ts b/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.ts index 6b7657a384e9f..4cc9b64adc092 100644 --- a/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.ts +++ b/x-pack/plugins/enterprise_search/server/routes/app_search/telemetry.ts @@ -6,9 +6,14 @@ import { schema } from '@kbn/config-schema'; +import { IRouteDependencies } from '../../plugin'; import { incrementUICounter } from '../../collectors/app_search/telemetry'; -export function registerTelemetryRoute({ router, getSavedObjectsService, log }) { +export function registerTelemetryRoute({ + router, + getSavedObjectsService, + log, +}: IRouteDependencies) { router.put( { path: '/api/app_search/telemetry', @@ -27,6 +32,8 @@ export function registerTelemetryRoute({ router, getSavedObjectsService, log }) const { action, metric } = request.body; try { + if (!getSavedObjectsService) throw new Error('Could not find Saved Objects service'); + return response.ok({ body: await incrementUICounter({ savedObjects: getSavedObjectsService(), From e5dcd5f476ad1f904e50846620135196611a79a7 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Wed, 3 Jun 2020 16:10:54 -0700 Subject: [PATCH 18/19] Remove any type from source code - thanks to Scotty for the inspiration --- .../engine_overview_header.tsx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx index 64da9192c9140..283eb5b3a72af 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview_header/engine_overview_header.tsx @@ -5,7 +5,14 @@ */ import React, { useContext } from 'react'; -import { EuiPageHeader, EuiPageHeaderSection, EuiTitle, EuiButton } from '@elastic/eui'; +import { + EuiPageHeader, + EuiPageHeaderSection, + EuiTitle, + EuiButton, + EuiButtonProps, + EuiLinkProps, +} from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { sendTelemetry } from '../../../shared/telemetry'; @@ -24,7 +31,8 @@ export const EngineOverviewHeader: React.FC = ({ fill: true, iconType: 'popout', 'data-test-subj': 'launchButton', - } as any; + } as EuiButtonProps & EuiLinkProps; + if (isButtonDisabled) { buttonProps.isDisabled = true; } else { From fa5ecdaf93ca72715b0ea95d7d0d62c03e5beb52 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Thu, 4 Jun 2020 09:23:41 -0700 Subject: [PATCH 19/19] Add eslint rules for Enterprise Search plugin - Add checks for type any, but only on non-test files - Disable react-hooks/exhaustive-deps, since we're already disabling it in a few files and other plugins also have it turned off --- .eslintrc.js | 12 ++++++++++++ .../components/engine_overview/engine_overview.tsx | 4 ++-- .../shared/kibana_breadcrumbs/set_breadcrumbs.tsx | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index aeaf6e04fdc01..6df3385bda5ff 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -881,6 +881,18 @@ module.exports = { }, }, + /** + * Enterprise Search overrides + */ + { + files: ['x-pack/plugins/enterprise_search/**/*.{ts,tsx}'], + excludedFiles: ['x-pack/plugins/enterprise_search/**/*.{test,mock}.{ts,tsx}'], + rules: { + 'react-hooks/exhaustive-deps': 'off', + '@typescript-eslint/no-explicit-any': 'error', + }, + }, + /** * disable jsx-a11y for kbn-ui-framework */ diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx index 18f4f7a7ae13f..ee193a4bf016c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx @@ -72,7 +72,7 @@ export const EngineOverview: React.FC = () => { const callbacks = { setResults: setEngines, setResultsTotal: setEnginesTotal }; setEnginesData(params, callbacks); - }, [enginesPage]); // eslint-disable-line react-hooks/exhaustive-deps + }, [enginesPage]); useEffect(() => { if (hasPlatinumLicense(license)) { @@ -81,7 +81,7 @@ export const EngineOverview: React.FC = () => { setEnginesData(params, callbacks); } - }, [license, metaEnginesPage]); // eslint-disable-line react-hooks/exhaustive-deps + }, [license, metaEnginesPage]); if (hasErrorConnecting) return ; if (hasNoAccount) return ; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx index 941ff91712a44..ad3cd65c09516 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana_breadcrumbs/set_breadcrumbs.tsx @@ -37,7 +37,7 @@ export const SetAppSearchBreadcrumbs: React.FC { setBreadcrumbs(appSearchBreadcrumbs(history)(crumb as TBreadcrumbs | [])); - }, []); // eslint-disable-line react-hooks/exhaustive-deps + }, []); return null; };