Skip to content

Commit

Permalink
[8.13] [Search] Fix infinite loop on search index page (#178244) (#17…
Browse files Browse the repository at this point in the history
…8301)

# Backport

This will backport the following commits from `main` to `8.13`:
- [[Search] Fix infinite loop on search index page
(#178244)](#178244)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Sander
Philipse","email":"94373878+sphilipse@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-03-08T12:12:31Z","message":"[Search]
Fix infinite loop on search index page (#178244)\n\n##
Summary\r\n\r\nThis fixes a bug on the search index page where we were
inadvertently\r\nclearing index data every time it was
loaded.","sha":"cc2c364d6061d514415d213b9a7540345e88e13c","branchLabelMapping":{"^v8.14.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:EnterpriseSearch","v8.13.0","v8.14.0"],"title":"[Search]
Fix infinite loop on search index
page","number":178244,"url":"https://github.com/elastic/kibana/pull/178244","mergeCommit":{"message":"[Search]
Fix infinite loop on search index page (#178244)\n\n##
Summary\r\n\r\nThis fixes a bug on the search index page where we were
inadvertently\r\nclearing index data every time it was
loaded.","sha":"cc2c364d6061d514415d213b9a7540345e88e13c"}},"sourceBranch":"main","suggestedTargetBranches":["8.13"],"targetPullRequestStates":[{"branch":"8.13","label":"v8.13.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.14.0","branchLabelMappingKey":"^v8.14.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/178244","number":178244,"mergeCommit":{"message":"[Search]
Fix infinite loop on search index page (#178244)\n\n##
Summary\r\n\r\nThis fixes a bug on the search index page where we were
inadvertently\r\nclearing index data every time it was
loaded.","sha":"cc2c364d6061d514415d213b9a7540345e88e13c"}}]}]
BACKPORT-->

Co-authored-by: Sander Philipse <94373878+sphilipse@users.noreply.github.com>
  • Loading branch information
kibanamachine and sphilipse authored Mar 8, 2024
1 parent 59be28e commit 262a3c7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@
*/

export function stripSearchPrefix(input: string, replacement?: string): string {
return input?.startsWith('search-') ? `${replacement || ''}${input.substring(7)}` : input || '';
return input?.startsWith('search-')
? `${replacement || ''}${input.substring(7)}`
: `${replacement || ''}${input}` || '';
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Status } from '../../../../../common/types/api';
import { ElasticsearchIndexWithIngestion } from '../../../../../common/types/indices';

import { Actions } from '../../../shared/api_logic/create_api_logic';
import { IndexNameLogic } from '../../components/search_index/index_name_logic';

import {
FetchIndexApiParams,
Expand Down Expand Up @@ -56,7 +57,12 @@ export const CachedFetchIndexApiLogic = kea<
},
connect: {
actions: [FetchIndexApiLogic, ['apiSuccess', 'apiError', 'apiReset', 'makeRequest']],
values: [FetchIndexApiLogic, ['data as fetchIndexApiData', 'status']],
values: [
FetchIndexApiLogic,
['data as fetchIndexApiData', 'status'],
IndexNameLogic,
['indexName'],
],
},
events: ({ values }) => ({
beforeUnmount: () => {
Expand Down Expand Up @@ -114,13 +120,6 @@ export const CachedFetchIndexApiLogic = kea<
},
},
],
indexName: [
'',
{
apiReset: () => '',
startPolling: (_, { indexName }) => indexName,
},
],
pollTimeoutId: [
null,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const ConnectorDetail: React.FC = () => {
const { startConnectorPoll } = useActions(ConnectorViewLogic);
useEffect(() => {
startConnectorPoll(connectorId);
}, []);
}, [connectorId]);

const { tabId = ConnectorDetailTabId.OVERVIEW } = useParams<{
tabId?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,37 @@ import { CONNECTOR_DETAIL_PATH, CONNECTOR_DETAIL_TAB_PATH } from '../../routes';

import { IndexNameLogic } from '../search_index/index_name_logic';

import { IndexViewLogic } from '../search_index/index_view_logic';

import { ConnectorDetail } from './connector_detail';
import { ConnectorViewLogic } from './connector_view_logic';

export const ConnectorDetailRouter: React.FC = () => {
useEffect(() => {
const unmountName = IndexNameLogic.mount();
const unmountView = ConnectorViewLogic.mount();
const unmountIndexView = IndexViewLogic.mount();
return () => {
unmountName();
unmountView();
unmountIndexView();
};
}, []);
const { setIndexName } = useActions(IndexNameLogic);
const { connector } = useValues(ConnectorViewLogic);
const { startFetchIndexPoll, stopFetchIndexPoll, resetFetchIndexApi } =
useActions(IndexViewLogic);
const indexName = connector?.index_name || '';
useEffect(() => {
setIndexName(indexName);
if (indexName) {
startFetchIndexPoll(indexName);
} else {
stopFetchIndexPoll();
resetFetchIndexApi();
}
}, [indexName]);

return (
<Routes>
<Route path={CONNECTOR_DETAIL_PATH} exact>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,15 @@ export const ConnectorViewLogic = kea<MakeLogicType<ConnectorViewValues, Connect
],
},
events: ({ actions }) => ({
beforeMount: () => {
actions.fetchConnectorApiReset();
actions.fetchIndexApiReset();
},
beforeUnmount: () => {
actions.fetchConnectorApiReset();
actions.fetchIndexApiReset();
actions.stopConnectorPoll();
actions.fetchConnectorApiReset();
},
}),
listeners: ({ actions, values }) => ({
fetchConnectorApiSuccess: () => {
if (values.indexName) {
actions.fetchIndex({ indexName: values.indexName });
listeners: ({ actions }) => ({
fetchConnectorApiSuccess: (response) => {
if (response.connector?.index_name) {
actions.setIndexName(response.connector.index_name);
}
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ import { BetaBadge } from '../../../../../shared/beta/beta_badge';

import { docLinks } from '../../../../../shared/doc_links';

import { ConnectorViewLogic } from '../../../connector_detail/connector_view_logic';
import { FilteringRulesTable } from '../../../shared/filtering_rules_table/filtering_rules_table';
import { IndexViewLogic } from '../../index_view_logic';

import { ConnectorFilteringLogic } from './connector_filtering_logic';
import { EditSyncRulesFlyout } from './edit_sync_rules_flyout';
import { SyncRulesStateCallouts } from './sync_rules_callouts';

export const ConnectorSyncRules: React.FC = () => {
const { indexName, hasAdvancedFilteringFeature, hasBasicFilteringFeature } =
useValues(IndexViewLogic);
useValues(ConnectorViewLogic);
const { applyDraft, setLocalFilteringRules, setLocalAdvancedSnippet, setIsEditing } =
useActions(ConnectorFilteringLogic);
const { advancedSnippet, draftErrors, draftState, filteringRules, hasDraft, isEditing } =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import React, { useEffect } from 'react';
import { Redirect, useParams } from 'react-router-dom';

import { useActions } from 'kea';
import { useActions, useValues } from 'kea';

import { Routes, Route } from '@kbn/shared-ux-router';

Expand All @@ -19,26 +19,53 @@ import {
SEARCH_INDEX_TAB_PATH,
} from '../../routes';

import { ConnectorViewLogic } from '../connector_detail/connector_view_logic';

import { IndexNameLogic } from './index_name_logic';
import { IndexViewLogic } from './index_view_logic';
import { SearchIndex } from './search_index';

export const SearchIndexRouter: React.FC = () => {
const indexName = decodeURIComponent(useParams<{ indexName: string }>().indexName);
const { setIndexName } = useActions(IndexNameLogic);
const { stopFetchIndexPoll } = useActions(IndexViewLogic);
const { startFetchIndexPoll, stopFetchIndexPoll, resetFetchIndexApi } =
useActions(IndexViewLogic);
const { connector } = useValues(IndexViewLogic);
const { startConnectorPoll, stopConnectorPoll, fetchConnectorApiReset } =
useActions(ConnectorViewLogic);

useEffect(() => {
const unmountName = IndexNameLogic.mount();
const unmountView = IndexViewLogic.mount();
const unmountConnectorView = ConnectorViewLogic.mount();
return () => {
stopFetchIndexPoll();
stopConnectorPoll();
resetFetchIndexApi();
fetchConnectorApiReset();
unmountName();
unmountView();
unmountConnectorView();
};
}, []);

useEffect(() => {
stopConnectorPoll();
fetchConnectorApiReset();
if (connector?.id) {
startConnectorPoll(connector.id);
}
}, [connector?.id]);

useEffect(() => {
stopFetchIndexPoll();
resetFetchIndexApi();
setIndexName(indexName);
if (indexName) {
startFetchIndexPoll(indexName);
} else {
stopFetchIndexPoll();
}
}, [indexName]);

return (
Expand Down

0 comments on commit 262a3c7

Please sign in to comment.