Skip to content

Commit 2b1dd4c

Browse files
authored
chore(search-indexes): only poll search indexes when there is connectivity to the cluster (#4935)
* chore: only poll in online mode * chore: remove .only * chore: remove unnecessary function * chore: refactor, so offline mode is handled in the action * chore: removed unused text / moved logic to the action
1 parent 0ea6a4d commit 2b1dd4c

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {
55
screen,
66
fireEvent,
77
within,
8+
waitFor,
89
} from '@testing-library/react';
910
import { expect } from 'chai';
1011
import sinon from 'sinon';
1112
import userEvent from '@testing-library/user-event';
1213
import type { Document } from 'mongodb';
1314

14-
import { SearchIndexesTable } from './search-indexes-table';
15+
import { POLLING_INTERVAL, SearchIndexesTable } from './search-indexes-table';
1516
import { SearchIndexesStatuses } from '../../modules/search-indexes';
1617
import { searchIndexes as indexes } from './../../../test/fixtures/search-indexes';
1718

@@ -184,4 +185,18 @@ describe('SearchIndexesTable Component', function () {
184185
expect(onEditIndexSpy.callCount).to.equal(1);
185186
});
186187
});
188+
189+
describe('connectivity', function () {
190+
it('does poll the index for changes in online mode', async function () {
191+
const onPollIndexesSpy = sinon.spy();
192+
renderIndexList({ onPollIndexes: onPollIndexesSpy, isWritable: true });
193+
194+
await waitFor(
195+
() => {
196+
expect(onPollIndexesSpy.callCount).to.be.greaterThanOrEqual(1);
197+
},
198+
{ timeout: POLLING_INTERVAL * 2 }
199+
);
200+
});
201+
});
187202
});

packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { IndexesTable } from '../indexes-table';
3131
import IndexActions from './search-index-actions';
3232
import { ZeroGraphic } from './zero-graphic';
3333

34-
const POLLING_INTERVAL = 5000;
34+
export const POLLING_INTERVAL = 5000;
3535

3636
type SearchIndexesTableProps = {
3737
indexes: SearchIndex[];

packages/compass-indexes/src/modules/search-indexes.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { readonlyViewChanged } from './is-readonly-view';
2020

2121
// Importing this to stub showConfirmation
2222
import * as searchIndexesSlice from './search-indexes';
23+
import { writeStateChanged } from './is-writable';
2324

2425
describe('search-indexes module', function () {
2526
let store: ReturnType<typeof setupStore>;
@@ -68,6 +69,18 @@ describe('search-indexes module', function () {
6869
expect(store.getState().searchIndexes.status).to.equal('NOT_READY');
6970
});
7071

72+
it('does nothing if isWritable is false (offline mode)', function () {
73+
store.dispatch(writeStateChanged(false));
74+
75+
expect(store.getState().isWritable).to.equal(false);
76+
expect(getSearchIndexesStub.callCount).to.equal(0);
77+
78+
store.dispatch(fetchSearchIndexes);
79+
80+
expect(getSearchIndexesStub.callCount).to.equal(0);
81+
expect(store.getState().searchIndexes.status).to.equal('NOT_READY');
82+
});
83+
7184
it('does nothing if there is no dataService', function () {
7285
store.getState().dataService = null;
7386
store.dispatch(fetchSearchIndexes);

packages/compass-indexes/src/modules/search-indexes.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,13 @@ const fetchIndexes = (
519519
return async (dispatch, getState) => {
520520
const {
521521
isReadonlyView,
522+
isWritable,
522523
dataService,
523524
namespace,
524525
searchIndexes: { sortColumn, sortOrder, status },
525526
} = getState();
526527

527-
if (isReadonlyView) {
528+
if (isReadonlyView || !isWritable) {
528529
return;
529530
}
530531

0 commit comments

Comments
 (0)