From 73f60e132d9967cf77dd1932995c73f7cd95058a Mon Sep 17 00:00:00 2001 From: Scotty Bollinger Date: Mon, 29 Mar 2021 19:59:21 -0500 Subject: [PATCH] [Enterprise Search] Fix bug in indexing status (#95719) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add interface The component was already passing the props the logic file needed, they just aren’t listed in the interface * Pass props to logic file Also destructures from props to prevent collision with the local logic values that are repopulated when data is fetched. * Update logic file to use props for default values * Fix test and use spy * Remove resetContext No longer needed! --- .../shared/indexing_status/indexing_status.test.tsx | 2 +- .../shared/indexing_status/indexing_status.tsx | 11 ++++------- .../indexing_status/indexing_status_logic.test.ts | 9 +++++---- .../shared/indexing_status/indexing_status_logic.ts | 9 +++++---- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.test.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.test.tsx index 44bd8b78320d..1ef522c0c0de 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.test.tsx @@ -27,7 +27,7 @@ describe('IndexingStatus', () => { const props = { percentageComplete: 50, numDocumentsWithErrors: 1, - activeReindexJobId: 12, + activeReindexJobId: '12abc', viewLinkPath: '/path', statusPath: '/other_path', itemId: '1', diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.tsx b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.tsx index ee0557e15396..bd3eacacb04e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status.tsx @@ -17,7 +17,7 @@ import { IndexingStatusContent } from './indexing_status_content'; import { IndexingStatusErrors } from './indexing_status_errors'; import { IndexingStatusLogic } from './indexing_status_logic'; -export interface IIndexingStatusProps { +export interface IIndexingStatusProps extends IIndexingStatus { viewLinkPath: string; itemId: string; statusPath: string; @@ -26,12 +26,9 @@ export interface IIndexingStatusProps { setGlobalIndexingStatus?(activeReindexJob: IIndexingStatus): void; } -export const IndexingStatus: React.FC = ({ - viewLinkPath, - statusPath, - onComplete, -}) => { - const { percentageComplete, numDocumentsWithErrors } = useValues(IndexingStatusLogic); +export const IndexingStatus: React.FC = (props) => { + const { viewLinkPath, statusPath, onComplete } = props; + const { percentageComplete, numDocumentsWithErrors } = useValues(IndexingStatusLogic(props)); const { fetchIndexingStatus } = useActions(IndexingStatusLogic); useEffect(() => { diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts index 679d04b41498..468aeacf9e11 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.test.ts @@ -12,9 +12,9 @@ import { nextTick } from '@kbn/test/jest'; import { IndexingStatusLogic } from './indexing_status_logic'; describe('IndexingStatusLogic', () => { - const { mount, unmount } = new LogicMounter(IndexingStatusLogic); const { http } = mockHttpValues; const { flashAPIErrors } = mockFlashMessageHelpers; + const { mount, unmount } = new LogicMounter(IndexingStatusLogic); const mockStatusResponse = { percentageComplete: 50, @@ -24,7 +24,7 @@ describe('IndexingStatusLogic', () => { beforeEach(() => { jest.clearAllMocks(); - mount(); + mount({}, { percentageComplete: 100, numDocumentsWithErrors: 0 }); }); it('has expected default values', () => { @@ -51,6 +51,7 @@ describe('IndexingStatusLogic', () => { jest.useFakeTimers(); const statusPath = '/api/workplace_search/path/123'; const onComplete = jest.fn(); + const clearIntervalSpy = jest.spyOn(global, 'clearInterval'); const TIMEOUT = 3000; it('calls API and sets values', async () => { @@ -84,13 +85,13 @@ describe('IndexingStatusLogic', () => { await nextTick(); - expect(clearInterval).toHaveBeenCalled(); + expect(clearIntervalSpy).toHaveBeenCalled(); expect(onComplete).toHaveBeenCalledWith(mockStatusResponse.numDocumentsWithErrors); }); it('handles unmounting', async () => { unmount(); - expect(clearInterval).toHaveBeenCalled(); + expect(clearIntervalSpy).toHaveBeenCalled(); }); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.ts index a436b669bcbe..a5f3f7ad3d06 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/indexing_status/indexing_status_logic.ts @@ -32,6 +32,7 @@ interface IndexingStatusValues { let pollingInterval: number; export const IndexingStatusLogic = kea>({ + path: ['enterprise_search', 'indexing_status_logic'], actions: { fetchIndexingStatus: ({ statusPath, onComplete }) => ({ statusPath, onComplete }), setIndexingStatus: ({ numDocumentsWithErrors, percentageComplete }) => ({ @@ -39,20 +40,20 @@ export const IndexingStatusLogic = kea ({ percentageComplete: [ - 100, + props.percentageComplete, { setIndexingStatus: (_, { percentageComplete }) => percentageComplete, }, ], numDocumentsWithErrors: [ - 0, + props.numDocumentsWithErrors, { setIndexingStatus: (_, { numDocumentsWithErrors }) => numDocumentsWithErrors, }, ], - }, + }), listeners: ({ actions }) => ({ fetchIndexingStatus: ({ statusPath, onComplete }: IndexingStatusProps) => { const { http } = HttpLogic.values;