From b57abad9dc398fb64e0ea6e746892ddc0761fa6b Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Tue, 20 Apr 2021 08:12:53 -0400 Subject: [PATCH] [App Search] 2 fixes for Result Settings (#97179) --- .../result_settings/result_settings.test.tsx | 10 ++++++++++ .../components/result_settings/result_settings.tsx | 7 +++++++ .../sample_response/sample_response_logic.test.ts | 12 ------------ .../sample_response/sample_response_logic.ts | 1 - 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.test.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.test.tsx index e5a901f8d07790..70bc49421a4f1f 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.test.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.test.tsx @@ -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'; @@ -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(() => { diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.tsx b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.tsx index 285d8fef357703..bea5bcc548fab5 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/result_settings.tsx @@ -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'; @@ -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 @@ -60,6 +66,7 @@ export const ResultSettings: React.FC = () => { return ( <> + { '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(); - }); }); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts index 808a7ec9c65dce..c64cb3465b3117 100644 --- a/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/app_search/components/result_settings/sample_response/sample_response_logic.ts @@ -63,7 +63,6 @@ export const SampleResponseLogic = kea ({ getSearchResults: async ({ query, resultFields }, breakpoint) => { - if (Object.keys(resultFields).length < 1) return; await breakpoint(250); const { http } = HttpLogic.values;