From 8e3465edbc489e3e275eab6359d581a4df292ad2 Mon Sep 17 00:00:00 2001 From: Yulia Cech Date: Wed, 20 Sep 2023 20:39:19 +0200 Subject: [PATCH 01/10] [Index Management] Refactor the index details component to use a query param instead of a path parameter for index name to avoid issues with encoded characters --- .../index_details_page.helpers.ts | 4 +- .../index_details_page.test.tsx | 12 -- .../public/application/sections/home/home.tsx | 5 +- .../index_list/details_page/details_page.tsx | 120 ++++++++---------- .../details_page/details_page_mappings.tsx | 7 +- .../details_page/details_page_settings.tsx | 13 +- .../details_page/details_page_stats.tsx | 13 +- .../sections/home/index_list/index_list.tsx | 3 +- .../public/application/services/routing.ts | 11 ++ 9 files changed, 75 insertions(+), 113 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts index 24cf015e3918dc..754356bd1f6f95 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts @@ -23,8 +23,8 @@ import { testIndexName } from './mocks'; let routerMock: typeof reactRouterMock; const testBedConfig: AsyncTestBedConfig = { memoryRouter: { - initialEntries: [`/indices/${testIndexName}`], - componentRoutePath: `/indices/:indexName/:indexDetailsSection?`, + initialEntries: [`/indices/index_details?indexName=${testIndexName}`], + componentRoutePath: `/indices/index_details`, onRouter: (router) => { routerMock = router; }, diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx index 78a93692224772..0186a4875e6cc7 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx @@ -206,12 +206,6 @@ describe('', () => { }); }); - it('documents tab', async () => { - await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Documents); - const tabContent = testBed.actions.getActiveTabContent(); - expect(tabContent).toEqual('Documents'); - }); - describe('Mappings tab', () => { it('loads mappings from the API', async () => { await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Mappings); @@ -375,12 +369,6 @@ describe('', () => { }); }); - it('pipelines tab', async () => { - await testBed.actions.clickIndexDetailsTab(IndexDetailsSection.Pipelines); - const tabContent = testBed.actions.getActiveTabContent(); - expect(tabContent).toEqual('Pipelines'); - }); - it('navigates back to indices', async () => { jest.spyOn(testBed.routerMock.history, 'push'); await testBed.actions.clickBackToIndicesButton(); diff --git a/x-pack/plugins/index_management/public/application/sections/home/home.tsx b/x-pack/plugins/index_management/public/application/sections/home/home.tsx index 27e68920c56122..0abb2bc04e290d 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/home.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/home.tsx @@ -149,10 +149,7 @@ export const IndexManagementHome: React.FunctionComponent - + indexManagementTabs} /> diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx index 33378fc138c04e..440dccc66af236 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx @@ -5,10 +5,9 @@ * 2.0. */ -import React, { useCallback, useEffect, useMemo, useState } from 'react'; +import React, { useCallback, useEffect, useMemo, useState, FunctionComponent } from 'react'; import { css } from '@emotion/react'; -import { Redirect, RouteComponentProps } from 'react-router-dom'; -import { Route, Routes } from '@kbn/shared-ux-router'; +import { RouteComponentProps } from 'react-router-dom'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiPageHeader, @@ -19,6 +18,7 @@ import { } from '@elastic/eui'; import { SectionLoading } from '@kbn/es-ui-shared-plugin/public'; +import { getIndexDetailsLink } from '../../../../services/routing'; import { Index } from '../../../../../../common'; import { INDEX_OPEN } from '../../../../../../common/constants'; import { Error } from '../../../../../shared_imports'; @@ -35,10 +35,8 @@ import { DetailsPageSettings } from './details_page_settings'; export enum IndexDetailsSection { Overview = 'overview', - Documents = 'documents', Mappings = 'mappings', Settings = 'settings', - Pipelines = 'pipelines', Stats = 'stats', } const defaultTabs = [ @@ -48,12 +46,6 @@ const defaultTabs = [ ), }, - { - id: IndexDetailsSection.Documents, - name: ( - - ), - }, { id: IndexDetailsSection.Mappings, name: ( @@ -66,12 +58,6 @@ const defaultTabs = [ ), }, - { - id: IndexDetailsSection.Pipelines, - name: ( - - ), - }, ]; const statsTab = { @@ -79,19 +65,52 @@ const statsTab = { name: , }; -export const DetailsPage: React.FunctionComponent< - RouteComponentProps<{ indexName: string; indexDetailsSection: IndexDetailsSection }> -> = ({ - match: { - params: { indexName, indexDetailsSection }, - }, - history, +const getSelectedTabContent = ({ + tab, + index, + indexName, +}: { + tab: IndexDetailsSection; + index?: Index | null; + indexName: string; }) => { + // if there is no index data, the tab content won't be rendered, to it's safe to return null here + if (!index) { + return null; + } + switch (tab) { + case IndexDetailsSection.Overview: + return ; + case IndexDetailsSection.Mappings: + return ; + case IndexDetailsSection.Settings: + return ( + + ); + case IndexDetailsSection.Stats: + return ; + default: + return ; + } +}; +export const DetailsPage: FunctionComponent< + RouteComponentProps<{ indexName: string; indexDetailsSection: IndexDetailsSection }> +> = ({ location: { search }, history }) => { const { config } = useAppContext(); + const queryParams = useMemo(() => new URLSearchParams(search), [search]); + const indexName = queryParams.get('indexName') ?? ''; + const tab = queryParams.get('tab') ?? IndexDetailsSection.Overview; + let indexDetailsSection = IndexDetailsSection.Overview; + if (Object.values(IndexDetailsSection).includes(tab as IndexDetailsSection)) { + indexDetailsSection = tab as IndexDetailsSection; + } + const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(null); const [index, setIndex] = useState(); - + const selectedTabContent = useMemo(() => { + return getSelectedTabContent({ tab: indexDetailsSection, index, indexName }); + }, [index, indexDetailsSection, indexName]); const fetchIndexDetails = useCallback(async () => { setIsLoading(true); try { @@ -111,7 +130,7 @@ export const DetailsPage: React.FunctionComponent< const onSectionChange = useCallback( (newSection: IndexDetailsSection) => { - return history.push(encodeURI(`/indices/${indexName}/${newSection}`)); + return history.push(getIndexDetailsLink(indexName, newSection)); }, [history, indexName] ); @@ -123,12 +142,12 @@ export const DetailsPage: React.FunctionComponent< const headerTabs = useMemo(() => { const visibleTabs = config.enableIndexStats ? [...defaultTabs, statsTab] : defaultTabs; - return visibleTabs.map((tab) => ({ - onClick: () => onSectionChange(tab.id), - isSelected: tab.id === indexDetailsSection, - key: tab.id, - 'data-test-subj': `indexDetailsTab-${tab.id}`, - label: tab.name, + return visibleTabs.map((visibleTab) => ({ + onClick: () => onSectionChange(visibleTab.id), + isSelected: visibleTab.id === indexDetailsSection, + key: visibleTab.id, + 'data-test-subj': `indexDetailsTab-${visibleTab.id}`, + label: visibleTab.name, })); }, [indexDetailsSection, onSectionChange, config]); @@ -187,42 +206,7 @@ export const DetailsPage: React.FunctionComponent< height: 100%; `} > - - } - /> -
Documents
} - /> - - ) => ( - - )} - /> -
Pipelines
} - /> - {config.enableIndexStats && ( - ) => ( - - )} - /> - )} - -
+ {selectedTabContent} ); diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings.tsx index ca8556599f224a..30e16e65b6dc2f 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_mappings.tsx @@ -20,16 +20,11 @@ import { EuiTitle, } from '@elastic/eui'; import { css } from '@emotion/react'; -import { RouteComponentProps } from 'react-router-dom'; import { FormattedMessage } from '@kbn/i18n-react'; import { SectionLoading } from '@kbn/es-ui-shared-plugin/public'; import { useLoadIndexMappings, documentationService } from '../../../../services'; -export const DetailsPageMappings: FunctionComponent> = ({ - match: { - params: { indexName }, - }, -}) => { +export const DetailsPageMappings: FunctionComponent<{ indexName: string }> = ({ indexName }) => { const { isLoading, data, error, resendRequest } = useLoadIndexMappings(indexName); if (isLoading) { diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx index a00267d9ea310b..6e0690a0164e64 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx @@ -6,7 +6,6 @@ */ import React, { FunctionComponent } from 'react'; -import { RouteComponentProps } from 'react-router-dom'; import { EuiButton, EuiPageTemplate, EuiSpacer, EuiText } from '@elastic/eui'; import { SectionLoading } from '@kbn/es-ui-shared-plugin/public'; import { FormattedMessage } from '@kbn/i18n-react'; @@ -14,14 +13,10 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { useLoadIndexSettings } from '../../../../services'; import { DetailsPageSettingsContent } from './details_page_settings_content'; -export const DetailsPageSettings: FunctionComponent< - RouteComponentProps<{ indexName: string }> & { isIndexOpen: boolean } -> = ({ - match: { - params: { indexName }, - }, - isIndexOpen, -}) => { +export const DetailsPageSettings: FunctionComponent<{ + indexName: string; + isIndexOpen: boolean; +}> = ({ indexName, isIndexOpen }) => { const { isLoading, data, error, resendRequest } = useLoadIndexSettings(indexName); if (isLoading) { diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_stats.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_stats.tsx index 91fbf54728bfd3..912a76949bb9dc 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_stats.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_stats.tsx @@ -6,7 +6,6 @@ */ import React, { FunctionComponent, useState, useCallback, useEffect } from 'react'; -import { RouteComponentProps } from 'react-router-dom'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiSpacer, @@ -28,16 +27,8 @@ import { IndicesStatsResponse } from '@elastic/elasticsearch/lib/api/types'; import { SectionLoading, Error } from '../../../../../shared_imports'; import { loadIndexStatistics, documentationService } from '../../../../services'; -interface Props { - isIndexOpen: boolean; -} - -export const DetailsPageStats: FunctionComponent< - RouteComponentProps<{ indexName: string }> & Props -> = ({ - match: { - params: { indexName }, - }, +export const DetailsPageStats: FunctionComponent<{ indexName: string; isIndexOpen: boolean }> = ({ + indexName, isIndexOpen, }) => { const [isLoading, setIsLoading] = useState(false); diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx index 14bbd94adc2fd0..6d4e3f031c1cf8 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/index_list.tsx @@ -9,6 +9,7 @@ import React, { useCallback } from 'react'; import { RouteComponentProps } from 'react-router-dom'; import { ScopedHistory } from '@kbn/core/public'; +import { getIndexDetailsLink } from '../../../services/routing'; import { APP_WRAPPER_CLASS, useExecutionContext } from '../../../../shared_imports'; import { useAppContext } from '../../../app_context'; import { DetailPanel } from './detail_panel'; @@ -27,7 +28,7 @@ export const IndexList: React.FunctionComponent = ({ histor const openDetailPanel = useCallback( (indexName: string) => { - return history.push(encodeURI(`/indices/${indexName}`)); + return history.push(getIndexDetailsLink(indexName)); }, [history] ); diff --git a/x-pack/plugins/index_management/public/application/services/routing.ts b/x-pack/plugins/index_management/public/application/services/routing.ts index 3eb8dc74155d60..ad3322acbe95ba 100644 --- a/x-pack/plugins/index_management/public/application/services/routing.ts +++ b/x-pack/plugins/index_management/public/application/services/routing.ts @@ -5,6 +5,9 @@ * 2.0. */ +import { IndexDetailsSection } from '../sections/home/index_list/details_page'; +import { Section } from '../sections/home/home'; + export const getTemplateListLink = () => `/templates`; export const getTemplateDetailsLink = (name: string, isLegacy?: boolean) => { @@ -54,3 +57,11 @@ export const getIndexListUri = (filter?: string, includeHiddenIndices?: boolean) export const getDataStreamDetailsLink = (name: string) => { return encodeURI(`/data_streams/${encodeURIComponent(name)}`); }; + +export const getIndexDetailsLink = (indexName: string, tab?: IndexDetailsSection) => { + let link = `/${Section.Indices}/index_details?indexName=${encodeURIComponent(indexName)}`; + if (tab) { + link = `${link}&tab=${tab}`; + } + return link; +}; From 96220f829eb6bda9ad873995e826f9a93d7d002c Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 21 Sep 2023 12:53:53 +0000 Subject: [PATCH 02/10] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../home/index_list/details_page/details_page_settings.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx index ff0c0f1934cf31..08e210cf1683c7 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page_settings.tsx @@ -5,7 +5,6 @@ * 2.0. */ - import React, { FunctionComponent, useEffect } from 'react'; import { EuiButton, EuiPageTemplate, EuiSpacer, EuiText } from '@elastic/eui'; import { SectionLoading } from '@kbn/es-ui-shared-plugin/public'; From 8a771d9080c8af77237bdd8c641288f93ae3ab20 Mon Sep 17 00:00:00 2001 From: Yulia Cech Date: Thu, 21 Sep 2023 15:00:25 +0200 Subject: [PATCH 03/10] [Index Management] Update the limits.yml --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 78bba1df4220a9..9d5f602c65c3be 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -72,7 +72,7 @@ pageLoadAssetSize: home: 30182 imageEmbeddable: 12500 indexLifecycleManagement: 107090 - indexManagement: 140608 + indexManagement: 641000 infra: 184320 ingestPipelines: 58003 inputControlVis: 172675 From a2138b0e78d37cabb50572004d4ae11382f21c8b Mon Sep 17 00:00:00 2001 From: Yulia Cech Date: Thu, 21 Sep 2023 17:11:22 +0200 Subject: [PATCH 04/10] [Index Management] Fix bundle size --- .../common/constants/home_sections.ts | 21 +++++++++++++++++++ .../common/constants/index.ts | 2 ++ .../public/application/sections/home/home.tsx | 10 ++------- .../index_list/details_page/details_page.tsx | 8 +------ .../public/application/services/routing.ts | 3 +-- 5 files changed, 27 insertions(+), 17 deletions(-) create mode 100644 x-pack/plugins/index_management/common/constants/home_sections.ts diff --git a/x-pack/plugins/index_management/common/constants/home_sections.ts b/x-pack/plugins/index_management/common/constants/home_sections.ts new file mode 100644 index 00000000000000..c4bb72691dcde8 --- /dev/null +++ b/x-pack/plugins/index_management/common/constants/home_sections.ts @@ -0,0 +1,21 @@ +/* + * 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. + */ + +export enum Section { + Indices = 'indices', + DataStreams = 'data_streams', + IndexTemplates = 'templates', + ComponentTemplates = 'component_templates', + EnrichPolicies = 'enrich_policies', +} + +export enum IndexDetailsSection { + Overview = 'overview', + Mappings = 'mappings', + Settings = 'settings', + Stats = 'stats', +} diff --git a/x-pack/plugins/index_management/common/constants/index.ts b/x-pack/plugins/index_management/common/constants/index.ts index 786dad4a5e375f..16972f187707a2 100644 --- a/x-pack/plugins/index_management/common/constants/index.ts +++ b/x-pack/plugins/index_management/common/constants/index.ts @@ -53,3 +53,5 @@ export { } from './ui_metric'; export { MAJOR_VERSION } from './plugin'; + +export { Section, IndexDetailsSection } from './home_sections'; diff --git a/x-pack/plugins/index_management/public/application/sections/home/home.tsx b/x-pack/plugins/index_management/public/application/sections/home/home.tsx index acb788987f23a1..f5e6cf85002fef 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/home.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/home.tsx @@ -10,6 +10,8 @@ import { RouteComponentProps } from 'react-router-dom'; import { Routes, Route } from '@kbn/shared-ux-router'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiButtonEmpty, EuiPageHeader, EuiSpacer } from '@elastic/eui'; + +import { Section } from '../../../../common/constants'; import { documentationService } from '../../services/documentation'; import { useAppContext } from '../../app_context'; import { ComponentTemplateList } from '../../components/component_templates'; @@ -19,14 +21,6 @@ import { IndexDetailsPage } from './index_list/details_page'; import { DataStreamList } from './data_stream_list'; import { TemplateList } from './template_list'; -export enum Section { - Indices = 'indices', - DataStreams = 'data_streams', - IndexTemplates = 'templates', - ComponentTemplates = 'component_templates', - EnrichPolicies = 'enrich_policies', -} - export const homeSections = [ Section.Indices, Section.DataStreams, diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx index 440dccc66af236..432f4321203485 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx @@ -18,6 +18,7 @@ import { } from '@elastic/eui'; import { SectionLoading } from '@kbn/es-ui-shared-plugin/public'; +import { Section, IndexDetailsSection } from '../../../../../../common/constants'; import { getIndexDetailsLink } from '../../../../services/routing'; import { Index } from '../../../../../../common'; import { INDEX_OPEN } from '../../../../../../common/constants'; @@ -25,7 +26,6 @@ import { Error } from '../../../../../shared_imports'; import { loadIndex } from '../../../../services'; import { useAppContext } from '../../../../app_context'; import { DiscoverLink } from '../../../../lib/discover_link'; -import { Section } from '../../home'; import { DetailsPageError } from './details_page_error'; import { ManageIndexButton } from './manage_index_button'; import { DetailsPageStats } from './details_page_stats'; @@ -33,12 +33,6 @@ import { DetailsPageMappings } from './details_page_mappings'; import { DetailsPageOverview } from './details_page_overview'; import { DetailsPageSettings } from './details_page_settings'; -export enum IndexDetailsSection { - Overview = 'overview', - Mappings = 'mappings', - Settings = 'settings', - Stats = 'stats', -} const defaultTabs = [ { id: IndexDetailsSection.Overview, diff --git a/x-pack/plugins/index_management/public/application/services/routing.ts b/x-pack/plugins/index_management/public/application/services/routing.ts index ad3322acbe95ba..3fd56644240752 100644 --- a/x-pack/plugins/index_management/public/application/services/routing.ts +++ b/x-pack/plugins/index_management/public/application/services/routing.ts @@ -5,8 +5,7 @@ * 2.0. */ -import { IndexDetailsSection } from '../sections/home/index_list/details_page'; -import { Section } from '../sections/home/home'; +import { Section, IndexDetailsSection } from '../../../common/constants'; export const getTemplateListLink = () => `/templates`; From bf9b1fabba98c644d0aafbe383755c67816b97ff Mon Sep 17 00:00:00 2001 From: Yulia Cech Date: Thu, 21 Sep 2023 18:27:11 +0200 Subject: [PATCH 05/10] [Index Management] Fix imports --- .../index_details_page/index_details_page.helpers.ts | 7 +++---- .../index_details_page/index_details_page.test.tsx | 5 ++++- x-pack/plugins/index_management/public/application/app.tsx | 4 ++-- .../sections/home/data_stream_list/data_stream_list.tsx | 2 +- .../public/application/sections/home/index.ts | 2 +- .../sections/home/index_list/details_page/index.ts | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts index 754356bd1f6f95..84c65812f6434d 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts @@ -13,10 +13,9 @@ import { } from '@kbn/test-jest-helpers'; import { HttpSetup } from '@kbn/core/public'; import { act } from 'react-dom/test-utils'; -import { - IndexDetailsPage, - IndexDetailsSection, -} from '../../../public/application/sections/home/index_list/details_page'; + +import { IndexDetailsSection } from '../../../common/constants'; +import { IndexDetailsPage } from '../../../public/application/sections/home/index_list/details_page'; import { WithAppDependencies } from '../helpers'; import { testIndexName } from './mocks'; diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx index 03d54c8e6ba604..9fbbb133fbd581 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx @@ -8,11 +8,14 @@ import { setupEnvironment } from '../helpers'; import { IndexDetailsPageTestBed, setup } from './index_details_page.helpers'; import { act } from 'react-dom/test-utils'; + +import React from 'react'; +import { IndexDetailsSection } from '../../../common/constants'; +import { API_BASE_PATH, INTERNAL_API_BASE_PATH } from '../../../common'; import { breadcrumbService, IndexManagementBreadcrumb, } from '../../../public/application/services/breadcrumbs'; -import { IndexDetailsSection } from '../../../public/application/sections/home/index_list/details_page'; import { testIndexEditableSettings, testIndexMappings, diff --git a/x-pack/plugins/index_management/public/application/app.tsx b/x-pack/plugins/index_management/public/application/app.tsx index 163af333e72478..1fc9dd26e4cdea 100644 --- a/x-pack/plugins/index_management/public/application/app.tsx +++ b/x-pack/plugins/index_management/public/application/app.tsx @@ -12,8 +12,8 @@ import { Redirect } from 'react-router-dom'; import { Router, Routes, Route } from '@kbn/shared-ux-router'; import { ScopedHistory } from '@kbn/core/public'; -import { UIM_APP_LOAD } from '../../common/constants'; -import { IndexManagementHome, homeSections, Section } from './sections/home'; +import { UIM_APP_LOAD, Section } from '../../common/constants'; +import { IndexManagementHome, homeSections } from './sections/home'; import { TemplateCreate } from './sections/template_create'; import { TemplateClone } from './sections/template_clone'; import { TemplateEdit } from './sections/template_edit'; diff --git a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx index 140fb2a4282ee4..04a5a4a20f491f 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/data_stream_list/data_stream_list.tsx @@ -32,11 +32,11 @@ import { APP_WRAPPER_CLASS, useExecutionContext, } from '../../../../shared_imports'; +import { Section } from '../../../../../common/constants'; import { useAppContext } from '../../../app_context'; import { useLoadDataStreams } from '../../../services/api'; import { breadcrumbService, IndexManagementBreadcrumb } from '../../../services/breadcrumbs'; import { documentationService } from '../../../services/documentation'; -import { Section } from '../home'; import { DataStreamTable } from './data_stream_table'; import { DataStreamDetailPanel } from './data_stream_detail_panel'; import { filterDataStreams, isSelectedDataStreamHidden } from '../../../lib/data_streams'; diff --git a/x-pack/plugins/index_management/public/application/sections/home/index.ts b/x-pack/plugins/index_management/public/application/sections/home/index.ts index 4ea8ac7906f979..db6dd2942bfe87 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index.ts +++ b/x-pack/plugins/index_management/public/application/sections/home/index.ts @@ -5,4 +5,4 @@ * 2.0. */ -export { IndexManagementHome, Section, homeSections } from './home'; +export { IndexManagementHome, homeSections } from './home'; diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/index.ts b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/index.ts index dd87a626cc90e1..b80f65823d0304 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/index.ts +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/index.ts @@ -5,4 +5,4 @@ * 2.0. */ -export { DetailsPage as IndexDetailsPage, IndexDetailsSection } from './details_page'; +export { DetailsPage as IndexDetailsPage } from './details_page'; From 4f94f82d20edaf4ede73a3b4c5d079cb64dce071 Mon Sep 17 00:00:00 2001 From: Yulia Cech Date: Thu, 21 Sep 2023 19:06:38 +0200 Subject: [PATCH 06/10] [Index Management] Fix imports --- .../index_details_page/index_details_page.test.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx index 9fbbb133fbd581..a7250c73dc61af 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx @@ -24,8 +24,6 @@ import { testIndexSettings, testIndexStats, } from './mocks'; -import { API_BASE_PATH, INTERNAL_API_BASE_PATH } from '../../../common'; -import React from 'react'; jest.mock('@kbn/kibana-react-plugin/public', () => { const original = jest.requireActual('@kbn/kibana-react-plugin/public'); From bb799aa6967459e106b08a4dbca0f6db37e9efdb Mon Sep 17 00:00:00 2001 From: Yulia Cech Date: Thu, 21 Sep 2023 20:49:41 +0200 Subject: [PATCH 07/10] [Index Management] Fix imports --- packages/kbn-optimizer/limits.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kbn-optimizer/limits.yml b/packages/kbn-optimizer/limits.yml index 9d5f602c65c3be..78bba1df4220a9 100644 --- a/packages/kbn-optimizer/limits.yml +++ b/packages/kbn-optimizer/limits.yml @@ -72,7 +72,7 @@ pageLoadAssetSize: home: 30182 imageEmbeddable: 12500 indexLifecycleManagement: 107090 - indexManagement: 641000 + indexManagement: 140608 infra: 184320 ingestPipelines: 58003 inputControlVis: 172675 From 41debe72eaf69a8414630846c36c7dc61a85e8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yulia=20=C4=8Cech?= <6585477+yuliacech@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:34:56 +0200 Subject: [PATCH 08/10] Update x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx Co-authored-by: Alison Goryachev --- .../sections/home/index_list/details_page/details_page.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx index 432f4321203485..7b2e24ce5cb873 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx @@ -68,7 +68,7 @@ const getSelectedTabContent = ({ index?: Index | null; indexName: string; }) => { - // if there is no index data, the tab content won't be rendered, to it's safe to return null here + // if there is no index data, the tab content won't be rendered, so it's safe to return null here if (!index) { return null; } From d3591e6c1bc2409ebd557e5b517c48461908fee2 Mon Sep 17 00:00:00 2001 From: Yulia Cech Date: Fri, 22 Sep 2023 13:10:26 +0200 Subject: [PATCH 09/10] [Index Management] Add no index name message and prevent an http request being unnecessarily sent out --- .../index_details_page.helpers.ts | 27 ++++-- .../index_details_page.test.tsx | 85 +++++++++++++------ .../index_list/details_page/details_page.tsx | 51 +++++++++-- 3 files changed, 118 insertions(+), 45 deletions(-) diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts index b0cfc40fd36fd9..a390232cd81c5e 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.helpers.ts @@ -20,16 +20,16 @@ import { WithAppDependencies } from '../helpers'; import { testIndexName } from './mocks'; let routerMock: typeof reactRouterMock; -const testBedConfig: AsyncTestBedConfig = { +const getTestBedConfig = (initialEntry?: string): AsyncTestBedConfig => ({ memoryRouter: { - initialEntries: [`/indices/index_details?indexName=${testIndexName}`], + initialEntries: [initialEntry ?? `/indices/index_details?indexName=${testIndexName}`], componentRoutePath: `/indices/index_details`, onRouter: (router) => { routerMock = router; }, }, doMountAsync: true, -}; +}); export interface IndexDetailsPageTestBed extends TestBed { routerMock: typeof reactRouterMock; @@ -66,6 +66,7 @@ export interface IndexDetailsPageTestBed extends TestBed { errorSection: { isDisplayed: () => boolean; clickReloadButton: () => Promise; + noIndexNameMessageIsDisplayed: () => boolean; }; stats: { getCodeBlockContent: () => string; @@ -84,13 +85,18 @@ export interface IndexDetailsPageTestBed extends TestBed { }; } -export const setup = async ( - httpSetup: HttpSetup, - overridingDependencies: any = {} -): Promise => { +export const setup = async ({ + httpSetup, + dependencies = {}, + initialEntry, +}: { + httpSetup: HttpSetup; + dependencies?: any; + initialEntry?: string; +}): Promise => { const initTestBed = registerTestBed( - WithAppDependencies(IndexDetailsPage, httpSetup, overridingDependencies), - testBedConfig + WithAppDependencies(IndexDetailsPage, httpSetup, dependencies), + getTestBedConfig(initialEntry) ); const testBed = await initTestBed(); const { find, component, exists } = testBed; @@ -105,6 +111,9 @@ export const setup = async ( }); component.update(); }, + noIndexNameMessageIsDisplayed: () => { + return exists('indexDetailsNoIndexNameError'); + }, }; const getHeader = () => { return component.find('[data-test-subj="indexDetailsHeader"] h1').text(); diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx index cc5796f90f3bcc..84b5a2b2af09b8 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx @@ -58,10 +58,13 @@ describe('', () => { httpRequestsMockHelpers.setLoadIndexSettingsResponse(testIndexName, testIndexSettings); await act(async () => { - testBed = await setup(httpSetup, { - url: { - locators: { - get: () => ({ navigate: jest.fn() }), + testBed = await setup({ + httpSetup, + dependencies: { + url: { + locators: { + get: () => ({ navigate: jest.fn() }), + }, }, }, }); @@ -76,7 +79,7 @@ describe('', () => { message: `Data for index ${testIndexName} was not found`, }); await act(async () => { - testBed = await setup(httpSetup); + testBed = await setup({ httpSetup }); }); testBed.component.update(); @@ -92,6 +95,19 @@ describe('', () => { await testBed.actions.errorSection.clickReloadButton(); expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests + 1); }); + + it('renders an error section when no index name is provided', async () => { + // already sent 2 requests while setting up the component + const numberOfRequests = 2; + expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests); + await act(async () => { + testBed = await setup({ httpSetup, initialEntry: '/indices/index_details' }); + }); + testBed.component.update(); + expect(testBed.actions.errorSection.noIndexNameMessageIsDisplayed()).toBe(true); + // no extra http request was sent + expect(httpSetup.get).toHaveBeenCalledTimes(numberOfRequests); + }); }); describe('Stats tab', () => { @@ -139,7 +155,7 @@ describe('', () => { ); await act(async () => { - testBed = await setup(httpSetup); + testBed = await setup({ httpSetup }); }); testBed.component.update(); @@ -149,8 +165,11 @@ describe('', () => { it('hides index stats tab if enableIndexStats===false', async () => { await act(async () => { - testBed = await setup(httpSetup, { - config: { enableIndexStats: false }, + testBed = await setup({ + httpSetup, + dependencies: { + config: { enableIndexStats: false }, + }, }); }); testBed.component.update(); @@ -165,7 +184,7 @@ describe('', () => { message: 'Error', }); await act(async () => { - testBed = await setup(httpSetup); + testBed = await setup({ httpSetup }); }); testBed.component.update(); @@ -214,8 +233,11 @@ describe('', () => { it('hides index stats from detail panels if enableIndexStats===false', async () => { await act(async () => { - testBed = await setup(httpSetup, { - config: { enableIndexStats: false }, + testBed = await setup({ + httpSetup, + dependencies: { + config: { enableIndexStats: false }, + }, }); }); testBed.component.update(); @@ -227,10 +249,13 @@ describe('', () => { describe('extension service summary', () => { it('renders all summaries added to the extension service', async () => { await act(async () => { - testBed = await setup(httpSetup, { - services: { - extensionsService: { - summaries: [() => test, () => test2], + testBed = await setup({ + httpSetup, + dependencies: { + services: { + extensionsService: { + summaries: [() => test, () => test2], + }, }, }, }); @@ -242,10 +267,13 @@ describe('', () => { it(`doesn't render empty panels if the summary renders null`, async () => { await act(async () => { - testBed = await setup(httpSetup, { - services: { - extensionsService: { - summaries: [() => null], + testBed = await setup({ + httpSetup, + dependencies: { + services: { + extensionsService: { + summaries: [() => null], + }, }, }, }); @@ -256,10 +284,13 @@ describe('', () => { it(`doesn't render anything when no summaries added to the extension service`, async () => { await act(async () => { - testBed = await setup(httpSetup, { - services: { - extensionsService: { - summaries: [], + testBed = await setup({ + httpSetup, + dependencies: { + services: { + extensionsService: { + summaries: [], + }, }, }, }); @@ -310,7 +341,7 @@ describe('', () => { message: `Was not able to load mappings`, }); await act(async () => { - testBed = await setup(httpSetup); + testBed = await setup({ httpSetup }); }); testBed.component.update(); @@ -372,7 +403,7 @@ describe('', () => { message: `Was not able to load settings`, }); await act(async () => { - testBed = await setup(httpSetup); + testBed = await setup( { httpSetup }); }); testBed.component.update(); @@ -485,7 +516,7 @@ describe('', () => { }); await act(async () => { - testBed = await setup(httpSetup); + testBed = await setup({ httpSetup }); }); testBed.component.update(); @@ -578,7 +609,7 @@ describe('', () => { }); await act(async () => { - testBed = await setup(httpSetup); + testBed = await setup({ httpSetup }); }); testBed.component.update(); diff --git a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx index 7b2e24ce5cb873..d59aeab60bff0e 100644 --- a/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx +++ b/x-pack/plugins/index_management/public/application/sections/home/index_list/details_page/details_page.tsx @@ -15,6 +15,9 @@ import { EuiPageHeaderProps, EuiPageSection, EuiButton, + EuiPageTemplate, + EuiText, + EuiCode, } from '@elastic/eui'; import { SectionLoading } from '@kbn/es-ui-shared-plugin/public'; @@ -106,15 +109,17 @@ export const DetailsPage: FunctionComponent< return getSelectedTabContent({ tab: indexDetailsSection, index, indexName }); }, [index, indexDetailsSection, indexName]); const fetchIndexDetails = useCallback(async () => { - setIsLoading(true); - try { - const { data, error: loadingError } = await loadIndex(indexName); - setIsLoading(false); - setError(loadingError); - setIndex(data); - } catch (e) { - setIsLoading(false); - setError(e); + if (indexName) { + setIsLoading(true); + try { + const { data, error: loadingError } = await loadIndex(indexName); + setIsLoading(false); + setError(loadingError); + setIndex(data); + } catch (e) { + setIsLoading(false); + setError(e); + } } }, [indexName]); @@ -145,6 +150,34 @@ export const DetailsPage: FunctionComponent< })); }, [indexDetailsSection, onSectionChange, config]); + if (!indexName) { + return ( + + + + } + body={ + + indexName, + }} + /> + + } + /> + ); + } if (isLoading && !index) { return ( From 8eba5d3f2b67f54b9603ba1f157b09f9d1bbc156 Mon Sep 17 00:00:00 2001 From: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Date: Fri, 22 Sep 2023 11:16:01 +0000 Subject: [PATCH 10/10] [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' --- .../index_details_page/index_details_page.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx index 84b5a2b2af09b8..6d9f2bc7daac7b 100644 --- a/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx +++ b/x-pack/plugins/index_management/__jest__/client_integration/index_details_page/index_details_page.test.tsx @@ -403,7 +403,7 @@ describe('', () => { message: `Was not able to load settings`, }); await act(async () => { - testBed = await setup( { httpSetup }); + testBed = await setup({ httpSetup }); }); testBed.component.update();