Skip to content

Commit

Permalink
[Optional?] Update FlashMessages to grab history from KibanaLogic
Browse files Browse the repository at this point in the history
- since we're now storing it there, we might as well grab it as well instead of passing in props?
  • Loading branch information
cee-chen committed Sep 29, 2020
1 parent a60020b commit e5f8e15
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ export const renderApp = (
errorConnecting,
readOnlyMode: initialData.readOnlyMode,
});
const unmountFlashMessagesLogic = mountFlashMessagesLogic({
history: params.history,
});
const unmountFlashMessagesLogic = mountFlashMessagesLogic();

ReactDOM.render(
<I18nProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -61,10 +62,10 @@ export const FlashMessagesLogic = kea<MakeLogicType<IFlashMessagesValues, IFlash
},
],
},
events: ({ props, values, actions }) => ({
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();
Expand All @@ -81,11 +82,7 @@ export const FlashMessagesLogic = kea<MakeLogicType<IFlashMessagesValues, IFlash
/**
* Mount/props helper
*/
interface IFlashMessagesLogicProps {
history: History;
}
export const mountFlashMessagesLogic = (props: IFlashMessagesLogicProps) => {
FlashMessagesLogic(props);
export const mountFlashMessagesLogic = () => {
const unmount = FlashMessagesLogic.mount();
return unmount;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*/

import { mockHistory } from '../../__mocks__';
jest.mock('../kibana', () => ({
KibanaLogic: { values: { history: mockHistory } },
}));

import {
FlashMessagesLogic,
Expand All @@ -18,7 +21,7 @@ describe('Flash Message Helpers', () => {
const message = 'I am a message';

beforeEach(() => {
mountFlashMessagesLogic({ history: mockHistory as any });
mountFlashMessagesLogic();
});

it('setSuccessMessage()', () => {
Expand Down

0 comments on commit e5f8e15

Please sign in to comment.