Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.15] [App Search] Continue polling empty engines even when they have a schema (#112915) #113146

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { DOCUMENTS_TITLE } from './constants';
import { SearchExperience } from './search_experience';

export const Documents: React.FC = () => {
const { isMetaEngine, isEngineEmpty } = useValues(EngineLogic);
const { isMetaEngine, hasNoDocuments } = useValues(EngineLogic);
const { myRole } = useValues(AppLogic);

return (
Expand All @@ -32,7 +32,7 @@ export const Documents: React.FC = () => {
rightSideItems:
myRole.canManageEngineDocuments && !isMetaEngine ? [<DocumentCreationButton />] : [],
}}
isEmptyState={isEngineEmpty}
isEmptyState={hasNoDocuments}
emptyState={<EmptyState />}
>
{isMetaEngine && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ describe('EngineLogic', () => {
dataLoading: true,
engine: {},
engineName: '',
isEngineEmpty: true,
isEngineSchemaEmpty: true,
hasNoDocuments: true,
hasEmptySchema: true,
isMetaEngine: false,
isSampleEngine: false,
hasSchemaErrors: false,
Expand All @@ -64,8 +64,8 @@ describe('EngineLogic', () => {
const DEFAULT_VALUES_WITH_ENGINE = {
...DEFAULT_VALUES,
engine: mockEngineData,
isEngineEmpty: false,
isEngineSchemaEmpty: false,
hasNoDocuments: false,
hasEmptySchema: false,
};

beforeEach(() => {
Expand Down Expand Up @@ -255,8 +255,8 @@ describe('EngineLogic', () => {
expect(EngineLogic.actions.onPollStart).toHaveBeenCalled();
});

it('polls for engine data if the current engine is empty', () => {
mount({ engine: {} });
it('polls for engine data if the current engine has no documents', () => {
mount({ engine: { ...mockEngineData, document_count: 0 } });
jest.spyOn(EngineLogic.actions, 'initializeEngine');

EngineLogic.actions.pollEmptyEngine();
Expand All @@ -267,8 +267,8 @@ describe('EngineLogic', () => {
expect(EngineLogic.actions.initializeEngine).toHaveBeenCalledTimes(2);
});

it('cancels the poll if the current engine changed from empty to non-empty', () => {
mount({ engine: mockEngineData });
it('cancels the poll if the current engine has documents', () => {
mount({ engine: { ...mockEngineData, document_count: 1 } });
jest.spyOn(EngineLogic.actions, 'stopPolling');
jest.spyOn(EngineLogic.actions, 'initializeEngine');

Expand Down Expand Up @@ -312,15 +312,15 @@ describe('EngineLogic', () => {
});

describe('selectors', () => {
describe('isEngineEmpty', () => {
describe('hasNoDocuments', () => {
it('returns true if the engine contains no documents', () => {
const engine = { ...mockEngineData, document_count: 0 };
mount({ engine });

expect(EngineLogic.values).toEqual({
...DEFAULT_VALUES_WITH_ENGINE,
engine,
isEngineEmpty: true,
hasNoDocuments: true,
});
});

Expand All @@ -329,20 +329,20 @@ describe('EngineLogic', () => {

expect(EngineLogic.values).toEqual({
...DEFAULT_VALUES,
isEngineEmpty: true,
hasNoDocuments: true,
});
});
});

describe('isEngineSchemaEmpty', () => {
describe('hasEmptySchema', () => {
it('returns true if the engine schema contains no fields', () => {
const engine = { ...mockEngineData, schema: {} };
mount({ engine });

expect(EngineLogic.values).toEqual({
...DEFAULT_VALUES_WITH_ENGINE,
engine,
isEngineSchemaEmpty: true,
hasEmptySchema: true,
});
});

Expand All @@ -351,7 +351,7 @@ describe('EngineLogic', () => {

expect(EngineLogic.values).toEqual({
...DEFAULT_VALUES,
isEngineSchemaEmpty: true,
hasEmptySchema: true,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ interface EngineValues {
dataLoading: boolean;
engine: Partial<EngineDetails>;
engineName: string;
isEngineEmpty: boolean;
isEngineSchemaEmpty: boolean;
hasNoDocuments: boolean;
hasEmptySchema: boolean;
isMetaEngine: boolean;
isSampleEngine: boolean;
hasSchemaErrors: boolean;
Expand Down Expand Up @@ -94,8 +94,8 @@ export const EngineLogic = kea<MakeLogicType<EngineValues, EngineActions>>({
],
},
selectors: ({ selectors }) => ({
isEngineEmpty: [() => [selectors.engine], (engine) => !engine.document_count],
isEngineSchemaEmpty: [
hasNoDocuments: [() => [selectors.engine], (engine) => !engine.document_count],
hasEmptySchema: [
() => [selectors.engine],
(engine) => Object.keys(engine.schema || {}).length === 0,
],
Expand Down Expand Up @@ -149,7 +149,7 @@ export const EngineLogic = kea<MakeLogicType<EngineValues, EngineActions>>({
if (values.intervalId) return; // Ensure we only have one poll at a time

const id = window.setInterval(() => {
if (values.isEngineEmpty && values.isEngineSchemaEmpty) {
if (values.hasNoDocuments) {
actions.initializeEngine(); // Re-fetch engine data when engine is empty
} else {
actions.stopPolling();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('EngineOverview', () => {
const values = {
dataLoading: false,
myRole: {},
isEngineEmpty: true,
hasNoDocuments: true,
isMetaEngine: false,
};

Expand All @@ -40,7 +40,7 @@ describe('EngineOverview', () => {

describe('EngineOverviewMetrics', () => {
it('renders when the engine has documents', () => {
setMockValues({ ...values, isEngineEmpty: false });
setMockValues({ ...values, hasNoDocuments: false });
const wrapper = shallow(<EngineOverview />);
expect(wrapper.find(EngineOverviewMetrics)).toHaveLength(1);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export const EngineOverview: React.FC = () => {
const {
myRole: { canManageEngineDocuments, canViewEngineCredentials },
} = useValues(AppLogic);
const { isEngineEmpty, isMetaEngine } = useValues(EngineLogic);
const { hasNoDocuments, isMetaEngine } = useValues(EngineLogic);

const canAddDocuments = canManageEngineDocuments && canViewEngineCredentials;
const showEngineOverview = !isEngineEmpty || !canAddDocuments || isMetaEngine;
const showEngineOverview = !hasNoDocuments || !canAddDocuments || isMetaEngine;

return showEngineOverview ? <EngineOverviewMetrics /> : <EmptyEngineOverview />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { SearchUILogic } from './search_ui_logic';

export const SearchUI: React.FC = () => {
const { loadFieldData } = useActions(SearchUILogic);
const { isEngineSchemaEmpty } = useValues(EngineLogic);
const { hasEmptySchema } = useValues(EngineLogic);

useEffect(() => {
loadFieldData();
Expand All @@ -34,7 +34,7 @@ export const SearchUI: React.FC = () => {
<AppSearchPageTemplate
pageChrome={getEngineBreadcrumbs([SEARCH_UI_TITLE])}
pageHeader={{ pageTitle: SEARCH_UI_TITLE }}
isEmptyState={isEngineSchemaEmpty}
isEmptyState={hasEmptySchema}
emptyState={<EmptyState />}
>
<EuiFlexGroup alignItems="flexStart">
Expand Down