Skip to content

Commit 90bd654

Browse files
author
Constance
authored
[Enterprise Search] Create HttpLogic Kea store, add http interceptors, and manage error connecting at top app-level (#75790)
* [Setup] Change error connecting status code to 502 - For clearer error handling * Set up new HttpProvider/Logic Kea store & listeners - This allows us to: - connect() directly to HttpLogic in other Kea logic files that need to make http calls, instead of passing in http manually via args - Set http interceptors & remove them interceptors on unmount within Kea - Share state derived from http (e.g. errorConnecting, readOnlyMode) between both AS & WS (but allow each app to handle that state differently if needed) + Refactors necessary for these changes: - Kea types - add events key, clarify that mount returns an unmount function, fix reducer state type - ReactDOM unmount - remove resetContext({}), was preventing logic from unmounting properly * Update AS & WS to show error connecting component at app level * [WS] Remove errorConnecting logic & http arg from Overview - Since main app is now handling errorConnecting - http can now be connected directly from HttpLogic Kea store, so no need to pass it + minor cleanup in logic_overview.test.ts - remove unneeded unmount(), act(), switch to HttpLogic mock * [AS] Add top-level ErrorConnecting component & remove error logic from EngineOverview * [AS] Clean up/move EngineOverview child components into subfolder - delete old ErrorState component - move LoadingState, EmptyState, and EngineOverviewHeader into subfolders in engine_overview * PR feedback: Update test assertions 404 copy
1 parent 3256992 commit 90bd654

34 files changed

+460
-207
lines changed
Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,19 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import '../../../__mocks__/shallow_usecontext.mock';
7+
import '../../../../__mocks__/shallow_usecontext.mock';
88

99
import React from 'react';
1010
import { shallow } from 'enzyme';
11-
import { EuiEmptyPrompt, EuiButton, EuiLoadingContent } from '@elastic/eui';
12-
import { ErrorStatePrompt } from '../../../shared/error_state';
11+
import { EuiEmptyPrompt, EuiButton } from '@elastic/eui';
1312

14-
jest.mock('../../../shared/telemetry', () => ({
13+
jest.mock('../../../../shared/telemetry', () => ({
1514
sendTelemetry: jest.fn(),
1615
SendAppSearchTelemetry: jest.fn(),
1716
}));
18-
import { sendTelemetry } from '../../../shared/telemetry';
17+
import { sendTelemetry } from '../../../../shared/telemetry';
1918

20-
import { ErrorState, EmptyState, LoadingState } from './';
21-
22-
describe('ErrorState', () => {
23-
it('renders', () => {
24-
const wrapper = shallow(<ErrorState />);
25-
26-
expect(wrapper.find(ErrorStatePrompt)).toHaveLength(1);
27-
});
28-
});
19+
import { EmptyState } from './';
2920

3021
describe('EmptyState', () => {
3122
it('renders', () => {
@@ -44,11 +35,3 @@ describe('EmptyState', () => {
4435
(sendTelemetry as jest.Mock).mockClear();
4536
});
4637
});
47-
48-
describe('LoadingState', () => {
49-
it('renders', () => {
50-
const wrapper = shallow(<LoadingState />);
51-
52-
expect(wrapper.find(EuiLoadingContent)).toHaveLength(2);
53-
});
54-
});
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import React, { useContext } from 'react';
88
import { EuiPageContent, EuiEmptyPrompt, EuiButton } from '@elastic/eui';
99
import { FormattedMessage } from '@kbn/i18n/react';
1010

11-
import { sendTelemetry } from '../../../shared/telemetry';
12-
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome';
13-
import { KibanaContext, IKibanaContext } from '../../../index';
14-
import { CREATE_ENGINES_PATH } from '../../routes';
11+
import { sendTelemetry } from '../../../../shared/telemetry';
12+
import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_chrome';
13+
import { KibanaContext, IKibanaContext } from '../../../../index';
14+
import { CREATE_ENGINES_PATH } from '../../../routes';
1515

16-
import { EngineOverviewHeader } from '../engine_overview_header';
16+
import { EngineOverviewHeader } from './header';
1717

18-
import './empty_states.scss';
18+
import './empty_state.scss';
1919

2020
export const EmptyState: React.FC = () => {
2121
const {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import '../../../__mocks__/shallow_usecontext.mock';
7+
import '../../../../__mocks__/shallow_usecontext.mock';
88

99
import React from 'react';
1010
import { shallow } from 'enzyme';
1111

12-
jest.mock('../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() }));
13-
import { sendTelemetry } from '../../../shared/telemetry';
12+
jest.mock('../../../../shared/telemetry', () => ({ sendTelemetry: jest.fn() }));
13+
import { sendTelemetry } from '../../../../shared/telemetry';
1414

15-
import { EngineOverviewHeader } from '../engine_overview_header';
15+
import { EngineOverviewHeader } from './';
1616

1717
describe('EngineOverviewHeader', () => {
1818
it('renders', () => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import {
1515
} from '@elastic/eui';
1616
import { FormattedMessage } from '@kbn/i18n/react';
1717

18-
import { sendTelemetry } from '../../../shared/telemetry';
19-
import { KibanaContext, IKibanaContext } from '../../../index';
18+
import { sendTelemetry } from '../../../../shared/telemetry';
19+
import { KibanaContext, IKibanaContext } from '../../../../index';
2020

2121
export const EngineOverviewHeader: React.FC = () => {
2222
const {

x-pack/plugins/enterprise_search/public/applications/app_search/components/empty_states/index.ts renamed to x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/components/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
export { EngineOverviewHeader } from './header';
78
export { LoadingState } from './loading_state';
89
export { EmptyState } from './empty_state';
9-
export { ErrorState } from './error_state';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
import React from 'react';
8+
import { shallow } from 'enzyme';
9+
import { EuiLoadingContent } from '@elastic/eui';
10+
11+
import { LoadingState } from './';
12+
13+
describe('LoadingState', () => {
14+
it('renders', () => {
15+
const wrapper = shallow(<LoadingState />);
16+
17+
expect(wrapper.find(EuiLoadingContent)).toHaveLength(2);
18+
});
19+
});
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
import React from 'react';
88
import { EuiPageContent, EuiSpacer, EuiLoadingContent } from '@elastic/eui';
99

10-
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome';
11-
import { EngineOverviewHeader } from '../engine_overview_header';
12-
13-
import './empty_states.scss';
10+
import { SetAppSearchChrome as SetPageChrome } from '../../../../shared/kibana_chrome';
11+
import { EngineOverviewHeader } from './header';
1412

1513
export const LoadingState: React.FC = () => {
1614
return (
1715
<>
1816
<SetPageChrome isRoot />
1917
<EngineOverviewHeader />
20-
<EuiPageContent className="emptyState">
18+
<EuiPageContent paddingSize="l">
2119
<EuiLoadingContent lines={5} />
2220
<EuiSpacer size="xxl" />
2321
<EuiLoadingContent lines={4} />

x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.test.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { shallow, ReactWrapper } from 'enzyme';
1212

1313
import { mountWithAsyncContext, mockKibanaContext } from '../../../__mocks__';
1414

15-
import { LoadingState, EmptyState, ErrorState } from '../empty_states';
15+
import { LoadingState, EmptyState } from './components';
1616
import { EngineTable } from './engine_table';
1717

1818
import { EngineOverview } from './';
@@ -40,16 +40,6 @@ describe('EngineOverview', () => {
4040

4141
expect(wrapper.find(EmptyState)).toHaveLength(1);
4242
});
43-
44-
it('hasErrorConnecting', async () => {
45-
const wrapper = await mountWithAsyncContext(<EngineOverview />, {
46-
http: {
47-
...mockHttp,
48-
get: () => ({ invalidPayload: true }),
49-
},
50-
});
51-
expect(wrapper.find(ErrorState)).toHaveLength(1);
52-
});
5343
});
5444

5545
describe('happy-path states', () => {

x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_overview.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import { KibanaContext, IKibanaContext } from '../../../index';
2222
import EnginesIcon from '../../assets/engine.svg';
2323
import MetaEnginesIcon from '../../assets/meta_engine.svg';
2424

25-
import { LoadingState, EmptyState, ErrorState } from '../empty_states';
26-
import { EngineOverviewHeader } from '../engine_overview_header';
25+
import { EngineOverviewHeader, LoadingState, EmptyState } from './components';
2726
import { EngineTable } from './engine_table';
2827

2928
import './engine_overview.scss';
@@ -42,8 +41,6 @@ export const EngineOverview: React.FC = () => {
4241
const { license } = useContext(LicenseContext) as ILicenseContext;
4342

4443
const [isLoading, setIsLoading] = useState(true);
45-
const [hasErrorConnecting, setHasErrorConnecting] = useState(false);
46-
4744
const [engines, setEngines] = useState([]);
4845
const [enginesPage, setEnginesPage] = useState(1);
4946
const [enginesTotal, setEnginesTotal] = useState(0);
@@ -57,16 +54,12 @@ export const EngineOverview: React.FC = () => {
5754
});
5855
};
5956
const setEnginesData = async (params: IGetEnginesParams, callbacks: ISetEnginesCallbacks) => {
60-
try {
61-
const response = await getEnginesData(params);
57+
const response = await getEnginesData(params);
6258

63-
callbacks.setResults(response.results);
64-
callbacks.setResultsTotal(response.meta.page.total_results);
59+
callbacks.setResults(response.results);
60+
callbacks.setResultsTotal(response.meta.page.total_results);
6561

66-
setIsLoading(false);
67-
} catch (error) {
68-
setHasErrorConnecting(true);
69-
}
62+
setIsLoading(false);
7063
};
7164

7265
useEffect(() => {
@@ -85,7 +78,6 @@ export const EngineOverview: React.FC = () => {
8578
}
8679
}, [license, metaEnginesPage]);
8780

88-
if (hasErrorConnecting) return <ErrorState />;
8981
if (isLoading) return <LoadingState />;
9082
if (!engines.length) return <EmptyState />;
9183

0 commit comments

Comments
 (0)