From 868fcc67466c19a79d5997f4c4e39d89a2922e05 Mon Sep 17 00:00:00 2001 From: Andrew Watkins Date: Fri, 15 Jun 2018 12:29:38 -0700 Subject: [PATCH] Type notification actions / reducers / tests --- ui/src/shared/actions/notifications.js | 9 ----- ui/src/shared/actions/notifications.ts | 33 +++++++++++++++++++ ui/src/shared/actions/sources.ts | 2 +- ui/src/shared/copy/notifications.ts | 8 ++--- .../{notifications.js => notifications.ts} | 7 ++-- ...ications.test.js => notifications.test.ts} | 6 ++-- 6 files changed, 46 insertions(+), 19 deletions(-) delete mode 100644 ui/src/shared/actions/notifications.js create mode 100644 ui/src/shared/actions/notifications.ts rename ui/src/shared/reducers/{notifications.js => notifications.ts} (66%) rename ui/test/shared/reducers/{notifications.test.js => notifications.test.ts} (86%) diff --git a/ui/src/shared/actions/notifications.js b/ui/src/shared/actions/notifications.js deleted file mode 100644 index 5e1fbce2c..000000000 --- a/ui/src/shared/actions/notifications.js +++ /dev/null @@ -1,9 +0,0 @@ -export const notify = notification => ({ - type: 'PUBLISH_NOTIFICATION', - payload: {notification}, -}) - -export const dismissNotification = id => ({ - type: 'DISMISS_NOTIFICATION', - payload: {id}, -}) diff --git a/ui/src/shared/actions/notifications.ts b/ui/src/shared/actions/notifications.ts new file mode 100644 index 000000000..49619a99b --- /dev/null +++ b/ui/src/shared/actions/notifications.ts @@ -0,0 +1,33 @@ +import {Notification} from 'src/types' + +export type Action = ActionPublishNotification | ActionDismissNotification + +// Publish notification +export type PubishNotification = (n: Notification) => ActionPublishNotification +export interface ActionPublishNotification { + type: 'PUBLISH_NOTIFICATION' + payload: { + notification: Notification + } +} + +export const notify = ( + notification: Notification +): ActionPublishNotification => ({ + type: 'PUBLISH_NOTIFICATION', + payload: {notification}, +}) + +// Dismiss notification +export type DismissNotification = (id: string) => ActionDismissNotification +export interface ActionDismissNotification { + type: 'DISMISS_NOTIFICATION' + payload: { + id: string + } +} + +export const dismissNotification = (id: string): ActionDismissNotification => ({ + type: 'DISMISS_NOTIFICATION', + payload: {id}, +}) diff --git a/ui/src/shared/actions/sources.ts b/ui/src/shared/actions/sources.ts index 0bd36f66c..a68d22f84 100644 --- a/ui/src/shared/actions/sources.ts +++ b/ui/src/shared/actions/sources.ts @@ -155,7 +155,7 @@ export const removeAndLoadSources = (source: Source) => async ( } = await getSourcesAJAX() dispatch(loadSources(newSources)) } catch (err) { - dispatch(notify(notifyServerError())) + dispatch(notify(notifyServerError)) } } diff --git a/ui/src/shared/copy/notifications.ts b/ui/src/shared/copy/notifications.ts index 3f21c92d6..4e99e9a74 100644 --- a/ui/src/shared/copy/notifications.ts +++ b/ui/src/shared/copy/notifications.ts @@ -69,14 +69,14 @@ export const notifySessionTimedOut = () => ({ message: 'Your session has timed out. Log in again to continue.', }) -export const notifyServerError = () => ({ +export const notifyServerError = { ...defaultErrorNotification, - mesasage: 'Internal Server Error. Check API Logs.', -}) + message: 'Internal Server Error. Check API Logs.', +} export const notifyCouldNotRetrieveKapacitors = sourceID => ({ ...defaultErrorNotification, - mesasage: `Internal Server Error. Could not retrieve Kapacitor Connections for source ${sourceID}.`, + message: `Internal Server Error. Could not retrieve Kapacitor Connections for source ${sourceID}.`, }) export const notifyCouldNotRetrieveKapacitorServices = kapacitor => ({ diff --git a/ui/src/shared/reducers/notifications.js b/ui/src/shared/reducers/notifications.ts similarity index 66% rename from ui/src/shared/reducers/notifications.js rename to ui/src/shared/reducers/notifications.ts index e132f779c..cb9f6fd92 100644 --- a/ui/src/shared/reducers/notifications.js +++ b/ui/src/shared/reducers/notifications.ts @@ -1,7 +1,10 @@ import uuid from 'uuid' -export const initialState = [] +import {Action} from 'src/shared/actions/notifications' +import {Notification} from 'src/types' -export const notifications = (state = initialState, action) => { +export const initialState: Notification[] = [] + +export const notifications = (state = initialState, action: Action) => { switch (action.type) { case 'PUBLISH_NOTIFICATION': { const {notification} = action.payload diff --git a/ui/test/shared/reducers/notifications.test.js b/ui/test/shared/reducers/notifications.test.ts similarity index 86% rename from ui/test/shared/reducers/notifications.test.js rename to ui/test/shared/reducers/notifications.test.ts index 4c57534d4..9d088b074 100644 --- a/ui/test/shared/reducers/notifications.test.js +++ b/ui/test/shared/reducers/notifications.test.ts @@ -1,8 +1,8 @@ -import {initialState, notifications} from 'shared/reducers/notifications' +import {initialState, notifications} from 'src/shared/reducers/notifications' -import {notify, dismissNotification} from 'shared/actions/notifications' +import {notify, dismissNotification} from 'src/shared/actions/notifications' -import {FIVE_SECONDS} from 'shared/constants/index' +import {FIVE_SECONDS} from 'src/shared/constants/index' const notificationID = '000'