Skip to content

Commit

Permalink
Added an empty message
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonStoltz committed Feb 24, 2021
1 parent d67a163 commit 3874304
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jest.mock('../engine', () => ({

import React from 'react';

import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';

import { EuiPageHeader } from '@elastic/eui';
import { EuiEmptyPrompt, EuiPageHeader } from '@elastic/eui';

import { RelevanceTuning } from './relevance_tuning';
import { RelevanceTuningForm } from './relevance_tuning_form';
Expand Down Expand Up @@ -78,15 +78,36 @@ describe('RelevanceTuning', () => {
expect(actions.resetSearchSettings).toHaveBeenCalled();
});

it('will not render buttons if the engine has no schema', () => {
// An eninge would have no schema if it is newly created, and no documents have been indexed
// yet.
setMockValues({
...values,
engineHasSchemaFields: false,
describe('when the engine has no schema', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
// An eninge would have no schema if it is newly created, and no documents have been indexed
// yet.
setMockValues({
...values,
engineHasSchemaFields: false,
});
wrapper = subject();
});

it('will not render buttons if the engine has no schema', () => {
setMockValues({
...values,
engineHasSchemaFields: false,
});
const buttons = wrapper.find(EuiPageHeader).prop('rightSideItems') as React.ReactElement[];
expect(buttons.length).toBe(0);
});

it('will render an empty message', () => {
setMockValues({
...values,
engineHasSchemaFields: false,
});
expect(wrapper.find(EuiEmptyPrompt).exists()).toBe(true);
expect(wrapper.find(RelevanceTuningForm).exists()).toBe(false);
});
const buttons = subject().find(EuiPageHeader).prop('rightSideItems') as React.ReactElement[];
expect(buttons.length).toBe(0);
});

it('shows a message when there are invalid boosts', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
EuiCallOut,
EuiText,
EuiLink,
EuiEmptyPrompt,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
Expand All @@ -28,7 +29,7 @@ import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chro
import { EuiLinkTo } from '../../../shared/react_router_helpers';
import { UnsavedChangesPrompt } from '../../../shared/unsaved_changes_prompt';

import { ENGINE_SCHEMA_PATH } from '../../routes';
import { DOCS_PREFIX, ENGINE_SCHEMA_PATH } from '../../routes';
import { EngineLogic, generateEnginePath } from '../engine';

import { RELEVANCE_TUNING_TITLE } from './constants';
Expand Down Expand Up @@ -190,12 +191,48 @@ export const RelevanceTuning: React.FC<Props> = ({ engineBreadcrumb }) => {
</EuiCallOut>
)}
<EuiSpacer />
<EuiFlexGroup>
<EuiFlexItem>
<RelevanceTuningForm />
</EuiFlexItem>
<EuiFlexItem />
</EuiFlexGroup>
{engineHasSchemaFields ? (
<EuiFlexGroup>
<EuiFlexItem>
<RelevanceTuningForm />
</EuiFlexItem>
<EuiFlexItem />
</EuiFlexGroup>
) : (
<EuiEmptyPrompt
title={
<h2>
{i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.emptyErrorMessageTitle',
{
defaultMessage: 'Tuning requires schema fields',
}
)}
</h2>
}
body={i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.emptyErrorMessage',
{
defaultMessage: 'Index documents to tune relevance.',
}
)}
actions={
<EuiButton
size="s"
color="primary"
href={`${DOCS_PREFIX}/relevance-tuning-guide.html`}
fill
>
{i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.relevanceTuning.emptyButtonLabel',
{
defaultMessage: 'Read the relevance tuning guide',
}
)}
</EuiButton>
}
/>
)}
</>
);
};

0 comments on commit 3874304

Please sign in to comment.