From c0c369547e41818e393ac5ae44565968c1484eab Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Tue, 17 Aug 2021 16:33:54 -0400 Subject: [PATCH] [Workplace Search] Replaces success Flash Messages with Toasts (#108937) (#108962) Co-authored-by: Scotty Bollinger --- .../components/add_source/add_source.tsx | 4 ++-- .../components/add_source/add_source_logic.ts | 4 ++-- .../display_settings/display_settings_logic.test.ts | 4 ++-- .../display_settings/display_settings_logic.ts | 4 ++-- .../components/schema/schema_logic.test.ts | 6 +++--- .../components/schema/schema_logic.ts | 4 ++-- .../views/content_sources/source_logic.test.ts | 7 +++---- .../views/content_sources/source_logic.ts | 9 ++++----- .../views/content_sources/sources_logic.test.ts | 6 +++--- .../views/content_sources/sources_logic.ts | 4 ++-- .../views/groups/group_logic.test.ts | 13 +++++-------- .../workplace_search/views/groups/group_logic.ts | 11 +++++------ .../workplace_search/views/groups/groups_logic.ts | 4 ++-- .../views/role_mappings/role_mappings_logic.ts | 6 +++--- .../views/security/security_logic.ts | 4 ++-- .../views/settings/settings_logic.test.ts | 9 ++------- .../views/settings/settings_logic.ts | 3 +-- 17 files changed, 45 insertions(+), 57 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source.tsx index 98d50c5fb5cea..f575ddb19ebdc 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source.tsx @@ -11,7 +11,7 @@ import { useActions, useValues } from 'kea'; import { i18n } from '@kbn/i18n'; -import { setSuccessMessage } from '../../../../../shared/flash_messages'; +import { flashSuccessToast } from '../../../../../shared/flash_messages'; import { KibanaLogic } from '../../../../../shared/kibana'; import { AppLogic } from '../../../../app_logic'; import { @@ -90,7 +90,7 @@ export const AddSource: React.FC = (props) => { const goToFormSourceCreated = () => { KibanaLogic.values.navigateToUrl(`${getSourcesPath(SOURCES_PATH, isOrganization)}`); - setSuccessMessage(FORM_SOURCE_ADDED_SUCCESS_MESSAGE); + flashSuccessToast(FORM_SOURCE_ADDED_SUCCESS_MESSAGE); }; const header = ; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts index a75e494aa2b1c..0aa7cbcf5f1c7 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/add_source/add_source_logic.ts @@ -14,7 +14,7 @@ import { HttpFetchQuery } from 'src/core/public'; import { flashAPIErrors, - setSuccessMessage, + flashSuccessToast, clearFlashMessages, setErrorMessage, } from '../../../../../shared/flash_messages'; @@ -491,7 +491,7 @@ export const AddSourceLogic = kea { const { http } = mockHttpValues; const { navigateToUrl } = mockKibanaValues; - const { clearFlashMessages, flashAPIErrors, setSuccessMessage } = mockFlashMessageHelpers; + const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers; const { mount } = new LogicMounter(DisplaySettingsLogic); const { searchResultConfig, exampleDocuments } = exampleResult; @@ -110,7 +110,7 @@ describe('DisplaySettingsLogic', () => { serverProps.searchResultConfig ); - expect(setSuccessMessage).toHaveBeenCalled(); + expect(flashSuccessToast).toHaveBeenCalled(); }); it('handles empty color', () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts index 556507d891dcb..28d10b1566b6c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/display_settings/display_settings_logic.ts @@ -11,7 +11,7 @@ import { cloneDeep, isEqual, differenceBy } from 'lodash'; import { DropResult } from '@elastic/eui'; import { - setSuccessMessage, + flashSuccessToast, clearFlashMessages, flashAPIErrors, } from '../../../../../shared/flash_messages'; @@ -405,7 +405,7 @@ export const DisplaySettingsLogic = kea< } }, setServerResponseData: () => { - setSuccessMessage(SUCCESS_MESSAGE); + flashSuccessToast(SUCCESS_MESSAGE); }, toggleFieldEditorModal: () => { clearFlashMessages(); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts index d642900aea169..142e50d52c9db 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.test.ts @@ -43,7 +43,7 @@ describe('SchemaLogic', () => { const { clearFlashMessages, flashAPIErrors, - setSuccessMessage, + flashSuccessToast, setErrorMessage, } = mockFlashMessageHelpers; const { mount } = new LogicMounter(SchemaLogic); @@ -371,7 +371,7 @@ describe('SchemaLogic', () => { } ); await nextTick(); - expect(setSuccessMessage).toHaveBeenCalledWith(SCHEMA_FIELD_ADDED_MESSAGE); + expect(flashSuccessToast).toHaveBeenCalledWith(SCHEMA_FIELD_ADDED_MESSAGE); expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse); }); @@ -430,7 +430,7 @@ describe('SchemaLogic', () => { } ); await nextTick(); - expect(setSuccessMessage).toHaveBeenCalledWith(SCHEMA_UPDATED_MESSAGE); + expect(flashSuccessToast).toHaveBeenCalledWith(SCHEMA_UPDATED_MESSAGE); expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts index f43be974102b2..114d63a3ce142 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/components/schema/schema_logic.ts @@ -13,7 +13,7 @@ import { i18n } from '@kbn/i18n'; import { ADD, UPDATE } from '../../../../../shared/constants/operations'; import { flashAPIErrors, - setSuccessMessage, + flashSuccessToast, setErrorMessage, clearFlashMessages, } from '../../../../../shared/flash_messages'; @@ -346,7 +346,7 @@ export const SchemaLogic = kea>({ body: JSON.stringify({ ...updatedSchema }), }); actions.onSchemaSetSuccess(response); - setSuccessMessage(successMessage); + flashSuccessToast(successMessage); } catch (e) { window.scrollTo(0, 0); if (isAdding) { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts index 81d2803690161..adeddb08dcb79 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.test.ts @@ -29,8 +29,7 @@ describe('SourceLogic', () => { const { clearFlashMessages, flashAPIErrors, - setSuccessMessage, - setQueuedSuccessMessage, + flashSuccessToast, setErrorMessage, } = mockFlashMessageHelpers; const { navigateToUrl } = mockKibanaValues; @@ -79,7 +78,7 @@ describe('SourceLogic', () => { ...contentSource, name: NAME, }); - expect(setSuccessMessage).toHaveBeenCalled(); + expect(flashSuccessToast).toHaveBeenCalled(); }); it('setSearchResults', () => { @@ -391,7 +390,7 @@ describe('SourceLogic', () => { expect(clearFlashMessages).toHaveBeenCalled(); expect(http.delete).toHaveBeenCalledWith('/api/workplace_search/org/sources/123'); await promise; - expect(setQueuedSuccessMessage).toHaveBeenCalled(); + expect(flashSuccessToast).toHaveBeenCalled(); expect(setButtonNotLoadingSpy).toHaveBeenCalled(); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts index 4d145bf798160..6040f319357d9 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/source_logic.ts @@ -12,9 +12,8 @@ import { i18n } from '@kbn/i18n'; import { DEFAULT_META } from '../../../shared/constants'; import { flashAPIErrors, - setSuccessMessage, + flashSuccessToast, setErrorMessage, - setQueuedSuccessMessage, clearFlashMessages, } from '../../../shared/flash_messages'; import { HttpLogic } from '../../../shared/http'; @@ -239,7 +238,8 @@ export const SourceLogic = kea>({ try { const response = await HttpLogic.values.http.delete(route); - setQueuedSuccessMessage( + KibanaLogic.values.navigateToUrl(getSourcesPath(SOURCES_PATH, isOrganization)); + flashSuccessToast( i18n.translate( 'xpack.enterpriseSearch.workplaceSearch.sources.flashMessages.contentSourceRemoved', { @@ -248,7 +248,6 @@ export const SourceLogic = kea>({ } ) ); - KibanaLogic.values.navigateToUrl(getSourcesPath(SOURCES_PATH, isOrganization)); } catch (e) { flashAPIErrors(e); } finally { @@ -256,7 +255,7 @@ export const SourceLogic = kea>({ } }, onUpdateSourceName: (name: string) => { - setSuccessMessage( + flashSuccessToast( i18n.translate( 'xpack.enterpriseSearch.workplaceSearch.sources.flashMessages.contentSourceNameChanged', { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.test.ts index 74d3faca5994b..bc18fade742aa 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.test.ts @@ -23,7 +23,7 @@ import { SourcesLogic, fetchSourceStatuses, POLLING_INTERVAL } from './sources_l describe('SourcesLogic', () => { const { http } = mockHttpValues; - const { flashAPIErrors, setQueuedSuccessMessage } = mockFlashMessageHelpers; + const { flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers; const { mount, unmount } = new LogicMounter(SourcesLogic); const contentSource = contentSources[0]; @@ -126,7 +126,7 @@ describe('SourcesLogic', () => { additionalConfiguration: false, serviceType: 'custom', }); - expect(setQueuedSuccessMessage).toHaveBeenCalledWith('Successfully connected source. '); + expect(flashSuccessToast).toHaveBeenCalledWith('Successfully connected source. '); }); it('unconfigured', () => { @@ -138,7 +138,7 @@ describe('SourcesLogic', () => { additionalConfiguration: true, serviceType: 'custom', }); - expect(setQueuedSuccessMessage).toHaveBeenCalledWith( + expect(flashSuccessToast).toHaveBeenCalledWith( 'Successfully connected source. This source requires additional configuration.' ); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts index 9de2b447619a6..14c79b75dff8e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/content_sources/sources_logic.ts @@ -10,7 +10,7 @@ import { cloneDeep, findIndex } from 'lodash'; import { i18n } from '@kbn/i18n'; -import { flashAPIErrors, setQueuedSuccessMessage } from '../../../shared/flash_messages'; +import { flashAPIErrors, flashSuccessToast } from '../../../shared/flash_messages'; import { HttpLogic } from '../../../shared/http'; import { AppLogic } from '../../app_logic'; import { Connector, ContentSourceDetails, ContentSourceStatus, SourceDataItem } from '../../types'; @@ -222,7 +222,7 @@ export const SourcesLogic = kea>( } ); - setQueuedSuccessMessage( + flashSuccessToast( [ successfullyConnectedMessage, additionalConfiguration ? additionalConfigurationMessage : '', diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts index 2e5a0b3d9b939..6184dada8f111 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.test.ts @@ -27,8 +27,7 @@ describe('GroupLogic', () => { const { clearFlashMessages, flashAPIErrors, - setSuccessMessage, - setQueuedSuccessMessage, + flashSuccessToast, setQueuedErrorMessage, } = mockFlashMessageHelpers; @@ -224,9 +223,7 @@ describe('GroupLogic', () => { await nextTick(); expect(navigateToUrl).toHaveBeenCalledWith(GROUPS_PATH); - expect(setQueuedSuccessMessage).toHaveBeenCalledWith( - 'Group "group" was successfully deleted.' - ); + expect(flashSuccessToast).toHaveBeenCalledWith('Group "group" was successfully deleted.'); }); it('handles error', async () => { @@ -255,7 +252,7 @@ describe('GroupLogic', () => { await nextTick(); expect(onGroupNameChangedSpy).toHaveBeenCalledWith(group); - expect(setSuccessMessage).toHaveBeenCalledWith( + expect(flashSuccessToast).toHaveBeenCalledWith( 'Successfully renamed this group to "group".' ); }); @@ -286,7 +283,7 @@ describe('GroupLogic', () => { await nextTick(); expect(onGroupSourcesSavedSpy).toHaveBeenCalledWith(group); - expect(setSuccessMessage).toHaveBeenCalledWith( + expect(flashSuccessToast).toHaveBeenCalledWith( 'Successfully updated shared content sources.' ); }); @@ -323,7 +320,7 @@ describe('GroupLogic', () => { }); await nextTick(); - expect(setSuccessMessage).toHaveBeenCalledWith( + expect(flashSuccessToast).toHaveBeenCalledWith( 'Successfully updated shared source prioritization.' ); expect(onGroupPrioritiesChangedSpy).toHaveBeenCalledWith(group); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts index 7f3e1d9f0b82d..f8ec50b309725 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/group_logic.ts @@ -13,8 +13,7 @@ import { i18n } from '@kbn/i18n'; import { clearFlashMessages, flashAPIErrors, - setSuccessMessage, - setQueuedSuccessMessage, + flashSuccessToast, setQueuedErrorMessage, } from '../../../shared/flash_messages'; import { HttpLogic } from '../../../shared/http'; @@ -206,7 +205,7 @@ export const GroupLogic = kea>({ } ); - setQueuedSuccessMessage(GROUP_DELETED_MESSAGE); + flashSuccessToast(GROUP_DELETED_MESSAGE); KibanaLogic.values.navigateToUrl(GROUPS_PATH); } catch (e) { flashAPIErrors(e); @@ -231,7 +230,7 @@ export const GroupLogic = kea>({ values: { groupName: response.name }, } ); - setSuccessMessage(GROUP_RENAMED_MESSAGE); + flashSuccessToast(GROUP_RENAMED_MESSAGE); } catch (e) { flashAPIErrors(e); } @@ -256,7 +255,7 @@ export const GroupLogic = kea>({ defaultMessage: 'Successfully updated shared content sources.', } ); - setSuccessMessage(GROUP_SOURCES_UPDATED_MESSAGE); + flashSuccessToast(GROUP_SOURCES_UPDATED_MESSAGE); } catch (e) { flashAPIErrors(e); } @@ -289,7 +288,7 @@ export const GroupLogic = kea>({ } ); - setSuccessMessage(GROUP_PRIORITIZATION_UPDATED_MESSAGE); + flashSuccessToast(GROUP_PRIORITIZATION_UPDATED_MESSAGE); actions.onGroupPrioritiesChanged(response); } catch (e) { flashAPIErrors(e); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts index a036cdda3d68e..36061bc18196b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/groups/groups_logic.ts @@ -15,7 +15,7 @@ import { DEFAULT_META } from '../../../shared/constants'; import { clearFlashMessages, flashAPIErrors, - setSuccessMessage, + flashSuccessToast, } from '../../../shared/flash_messages'; import { HttpLogic } from '../../../shared/http'; import { ContentSource, Group, User } from '../../types'; @@ -328,7 +328,7 @@ export const GroupsLogic = kea>({ } ); - setSuccessMessage(SUCCESS_MESSAGE); + flashSuccessToast(SUCCESS_MESSAGE); actions.setNewGroup(response); } catch (e) { flashAPIErrors(e); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts index 6e7104964cdb7..29b448bc0684a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/role_mappings/role_mappings_logic.ts @@ -10,7 +10,7 @@ import { kea, MakeLogicType } from 'kea'; import { clearFlashMessages, flashAPIErrors, - setSuccessMessage, + flashSuccessToast, } from '../../../shared/flash_messages'; import { HttpLogic } from '../../../shared/http'; import { @@ -397,7 +397,7 @@ export const RoleMappingsLogic = kea> try { const response = await http.patch(route, { body }); actions.setSourceRestrictionsUpdated(response); - setSuccessMessage(SOURCE_RESTRICTIONS_SUCCESS_MESSAGE); + flashSuccessToast(SOURCE_RESTRICTIONS_SUCCESS_MESSAGE); AppLogic.actions.setSourceRestriction(isEnabled); } catch (e) { flashAPIErrors(e); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts index f2887594361c0..e56b1df1ab873 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.test.ts @@ -22,12 +22,7 @@ import { SettingsLogic } from './settings_logic'; describe('SettingsLogic', () => { const { http } = mockHttpValues; const { navigateToUrl } = mockKibanaValues; - const { - clearFlashMessages, - flashAPIErrors, - flashSuccessToast, - setQueuedSuccessMessage, - } = mockFlashMessageHelpers; + const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers; const { mount } = new LogicMounter(SettingsLogic); const ORG_NAME = 'myOrg'; const defaultValues = { @@ -309,7 +304,7 @@ describe('SettingsLogic', () => { await nextTick(); expect(navigateToUrl).toHaveBeenCalledWith('/settings/connectors'); - expect(setQueuedSuccessMessage).toHaveBeenCalled(); + expect(flashSuccessToast).toHaveBeenCalled(); }); it('handles error', async () => { diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts index c32ac9c84fd0a..886f81129ee17 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/settings/settings_logic.ts @@ -11,7 +11,6 @@ import { i18n } from '@kbn/i18n'; import { clearFlashMessages, - setQueuedSuccessMessage, flashSuccessToast, flashAPIErrors, } from '../../../shared/flash_messages'; @@ -290,7 +289,7 @@ export const SettingsLogic = kea> try { await http.delete(route); KibanaLogic.values.navigateToUrl(ORG_SETTINGS_CONNECTORS_PATH); - setQueuedSuccessMessage( + flashSuccessToast( i18n.translate('xpack.enterpriseSearch.workplaceSearch.settings.configRemoved.message', { defaultMessage: 'Successfully removed configuration for {name}.', values: { name },