Skip to content

Commit

Permalink
[App Search] 2 fixes for Result Settings (#97179)
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonStoltz committed Apr 20, 2021
1 parent 7c103bf commit b57abad
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { shallow, ShallowWrapper } from 'enzyme';

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

import { UnsavedChangesPrompt } from '../../../shared/unsaved_changes_prompt';

import { ResultSettings } from './result_settings';
import { ResultSettingsTable } from './result_settings_table';
import { SampleResponse } from './sample_response';
Expand Down Expand Up @@ -110,6 +112,14 @@ describe('ResultSettings', () => {
expect(actions.clearAllFields).toHaveBeenCalled();
});

it('will prevent user from leaving the page if there are unsaved changes', () => {
setMockValues({
...values,
stagedUpdates: true,
});
expect(subject().find(UnsavedChangesPrompt).prop('hasUnsavedChanges')).toBe(true);
});

describe('when there is no schema yet', () => {
let wrapper: ShallowWrapper;
beforeAll(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { SAVE_BUTTON_LABEL } from '../../../shared/constants';
import { FlashMessages } from '../../../shared/flash_messages';
import { SetAppSearchChrome as SetPageChrome } from '../../../shared/kibana_chrome';
import { Loading } from '../../../shared/loading';
import { UnsavedChangesPrompt } from '../../../shared/unsaved_changes_prompt';
import { RESTORE_DEFAULTS_BUTTON_LABEL } from '../../constants';
import { getEngineBreadcrumbs } from '../engine';

Expand All @@ -39,6 +40,11 @@ const CLEAR_BUTTON_LABEL = i18n.translate(
{ defaultMessage: 'Clear all values' }
);

const UNSAVED_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.resultSettings.unsavedChangesMessage',
{ defaultMessage: 'Result Settings have not been saved. Are you sure you want to leave?' }
);

export const ResultSettings: React.FC = () => {
const { dataLoading, schema, stagedUpdates, resultFieldsAtDefaultSettings } = useValues(
ResultSettingsLogic
Expand All @@ -60,6 +66,7 @@ export const ResultSettings: React.FC = () => {
return (
<>
<SetPageChrome trail={getEngineBreadcrumbs([RESULT_SETTINGS_TITLE])} />
<UnsavedChangesPrompt hasUnsavedChanges={stagedUpdates} messageText={UNSAVED_MESSAGE} />
<EuiPageHeader
pageTitle={RESULT_SETTINGS_TITLE}
description={i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,6 @@ describe('SampleResponseLogic', () => {
'An error occured.'
);
});

it('does nothing if an empty object is passed for the resultFields parameter', async () => {
mount();
jest.spyOn(SampleResponseLogic.actions, 'getSearchResultsSuccess');

SampleResponseLogic.actions.getSearchResults('foo', {});

jest.runAllTimers();
await nextTick();

expect(SampleResponseLogic.actions.getSearchResultsSuccess).not.toHaveBeenCalled();
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const SampleResponseLogic = kea<MakeLogicType<SampleResponseValues, Sampl
},
listeners: ({ actions }) => ({
getSearchResults: async ({ query, resultFields }, breakpoint) => {
if (Object.keys(resultFields).length < 1) return;
await breakpoint(250);

const { http } = HttpLogic.values;
Expand Down

0 comments on commit b57abad

Please sign in to comment.