From e5f8e15e3de176071daa61e54f8fa663cb9865c5 Mon Sep 17 00:00:00 2001 From: Constance Chen Date: Mon, 28 Sep 2020 20:31:18 -0700 Subject: [PATCH] [Optional?] Update FlashMessages to grab history from KibanaLogic - since we're now storing it there, we might as well grab it as well instead of passing in props? --- .../enterprise_search/public/applications/index.tsx | 4 +--- .../flash_messages/flash_messages_logic.test.ts | 5 ++++- .../shared/flash_messages/flash_messages_logic.ts | 13 +++++-------- .../flash_messages/set_message_helpers.test.ts | 5 ++++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/index.tsx b/x-pack/plugins/enterprise_search/public/applications/index.tsx index 4b5f1374814d5..8b5e7daea989c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/index.tsx @@ -54,9 +54,7 @@ export const renderApp = ( errorConnecting, readOnlyMode: initialData.readOnlyMode, }); - const unmountFlashMessagesLogic = mountFlashMessagesLogic({ - history: params.history, - }); + const unmountFlashMessagesLogic = mountFlashMessagesLogic(); ReactDOM.render( diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.test.ts index c12011b47a472..ff1ec7428e828 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.test.ts @@ -7,11 +7,14 @@ import { resetContext } from 'kea'; import { mockHistory } from '../../__mocks__'; +jest.mock('../kibana', () => ({ + KibanaLogic: { values: { history: mockHistory } }, +})); import { FlashMessagesLogic, mountFlashMessagesLogic, IFlashMessage } from './'; describe('FlashMessagesLogic', () => { - const mount = () => mountFlashMessagesLogic({ history: mockHistory as any }); + const mount = () => mountFlashMessagesLogic(); beforeEach(() => { jest.clearAllMocks(); diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts index 1735cc8ac7228..5a05a03adeb6b 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/flash_messages_logic.ts @@ -6,7 +6,8 @@ import { kea, MakeLogicType } from 'kea'; import { ReactNode } from 'react'; -import { History } from 'history'; + +import { KibanaLogic } from '../kibana'; export interface IFlashMessage { type: 'success' | 'info' | 'warning' | 'error'; @@ -61,10 +62,10 @@ export const FlashMessagesLogic = kea ({ + events: ({ values, actions }) => ({ afterMount: () => { // On React Router navigation, clear previous flash messages and load any queued messages - const unlisten = props.history.listen(() => { + const unlisten = KibanaLogic.values.history.listen(() => { actions.clearFlashMessages(); actions.setFlashMessages(values.queuedMessages); actions.clearQueuedMessages(); @@ -81,11 +82,7 @@ export const FlashMessagesLogic = kea { - FlashMessagesLogic(props); +export const mountFlashMessagesLogic = () => { const unmount = FlashMessagesLogic.mount(); return unmount; }; diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/set_message_helpers.test.ts b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/set_message_helpers.test.ts index f2ddd560ac9c1..46027fdfb22b1 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/set_message_helpers.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/flash_messages/set_message_helpers.test.ts @@ -5,6 +5,9 @@ */ import { mockHistory } from '../../__mocks__'; +jest.mock('../kibana', () => ({ + KibanaLogic: { values: { history: mockHistory } }, +})); import { FlashMessagesLogic, @@ -18,7 +21,7 @@ describe('Flash Message Helpers', () => { const message = 'I am a message'; beforeEach(() => { - mountFlashMessagesLogic({ history: mockHistory as any }); + mountFlashMessagesLogic(); }); it('setSuccessMessage()', () => {