Skip to content

Commit

Permalink
[Workplace Search] Replaces success Flash Messages with Toasts (#108937)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottybollinger authored and kibanamachine committed Aug 17, 2021
1 parent 32e101a commit 6b009c2
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -90,7 +90,7 @@ export const AddSource: React.FC<AddSourceProps> = (props) => {

const goToFormSourceCreated = () => {
KibanaLogic.values.navigateToUrl(`${getSourcesPath(SOURCES_PATH, isOrganization)}`);
setSuccessMessage(FORM_SOURCE_ADDED_SUCCESS_MESSAGE);
flashSuccessToast(FORM_SOURCE_ADDED_SUCCESS_MESSAGE);
};

const header = <AddSourceHeader name={name} serviceType={serviceType} categories={categories} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { HttpFetchQuery } from 'src/core/public';

import {
flashAPIErrors,
setSuccessMessage,
flashSuccessToast,
clearFlashMessages,
setErrorMessage,
} from '../../../../../shared/flash_messages';
Expand Down Expand Up @@ -491,7 +491,7 @@ export const AddSourceLogic = kea<MakeLogicType<AddSourceValues, AddSourceAction
});
if (successCallback) successCallback();
if (isUpdating) {
setSuccessMessage(
flashSuccessToast(
i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.sources.flashMessages.contentSourceConfigUpdated',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { DisplaySettingsLogic, defaultSearchResultConfig } from './display_setti
describe('DisplaySettingsLogic', () => {
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;
Expand Down Expand Up @@ -110,7 +110,7 @@ describe('DisplaySettingsLogic', () => {
serverProps.searchResultConfig
);

expect(setSuccessMessage).toHaveBeenCalled();
expect(flashSuccessToast).toHaveBeenCalled();
});

it('handles empty color', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { cloneDeep, isEqual, differenceBy } from 'lodash';
import { DropResult } from '@elastic/eui';

import {
setSuccessMessage,
flashSuccessToast,
clearFlashMessages,
flashAPIErrors,
} from '../../../../../shared/flash_messages';
Expand Down Expand Up @@ -405,7 +405,7 @@ export const DisplaySettingsLogic = kea<
}
},
setServerResponseData: () => {
setSuccessMessage(SUCCESS_MESSAGE);
flashSuccessToast(SUCCESS_MESSAGE);
},
toggleFieldEditorModal: () => {
clearFlashMessages();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('SchemaLogic', () => {
const {
clearFlashMessages,
flashAPIErrors,
setSuccessMessage,
flashSuccessToast,
setErrorMessage,
} = mockFlashMessageHelpers;
const { mount } = new LogicMounter(SchemaLogic);
Expand Down Expand Up @@ -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);
});

Expand Down Expand Up @@ -430,7 +430,7 @@ describe('SchemaLogic', () => {
}
);
await nextTick();
expect(setSuccessMessage).toHaveBeenCalledWith(SCHEMA_UPDATED_MESSAGE);
expect(flashSuccessToast).toHaveBeenCalledWith(SCHEMA_UPDATED_MESSAGE);
expect(onSchemaSetSuccessSpy).toHaveBeenCalledWith(serverResponse);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -346,7 +346,7 @@ export const SchemaLogic = kea<MakeLogicType<SchemaValues, SchemaActions>>({
body: JSON.stringify({ ...updatedSchema }),
});
actions.onSchemaSetSuccess(response);
setSuccessMessage(successMessage);
flashSuccessToast(successMessage);
} catch (e) {
window.scrollTo(0, 0);
if (isAdding) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ describe('SourceLogic', () => {
const {
clearFlashMessages,
flashAPIErrors,
setSuccessMessage,
setQueuedSuccessMessage,
flashSuccessToast,
setErrorMessage,
} = mockFlashMessageHelpers;
const { navigateToUrl } = mockKibanaValues;
Expand Down Expand Up @@ -79,7 +78,7 @@ describe('SourceLogic', () => {
...contentSource,
name: NAME,
});
expect(setSuccessMessage).toHaveBeenCalled();
expect(flashSuccessToast).toHaveBeenCalled();
});

it('setSearchResults', () => {
Expand Down Expand Up @@ -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();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -239,7 +238,8 @@ export const SourceLogic = kea<MakeLogicType<SourceValues, SourceActions>>({

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',
{
Expand All @@ -248,15 +248,14 @@ export const SourceLogic = kea<MakeLogicType<SourceValues, SourceActions>>({
}
)
);
KibanaLogic.values.navigateToUrl(getSourcesPath(SOURCES_PATH, isOrganization));
} catch (e) {
flashAPIErrors(e);
} finally {
actions.setButtonNotLoading();
}
},
onUpdateSourceName: (name: string) => {
setSuccessMessage(
flashSuccessToast(
i18n.translate(
'xpack.enterpriseSearch.workplaceSearch.sources.flashMessages.contentSourceNameChanged',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -126,7 +126,7 @@ describe('SourcesLogic', () => {
additionalConfiguration: false,
serviceType: 'custom',
});
expect(setQueuedSuccessMessage).toHaveBeenCalledWith('Successfully connected source. ');
expect(flashSuccessToast).toHaveBeenCalledWith('Successfully connected source. ');
});

it('unconfigured', () => {
Expand All @@ -138,7 +138,7 @@ describe('SourcesLogic', () => {
additionalConfiguration: true,
serviceType: 'custom',
});
expect(setQueuedSuccessMessage).toHaveBeenCalledWith(
expect(flashSuccessToast).toHaveBeenCalledWith(
'Successfully connected source. This source requires additional configuration.'
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -222,7 +222,7 @@ export const SourcesLogic = kea<MakeLogicType<ISourcesValues, ISourcesActions>>(
}
);

setQueuedSuccessMessage(
flashSuccessToast(
[
successfullyConnectedMessage,
additionalConfiguration ? additionalConfigurationMessage : '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ describe('GroupLogic', () => {
const {
clearFlashMessages,
flashAPIErrors,
setSuccessMessage,
setQueuedSuccessMessage,
flashSuccessToast,
setQueuedErrorMessage,
} = mockFlashMessageHelpers;

Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -255,7 +252,7 @@ describe('GroupLogic', () => {

await nextTick();
expect(onGroupNameChangedSpy).toHaveBeenCalledWith(group);
expect(setSuccessMessage).toHaveBeenCalledWith(
expect(flashSuccessToast).toHaveBeenCalledWith(
'Successfully renamed this group to "group".'
);
});
Expand Down Expand Up @@ -286,7 +283,7 @@ describe('GroupLogic', () => {

await nextTick();
expect(onGroupSourcesSavedSpy).toHaveBeenCalledWith(group);
expect(setSuccessMessage).toHaveBeenCalledWith(
expect(flashSuccessToast).toHaveBeenCalledWith(
'Successfully updated shared content sources.'
);
});
Expand Down Expand Up @@ -323,7 +320,7 @@ describe('GroupLogic', () => {
});

await nextTick();
expect(setSuccessMessage).toHaveBeenCalledWith(
expect(flashSuccessToast).toHaveBeenCalledWith(
'Successfully updated shared source prioritization.'
);
expect(onGroupPrioritiesChangedSpy).toHaveBeenCalledWith(group);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -206,7 +205,7 @@ export const GroupLogic = kea<MakeLogicType<GroupValues, GroupActions>>({
}
);

setQueuedSuccessMessage(GROUP_DELETED_MESSAGE);
flashSuccessToast(GROUP_DELETED_MESSAGE);
KibanaLogic.values.navigateToUrl(GROUPS_PATH);
} catch (e) {
flashAPIErrors(e);
Expand All @@ -231,7 +230,7 @@ export const GroupLogic = kea<MakeLogicType<GroupValues, GroupActions>>({
values: { groupName: response.name },
}
);
setSuccessMessage(GROUP_RENAMED_MESSAGE);
flashSuccessToast(GROUP_RENAMED_MESSAGE);
} catch (e) {
flashAPIErrors(e);
}
Expand All @@ -256,7 +255,7 @@ export const GroupLogic = kea<MakeLogicType<GroupValues, GroupActions>>({
defaultMessage: 'Successfully updated shared content sources.',
}
);
setSuccessMessage(GROUP_SOURCES_UPDATED_MESSAGE);
flashSuccessToast(GROUP_SOURCES_UPDATED_MESSAGE);
} catch (e) {
flashAPIErrors(e);
}
Expand Down Expand Up @@ -289,7 +288,7 @@ export const GroupLogic = kea<MakeLogicType<GroupValues, GroupActions>>({
}
);

setSuccessMessage(GROUP_PRIORITIZATION_UPDATED_MESSAGE);
flashSuccessToast(GROUP_PRIORITIZATION_UPDATED_MESSAGE);
actions.onGroupPrioritiesChanged(response);
} catch (e) {
flashAPIErrors(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -328,7 +328,7 @@ export const GroupsLogic = kea<MakeLogicType<GroupsValues, GroupsActions>>({
}
);

setSuccessMessage(SUCCESS_MESSAGE);
flashSuccessToast(SUCCESS_MESSAGE);
actions.setNewGroup(response);
} catch (e) {
flashAPIErrors(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { kea, MakeLogicType } from 'kea';
import {
clearFlashMessages,
flashAPIErrors,
setSuccessMessage,
flashSuccessToast,
} from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
import {
Expand Down Expand Up @@ -397,7 +397,7 @@ export const RoleMappingsLogic = kea<MakeLogicType<RoleMappingsValues, RoleMappi
try {
await http.delete(route);
actions.initializeRoleMappings();
setSuccessMessage(ROLE_MAPPING_DELETED_MESSAGE);
flashSuccessToast(ROLE_MAPPING_DELETED_MESSAGE);
} catch (e) {
flashAPIErrors(e);
}
Expand Down Expand Up @@ -435,7 +435,7 @@ export const RoleMappingsLogic = kea<MakeLogicType<RoleMappingsValues, RoleMappi
try {
await request;
actions.initializeRoleMappings();
setSuccessMessage(SUCCESS_MESSAGE);
flashSuccessToast(SUCCESS_MESSAGE);
} catch (e) {
actions.setRoleMappingErrors(e?.body?.attributes?.errors);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { isEqual } from 'lodash';

import {
clearFlashMessages,
setSuccessMessage,
flashSuccessToast,
flashAPIErrors,
} from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
Expand Down Expand Up @@ -153,7 +153,7 @@ export const SecurityLogic = kea<MakeLogicType<SecurityValues, SecurityActions>>
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);
Expand Down
Loading

0 comments on commit 6b009c2

Please sign in to comment.