Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App Search] Success toast polish pass #103410

Merged
merged 13 commits into from
Jun 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const MOCK_CLIENT_DATA = crawlerDataServerToClient(MOCK_SERVER_DATA);
describe('CrawlerOverviewLogic', () => {
const { mount } = new LogicMounter(CrawlerOverviewLogic);
const { http } = mockHttpValues;
const { flashAPIErrors, setSuccessMessage } = mockFlashMessageHelpers;
const { flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -138,7 +138,7 @@ describe('CrawlerOverviewLogic', () => {
expect(CrawlerOverviewLogic.actions.onReceiveCrawlerData).toHaveBeenCalledWith(
MOCK_CLIENT_DATA
);
expect(setSuccessMessage).toHaveBeenCalled();
expect(flashSuccessToast).toHaveBeenCalled();
});

it('calls flashApiErrors when there is an error', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { kea, MakeLogicType } from 'kea';

import { i18n } from '@kbn/i18n';

import { flashAPIErrors, setSuccessMessage } from '../../../shared/flash_messages';
import { flashAPIErrors, flashSuccessToast } from '../../../shared/flash_messages';

import { HttpLogic } from '../../../shared/http';
import { EngineLogic } from '../engine';
Expand All @@ -21,7 +21,7 @@ export const DELETE_DOMAIN_MESSAGE = (domainUrl: string) =>
i18n.translate(
'xpack.enterpriseSearch.appSearch.crawler.domainsTable.action.delete.successMessage',
{
defaultMessage: 'Successfully deleted "{domainUrl}"',
defaultMessage: "Domain '{domainUrl}' was deleted",
values: {
domainUrl,
},
Expand Down Expand Up @@ -90,7 +90,7 @@ export const CrawlerOverviewLogic = kea<
);
const crawlerData = crawlerDataServerToClient(response);
actions.onReceiveCrawlerData(crawlerData);
setSuccessMessage(DELETE_DOMAIN_MESSAGE(domain.url));
flashSuccessToast(DELETE_DOMAIN_MESSAGE(domain.url));
} catch (e) {
flashAPIErrors(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,21 @@ export enum ApiTokenTypes {
Search = 'search',
}

export const CREATE_MESSAGE = i18n.translate('xpack.enterpriseSearch.appSearch.tokens.created', {
defaultMessage: 'Successfully created key.',
});
export const UPDATE_MESSAGE = i18n.translate('xpack.enterpriseSearch.appSearch.tokens.update', {
defaultMessage: 'Successfully updated API Key.',
});
export const DELETE_MESSAGE = i18n.translate('xpack.enterpriseSearch.appSearch.tokens.deleted', {
defaultMessage: 'Successfully deleted key.',
});
export const CREATE_MESSAGE = (name: string) =>
i18n.translate('xpack.enterpriseSearch.appSearch.tokens.created', {
defaultMessage: "API key '{name}' was created",
values: { name },
});
export const UPDATE_MESSAGE = (name: string) =>
i18n.translate('xpack.enterpriseSearch.appSearch.tokens.update', {
defaultMessage: "API key '{name}' was updated",
values: { name },
});
export const DELETE_MESSAGE = (name: string) =>
i18n.translate('xpack.enterpriseSearch.appSearch.tokens.deleted', {
defaultMessage: "API key '{name}' was deleted",
values: { name },
});

export const SEARCH_DISPLAY = i18n.translate(
'xpack.enterpriseSearch.appSearch.tokens.permissions.display.search',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { CredentialsLogic } from './credentials_logic';
describe('CredentialsLogic', () => {
const { mount } = new LogicMounter(CredentialsLogic);
const { http } = mockHttpValues;
const { clearFlashMessages, setSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers;
const { clearFlashMessages, flashSuccessToast, flashAPIErrors } = mockFlashMessageHelpers;

const DEFAULT_VALUES = {
activeApiToken: {
Expand Down Expand Up @@ -1110,7 +1110,7 @@ describe('CredentialsLogic', () => {
await nextTick();

expect(CredentialsLogic.actions.fetchCredentials).toHaveBeenCalled();
expect(setSuccessMessage).toHaveBeenCalled();
expect(flashSuccessToast).toHaveBeenCalled();
});

it('handles errors', async () => {
Expand Down Expand Up @@ -1142,7 +1142,7 @@ describe('CredentialsLogic', () => {
});
await nextTick();
expect(CredentialsLogic.actions.onApiTokenCreateSuccess).toHaveBeenCalledWith(createdToken);
expect(setSuccessMessage).toHaveBeenCalled();
expect(flashSuccessToast).toHaveBeenCalled();
});

it('calls a PUT endpoint that updates the active token if it already exists', async () => {
Expand All @@ -1169,7 +1169,7 @@ describe('CredentialsLogic', () => {
});
await nextTick();
expect(CredentialsLogic.actions.onApiTokenUpdateSuccess).toHaveBeenCalledWith(updatedToken);
expect(setSuccessMessage).toHaveBeenCalled();
expect(flashSuccessToast).toHaveBeenCalled();
});

it('handles errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Meta } from '../../../../../common/types';
import { DEFAULT_META } from '../../../shared/constants';
import {
clearFlashMessages,
setSuccessMessage,
flashSuccessToast,
flashAPIErrors,
} from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
Expand Down Expand Up @@ -261,7 +261,7 @@ export const CredentialsLogic = kea<CredentialsLogicType>({
await http.delete(`/api/app_search/credentials/${tokenName}`);

actions.fetchCredentials();
setSuccessMessage(DELETE_MESSAGE);
flashSuccessToast(DELETE_MESSAGE(tokenName));
} catch (e) {
flashAPIErrors(e);
}
Expand Down Expand Up @@ -289,11 +289,11 @@ export const CredentialsLogic = kea<CredentialsLogicType>({
if (id) {
const response = await http.put(`/api/app_search/credentials/${name}`, { body });
actions.onApiTokenUpdateSuccess(response);
setSuccessMessage(UPDATE_MESSAGE);
flashSuccessToast(UPDATE_MESSAGE(name));
} else {
const response = await http.post('/api/app_search/credentials', { body });
actions.onApiTokenCreateSuccess(response);
setSuccessMessage(CREATE_MESSAGE);
flashSuccessToast(CREATE_MESSAGE(name));
}
} catch (e) {
flashAPIErrors(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const DELETE_MESSAGE = i18n.translate(
);
export const SUCCESS_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.curations.deleteSuccessMessage',
{ defaultMessage: 'Successfully removed curation.' }
{ defaultMessage: 'Your curation was deleted' }
);
export const RESTORE_CONFIRMATION = i18n.translate(
'xpack.enterpriseSearch.appSearch.engine.curations.restoreConfirmation',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('CurationsLogic', () => {
const { mount } = new LogicMounter(CurationsLogic);
const { http } = mockHttpValues;
const { navigateToUrl } = mockKibanaValues;
const { clearFlashMessages, setSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers;
const { clearFlashMessages, flashSuccessToast, flashAPIErrors } = mockFlashMessageHelpers;

const MOCK_CURATIONS_RESPONSE = {
meta: {
Expand Down Expand Up @@ -154,7 +154,7 @@ describe('CurationsLogic', () => {
'/api/app_search/engines/some-engine/curations/some-curation-id'
);
expect(CurationsLogic.actions.loadCurations).toHaveBeenCalled();
expect(setSuccessMessage).toHaveBeenCalledWith('Successfully removed curation.');
expect(flashSuccessToast).toHaveBeenCalledWith('Your curation was deleted');
});

it('handles errors', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Meta } from '../../../../../common/types';
import { DEFAULT_META } from '../../../shared/constants';
import {
clearFlashMessages,
setSuccessMessage,
flashSuccessToast,
flashAPIErrors,
} from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
Expand Down Expand Up @@ -95,7 +95,7 @@ export const CurationsLogic = kea<MakeLogicType<CurationsValues, CurationsAction
try {
await http.delete(`/api/app_search/engines/${engineName}/curations/${id}`);
actions.loadCurations();
setSuccessMessage(SUCCESS_MESSAGE);
flashSuccessToast(SUCCESS_MESSAGE);
} catch (e) {
flashAPIErrors(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('DocumentDetailLogic', () => {
const { mount } = new LogicMounter(DocumentDetailLogic);
const { http } = mockHttpValues;
const { navigateToUrl } = mockKibanaValues;
const { setQueuedSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers;
const { flashSuccessToast, flashAPIErrors } = mockFlashMessageHelpers;

const DEFAULT_VALUES = {
dataLoading: true,
Expand Down Expand Up @@ -101,9 +101,9 @@ describe('DocumentDetailLogic', () => {

expect(http.delete).toHaveBeenCalledWith('/api/app_search/engines/engine1/documents/1');
await nextTick();
expect(setQueuedSuccessMessage).toHaveBeenCalledWith(
'Successfully marked document for deletion. It will be deleted momentarily.'
);
expect(flashSuccessToast).toHaveBeenCalledWith('Your document was marked for deletion', {
text: 'It will be deleted momentarily.',
});
expect(navigateToUrl).toHaveBeenCalledWith('/engines/engine1/documents');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { kea, MakeLogicType } from 'kea';

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 { KibanaLogic } from '../../../shared/kibana';

Expand Down Expand Up @@ -79,19 +79,20 @@ export const DocumentDetailLogic = kea<DocumentDetailLogicType>({
'xpack.enterpriseSearch.appSearch.documentDetail.confirmDelete',
{ defaultMessage: 'Are you sure you want to delete this document?' }
);
const DELETE_SUCCESS = i18n.translate(
const DELETE_SUCCESS_TITLE = i18n.translate(
'xpack.enterpriseSearch.appSearch.documentDetail.deleteSuccess',
{
defaultMessage:
'Successfully marked document for deletion. It will be deleted momentarily.',
}
{ defaultMessage: 'Your document was marked for deletion' }
);
const DELETE_SUCCESS_TEXT = i18n.translate(
'xpack.enterpriseSearch.appSearch.documentDetail.deleteSuccessDescription',
{ defaultMessage: 'It will be deleted momentarily.' }
);

if (window.confirm(CONFIRM_DELETE)) {
try {
const { http } = HttpLogic.values;
await http.delete(`/api/app_search/engines/${engineName}/documents/${documentId}`);
setQueuedSuccessMessage(DELETE_SUCCESS);
flashSuccessToast(DELETE_SUCCESS_TITLE, { text: DELETE_SUCCESS_TEXT });
navigateToUrl(generateEnginePath(ENGINE_DOCUMENTS_PATH));
} catch (e) {
flashAPIErrors(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ export const ENGINE_CREATION_FORM_SUBMIT_BUTTON_LABEL = i18n.translate(
}
);

export const ENGINE_CREATION_SUCCESS_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.appSearch.engineCreation.successMessage',
{
defaultMessage: 'Successfully created engine.',
}
);
export const ENGINE_CREATION_SUCCESS_MESSAGE = (name: string) =>
i18n.translate('xpack.enterpriseSearch.appSearch.engineCreation.successMessage', {
defaultMessage: "Engine '{name}' was created",
values: { name },
});

export const SUPPORTED_LANGUAGES = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('EngineCreationLogic', () => {
const { mount } = new LogicMounter(EngineCreationLogic);
const { http } = mockHttpValues;
const { navigateToUrl } = mockKibanaValues;
const { setQueuedSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers;
const { flashSuccessToast, flashAPIErrors } = mockFlashMessageHelpers;

const DEFAULT_VALUES = {
isLoading: false,
Expand Down Expand Up @@ -99,8 +99,8 @@ describe('EngineCreationLogic', () => {
jest.clearAllMocks();
});

it('should set a success message', () => {
expect(setQueuedSuccessMessage).toHaveBeenCalledWith('Successfully created engine.');
it('should show a success message', () => {
expect(flashSuccessToast).toHaveBeenCalledWith("Engine 'test' was created");
});

it('should navigate the user to the engine page', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { generatePath } from 'react-router-dom';

import { kea, MakeLogicType } from 'kea';

import { flashAPIErrors, setQueuedSuccessMessage } from '../../../shared/flash_messages';
import { flashAPIErrors, flashSuccessToast } from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
import { KibanaLogic } from '../../../shared/kibana';
import { ENGINE_PATH } from '../../routes';
Expand Down Expand Up @@ -85,7 +85,7 @@ export const EngineCreationLogic = kea<MakeLogicType<EngineCreationValues, Engin
const { navigateToUrl } = KibanaLogic.values;
const enginePath = generatePath(ENGINE_PATH, { engineName: name });

setQueuedSuccessMessage(ENGINE_CREATION_SUCCESS_MESSAGE);
flashSuccessToast(ENGINE_CREATION_SUCCESS_MESSAGE(name));
navigateToUrl(enginePath);
},
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const DELETE_ENGINE_MESSAGE = (engineName: string) =>
i18n.translate(
'xpack.enterpriseSearch.appSearch.enginesOverview.table.action.delete.successMessage',
{
defaultMessage: 'Successfully deleted "{engineName}"',
defaultMessage: "Engine '{engineName}' was deleted",
values: {
engineName,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { EnginesLogic } from './';
describe('EnginesLogic', () => {
const { mount } = new LogicMounter(EnginesLogic);
const { http } = mockHttpValues;
const { flashAPIErrors, setSuccessMessage } = mockFlashMessageHelpers;
const { flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers;

const DEFAULT_VALUES = {
dataLoading: true,
Expand Down Expand Up @@ -199,10 +199,10 @@ describe('EnginesLogic', () => {
mount();
});

it('should call setSuccessMessage', () => {
it('should call flashSuccessToast', () => {
EnginesLogic.actions.onDeleteEngineSuccess(MOCK_ENGINE);

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

it('should call loadEngines if engine.type === default', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { kea, MakeLogicType } from 'kea';

import { Meta } from '../../../../../common/types';
import { DEFAULT_META } from '../../../shared/constants';
import { flashAPIErrors, setSuccessMessage } from '../../../shared/flash_messages';
import { flashAPIErrors, flashSuccessToast } from '../../../shared/flash_messages';
import { HttpLogic } from '../../../shared/http';
import { updateMetaPageIndex } from '../../../shared/table_pagination';

Expand Down Expand Up @@ -141,7 +141,7 @@ export const EnginesLogic = kea<MakeLogicType<EnginesValues, EnginesActions>>({
actions.onMetaEnginesLoad(response);
},
onDeleteEngineSuccess: async ({ engine }) => {
setSuccessMessage(DELETE_ENGINE_MESSAGE(engine.name));
flashSuccessToast(DELETE_ENGINE_MESSAGE(engine.name));
if ([EngineTypes.default, EngineTypes.indexed].includes(engine.type)) {
actions.loadEngines();
} else if (engine.type === EngineTypes.meta) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ export const META_ENGINE_CREATION_FORM_MAX_SOURCE_ENGINES_WARNING_TITLE = (
}
);

export const META_ENGINE_CREATION_SUCCESS_MESSAGE = i18n.translate(
'xpack.enterpriseSearch.appSearch.metaEngineCreation.successMessage',
{
defaultMessage: 'Successfully created meta engine.',
}
);
export const META_ENGINE_CREATION_SUCCESS_MESSAGE = (name: string) =>
i18n.translate('xpack.enterpriseSearch.appSearch.metaEngineCreation.successMessage', {
defaultMessage: "Meta engine '{name}' was created",
values: { name },
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('MetaEngineCreationLogic', () => {
const { mount } = new LogicMounter(MetaEngineCreationLogic);
const { http } = mockHttpValues;
const { navigateToUrl } = mockKibanaValues;
const { setQueuedSuccessMessage, flashAPIErrors } = mockFlashMessageHelpers;
const { flashSuccessToast, flashAPIErrors } = mockFlashMessageHelpers;

const DEFAULT_VALUES = {
isLoading: false,
Expand Down Expand Up @@ -152,8 +152,8 @@ describe('MetaEngineCreationLogic', () => {
MetaEngineCreationLogic.actions.onEngineCreationSuccess();
});

it('should set a success message', () => {
expect(setQueuedSuccessMessage).toHaveBeenCalledWith('Successfully created meta engine.');
it('should show a success message', () => {
expect(flashSuccessToast).toHaveBeenCalledWith("Meta engine 'test' was created");
});

it('should navigate the user to the engine page', () => {
Expand Down
Loading