Skip to content

Commit

Permalink
Fix polling issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sphilipse committed Mar 8, 2024
1 parent aeb7119 commit 8df29f9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 14 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 @@ -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 @@ -102,18 +102,15 @@ export const ConnectorViewLogic = kea<MakeLogicType<ConnectorViewValues, Connect
],
},
events: ({ actions }) => ({
beforeMount: () => {
actions.fetchConnectorApiReset();
},
beforeUnmount: () => {
actions.fetchConnectorApiReset();
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 8df29f9

Please sign in to comment.