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

[Enterprise Search] Fix various plugin states when app has error connecting to Enterprise Search #78091

Merged
merged 2 commits into from
Sep 22, 2020
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 @@ -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