Skip to content

Commit

Permalink
[Enterprise Search] Fix various plugin states when app has error conn…
Browse files Browse the repository at this point in the history
…ecting to Enterprise Search (#78091)

* Display error connecting prompt on Overview page instead of blank page

* Fix App Search and Workplace Search to not crash during error connecting
- due to obj type errors
  • Loading branch information
Constance authored and cee-chen committed Sep 22, 2020
1 parent 44e75ba commit 140f7d7
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ describe('AppLogic', () => {
}),
});
});

it('gracefully handles missing initial data', () => {
AppLogic.actions.initializeAppData({});

expect(AppLogic.values).toEqual({
...DEFAULT_VALUES,
hasInitialized: true,
});
});
});

describe('setOnboardingComplete()', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
account: [
{},
{
initializeAppData: (_, { appSearch: account }) => account,
initializeAppData: (_, { appSearch: account }) => account || {},
setOnboardingComplete: (account) => ({
...account,
onboardingComplete: true,
Expand All @@ -49,7 +49,7 @@ export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
configuredLimits: [
{},
{
initializeAppData: (_, { configuredLimits }) => configuredLimits.appSearch,
initializeAppData: (_, { configuredLimits }) => configuredLimits?.appSearch || {},
},
],
ilmEnabled: [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { shallow } from 'enzyme';

import { ErrorStatePrompt } from '../../../shared/error_state';
import { ErrorConnecting } from './';

describe('ErrorConnecting', () => {
it('renders', () => {
const wrapper = shallow(<ErrorConnecting />);

expect(wrapper.find(ErrorStatePrompt)).toHaveLength(1);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import { EuiPage, EuiPageContent } from '@elastic/eui';

import { ErrorStatePrompt } from '../../../shared/error_state';

export const ErrorConnecting: React.FC = () => (
<EuiPage restrictWidth>
<EuiPageContent>
<ErrorStatePrompt />
</EuiPageContent>
</EuiPage>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export { ErrorConnecting } from './error_connecting';
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@

import React from 'react';
import { shallow } from 'enzyme';

import { EuiPage } from '@elastic/eui';

import '../__mocks__/kea.mock';
import { useValues } from 'kea';

import { EnterpriseSearch } from './';
import { ErrorConnecting } from './components/error_connecting';
import { ProductCard } from './components/product_card';

describe('EnterpriseSearch', () => {
beforeEach(() => {
(useValues as jest.Mock).mockReturnValue({ errorConnecting: false });
});

it('renders the overview page and product cards', () => {
const wrapper = shallow(
<EnterpriseSearch access={{ hasAppSearchAccess: true, hasWorkplaceSearchAccess: true }} />
Expand All @@ -22,6 +29,14 @@ describe('EnterpriseSearch', () => {
expect(wrapper.find(ProductCard)).toHaveLength(2);
});

it('renders the error connecting prompt', () => {
(useValues as jest.Mock).mockReturnValueOnce({ errorConnecting: true });
const wrapper = shallow(<EnterpriseSearch />);

expect(wrapper.find(ErrorConnecting)).toHaveLength(1);
expect(wrapper.find(EuiPage)).toHaveLength(0);
});

describe('access checks', () => {
it('does not render the App Search card if the user does not have access to AS', () => {
const wrapper = shallow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import React from 'react';
import { useValues } from 'kea';
import {
EuiPage,
EuiPageBody,
Expand All @@ -21,19 +22,24 @@ import { i18n } from '@kbn/i18n';
import { IInitialAppData } from '../../../common/types';
import { APP_SEARCH_PLUGIN, WORKPLACE_SEARCH_PLUGIN } from '../../../common/constants';

import { HttpLogic } from '../shared/http';
import { SetEnterpriseSearchChrome as SetPageChrome } from '../shared/kibana_chrome';
import { SendEnterpriseSearchTelemetry as SendTelemetry } from '../shared/telemetry';

import { ErrorConnecting } from './components/error_connecting';
import { ProductCard } from './components/product_card';

import AppSearchImage from './assets/app_search.png';
import WorkplaceSearchImage from './assets/workplace_search.png';
import './index.scss';

export const EnterpriseSearch: React.FC<IInitialAppData> = ({ access = {} }) => {
const { errorConnecting } = useValues(HttpLogic);
const { hasAppSearchAccess, hasWorkplaceSearchAccess } = access;

return (
return errorConnecting ? (
<ErrorConnecting />
) : (
<EuiPage restrictWidth className="enterpriseSearchOverview">
<SetPageChrome isRoot />
<SendTelemetry action="viewed" metric="overview" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,15 @@ describe('AppLogic', () => {

expect(AppLogic.values).toEqual(expectedLogicValues);
});

it('gracefully handles missing initial data', () => {
AppLogic.actions.initializeAppData({});

expect(AppLogic.values).toEqual({
...DEFAULT_VALUES,
hasInitialized: true,
isFederatedAuth: false,
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface IAppActions {
initializeAppData(props: IInitialAppData): IInitialAppData;
}

const emptyOrg = {} as IOrganization;
const emptyAccount = {} as IAccount;

export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
path: ['enterprise_search', 'workplace_search', 'app_logic'],
actions: {
Expand All @@ -43,15 +46,15 @@ export const AppLogic = kea<MakeLogicType<IAppValues, IAppActions>>({
},
],
organization: [
{} as IOrganization,
emptyOrg,
{
initializeAppData: (_, { workplaceSearch }) => workplaceSearch!.organization,
initializeAppData: (_, { workplaceSearch }) => workplaceSearch?.organization || emptyOrg,
},
],
account: [
{} as IAccount,
emptyAccount,
{
initializeAppData: (_, { workplaceSearch }) => workplaceSearch!.account,
initializeAppData: (_, { workplaceSearch }) => workplaceSearch?.account || emptyAccount,
},
],
},
Expand Down

0 comments on commit 140f7d7

Please sign in to comment.