[Enterprise Search] Fix bug in indexing status (#95719)
* 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!
This commit is contained in:
parent
f94a6889bb
commit
73f60e132d
|
@ -27,7 +27,7 @@ describe('IndexingStatus', () => {
|
|||
const props = {
|
||||
percentageComplete: 50,
|
||||
numDocumentsWithErrors: 1,
|
||||
activeReindexJobId: 12,
|
||||
activeReindexJobId: '12abc',
|
||||
viewLinkPath: '/path',
|
||||
statusPath: '/other_path',
|
||||
itemId: '1',
|
||||
|
|
|
@ -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<IIndexingStatusProps> = ({
|
||||
viewLinkPath,
|
||||
statusPath,
|
||||
onComplete,
|
||||
}) => {
|
||||
const { percentageComplete, numDocumentsWithErrors } = useValues(IndexingStatusLogic);
|
||||
export const IndexingStatus: React.FC<IIndexingStatusProps> = (props) => {
|
||||
const { viewLinkPath, statusPath, onComplete } = props;
|
||||
const { percentageComplete, numDocumentsWithErrors } = useValues(IndexingStatusLogic(props));
|
||||
const { fetchIndexingStatus } = useActions(IndexingStatusLogic);
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -32,6 +32,7 @@ interface IndexingStatusValues {
|
|||
let pollingInterval: number;
|
||||
|
||||
export const IndexingStatusLogic = kea<MakeLogicType<IndexingStatusValues, IndexingStatusActions>>({
|
||||
path: ['enterprise_search', 'indexing_status_logic'],
|
||||
actions: {
|
||||
fetchIndexingStatus: ({ statusPath, onComplete }) => ({ statusPath, onComplete }),
|
||||
setIndexingStatus: ({ numDocumentsWithErrors, percentageComplete }) => ({
|
||||
|
@ -39,20 +40,20 @@ export const IndexingStatusLogic = kea<MakeLogicType<IndexingStatusValues, Index
|
|||
percentageComplete,
|
||||
}),
|
||||
},
|
||||
reducers: {
|
||||
reducers: ({ props }) => ({
|
||||
percentageComplete: [
|
||||
100,
|
||||
props.percentageComplete,
|
||||
{
|
||||
setIndexingStatus: (_, { percentageComplete }) => percentageComplete,
|
||||
},
|
||||
],
|
||||
numDocumentsWithErrors: [
|
||||
0,
|
||||
props.numDocumentsWithErrors,
|
||||
{
|
||||
setIndexingStatus: (_, { numDocumentsWithErrors }) => numDocumentsWithErrors,
|
||||
},
|
||||
],
|
||||
},
|
||||
}),
|
||||
listeners: ({ actions }) => ({
|
||||
fetchIndexingStatus: ({ statusPath, onComplete }: IndexingStatusProps) => {
|
||||
const { http } = HttpLogic.values;
|
||||
|
|
Loading…
Reference in a new issue