Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.14] [Search] Fix search index rerendering unnecessarily (#186412) #187558

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect } from 'react';
import React, { useEffect, useMemo } from 'react';

import { useParams } from 'react-router-dom';

Expand All @@ -15,12 +15,15 @@ import { EuiTabbedContent, EuiTabbedContentTab } from '@elastic/eui';

import { i18n } from '@kbn/i18n';

import { ClientConfigType } from '../../../../../common/types';

import { generateEncodedPath } from '../../../shared/encode_path_params';
import { ErrorStatePrompt } from '../../../shared/error_state';
import { HttpLogic } from '../../../shared/http';
import { KibanaLogic } from '../../../shared/kibana';
import { SEARCH_INDEX_PATH, SEARCH_INDEX_TAB_PATH } from '../../routes';

import { ElasticsearchViewIndex } from '../../types';
import { isConnectorIndex, isCrawlerIndex } from '../../utils/indices';
import { ConnectorConfiguration } from '../connector_detail/connector_configuration';
import { EnterpriseSearchContentPageTemplate } from '../layout/page_template';
Expand Down Expand Up @@ -207,20 +210,6 @@ export const SearchIndex: React.FC = () => {
...(hasDefaultIngestPipeline ? [PIPELINES_TAB] : []),
];

const selectedTab = tabs.find((tab) => tab.id === tabId);

const onTabClick = (tab: EuiTabbedContentTab) => {
KibanaLogic.values.navigateToUrl(
generateEncodedPath(
tab.id === SearchIndexTabId.OVERVIEW ? SEARCH_INDEX_PATH : SEARCH_INDEX_TAB_PATH,
{
indexName,
tabId: tab.id,
}
)
);
};

return (
<EnterpriseSearchContentPageTemplate
pageChrome={[...baseBreadcrumbs, indexName]}
Expand All @@ -234,18 +223,56 @@ export const SearchIndex: React.FC = () => {
rightSideItems: getHeaderActions(index),
}}
>
{isCrawlerIndex(index) && !index.connector ? (
<NoConnectorRecord />
) : isCrawlerIndex(index) && (Boolean(errorConnectingMessage) || !config.host) ? (
<ErrorStatePrompt />
) : (
<>
{indexName === index?.name && (
<EuiTabbedContent tabs={tabs} selectedTab={selectedTab} onTabClick={onTabClick} />
)}
{isCrawlerIndex(index) && <CrawlCustomSettingsFlyout />}
</>
)}
<Content
index={index}
errorConnectingMessage={errorConnectingMessage}
config={config}
tabs={tabs}
tabId={tabId}
/>
</EnterpriseSearchContentPageTemplate>
);
};

interface ContentProps {
config?: ClientConfigType;
errorConnectingMessage: string;
index?: ElasticsearchViewIndex;
tabId?: string;
tabs: EuiTabbedContentTab[];
}

const Content: React.FC<ContentProps> = ({
config,
errorConnectingMessage,
index,
tabs,
tabId,
}) => {
const selectedTab = useMemo(() => tabs.find((tab) => tab.id === tabId), [tabId]);

const onTabClick = (tab: EuiTabbedContentTab) => {
KibanaLogic.values.navigateToUrl(
generateEncodedPath(
tab.id === SearchIndexTabId.OVERVIEW ? SEARCH_INDEX_PATH : SEARCH_INDEX_TAB_PATH,
{
indexName: index?.name || '',
tabId: tab.id,
}
)
);
};

if (isCrawlerIndex(index) && !index.connector) {
return <NoConnectorRecord />;
}
if (isCrawlerIndex(index) && (Boolean(errorConnectingMessage) || !config?.host)) {
return <ErrorStatePrompt />;
}
return (
<>
<EuiTabbedContent tabs={tabs} selectedTab={selectedTab} onTabClick={onTabClick} />
{isCrawlerIndex(index) && <CrawlCustomSettingsFlyout />}
</>
);
};
Loading