From 058af91e4637852812a1f6a79cd1307b5757d9da Mon Sep 17 00:00:00 2001 From: Delmer Reed Date: Fri, 22 Jun 2018 20:42:00 -0400 Subject: [PATCH] Refactor error types to follow new file structure Co-authored-by: Jared Scheib --- ui/src/dashboards/actions/index.ts | 2 +- .../dashboards/containers/DashboardPage.tsx | 2 +- ui/src/index.tsx | 9 +++++- ui/src/shared/actions/errors.ts | 32 +++---------------- ui/src/types/actions/dashboard.ts | 2 +- ui/src/types/actions/error.ts | 14 ++++++++ ui/src/types/error.ts | 13 ++++++++ 7 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 ui/src/types/actions/error.ts create mode 100644 ui/src/types/error.ts diff --git a/ui/src/dashboards/actions/index.ts b/ui/src/dashboards/actions/index.ts index fe2d2550f2..b93e1615c7 100644 --- a/ui/src/dashboards/actions/index.ts +++ b/ui/src/dashboards/actions/index.ts @@ -73,7 +73,7 @@ import * as DashboardAPIs from 'src/types/apis/dashboard' import * as DashboardReducers from 'src/types/reducers/dashboard' import * as AuthReducers from 'src/types/reducers/auth' import * as NotificationActions from 'src/shared/actions/notifications' -import * as ErrorActions from 'src/shared/actions/errors' +import * as ErrorActions from 'src/types/actions/error' import {LocationAction} from 'react-router-redux' export const loadDashboards: DashboardActions.LoadDashboardsActionCreator = ( diff --git a/ui/src/dashboards/containers/DashboardPage.tsx b/ui/src/dashboards/containers/DashboardPage.tsx index 58c396842c..9be4cec1d5 100644 --- a/ui/src/dashboards/containers/DashboardPage.tsx +++ b/ui/src/dashboards/containers/DashboardPage.tsx @@ -65,7 +65,7 @@ import * as AnnotationActions from 'src/shared/actions/annotations' import * as AppActions from 'src/shared/actions/app' import * as CellEditorOverlayActions from 'src/dashboards/actions/cellEditorOverlay' import * as DashboardActions from 'src/types/actions/dashboard' -import * as ErrorActions from 'src/shared/actions/errors' +import * as ErrorActions from 'src/types/actions/error' import * as NotificationActions from 'src/shared/actions/notifications' interface DashboardActions { diff --git a/ui/src/index.tsx b/ui/src/index.tsx index 438517a761..a7c39fefc7 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -49,6 +49,7 @@ import {notify} from 'src/shared/actions/notifications' import 'src/style/chronograf.scss' import {HEARTBEAT_INTERVAL} from 'src/shared/constants' +import * as ErrorData from 'src/types/error' const errorsQueue = [] @@ -185,7 +186,13 @@ class Root extends PureComponent<{}, State> { if (typeof error === 'object') { dispatch(notify(error)) } else { - dispatch(errorThrown({status: 0, auth: null}, error, 'warning')) + dispatch( + errorThrown( + {status: 0, auth: null}, + error, + ErrorData.AlertType.Warning + ) + ) } }) } diff --git a/ui/src/shared/actions/errors.ts b/ui/src/shared/actions/errors.ts index 9ca97e20ad..e00b5e1f91 100644 --- a/ui/src/shared/actions/errors.ts +++ b/ui/src/shared/actions/errors.ts @@ -1,35 +1,13 @@ -enum AlertType { - 'info', -} +import * as ErrorData from 'src/types/error' +import * as ErrorActions from 'src/types/actions/error' -export type ErrorThrownActionCreator = ( - error: Error, - altText?: string, - alertType?: AlertType -) => ErrorThrownAction - -interface ErrorThrownAction { - type: 'ERROR_THROWN' - error: ErrorDescription - altText?: string - alertType?: AlertType -} export const errorThrown = ( - error: ErrorDescription, + error: ErrorData.ErrorDescription, altText?: string, - alertType?: AlertType -): ErrorThrownAction => ({ + alertType?: ErrorData.AlertType +): ErrorActions.ErrorThrownAction => ({ type: 'ERROR_THROWN', error, altText, alertType, }) - -interface ErrorDescription { - status: number - auth: { - links: { - me: string - } - } -} diff --git a/ui/src/types/actions/dashboard.ts b/ui/src/types/actions/dashboard.ts index d93193c6e8..c28c320390 100644 --- a/ui/src/types/actions/dashboard.ts +++ b/ui/src/types/actions/dashboard.ts @@ -5,7 +5,7 @@ import {Source} from 'src/types' import * as DashboardData from 'src/types/dashboard' import * as QueryData from 'src/types/query' import * as TempVarData from 'src/types/tempVars' -import * as ErrorActions from 'src/shared/actions/errors' +import * as ErrorActions from 'src/types/actions/error' import * as NotificationActions from 'src/shared/actions/notifications' import * as DashboardReducers from 'src/types/reducers/dashboard' import {Location} from 'history' diff --git a/ui/src/types/actions/error.ts b/ui/src/types/actions/error.ts new file mode 100644 index 0000000000..185def97ed --- /dev/null +++ b/ui/src/types/actions/error.ts @@ -0,0 +1,14 @@ +import * as ErrorData from 'src/types/error' + +export type ErrorThrownActionCreator = ( + error: ErrorData.ErrorDescription, + altText?: string, + alertType?: ErrorData.AlertType +) => ErrorThrownAction + +export interface ErrorThrownAction { + type: 'ERROR_THROWN' + error: ErrorData.ErrorDescription + altText?: string + alertType?: ErrorData.AlertType +} diff --git a/ui/src/types/error.ts b/ui/src/types/error.ts new file mode 100644 index 0000000000..718355f3f8 --- /dev/null +++ b/ui/src/types/error.ts @@ -0,0 +1,13 @@ +export interface ErrorDescription { + status: number + auth: { + links: { + me: string + } + } +} + +export enum AlertType { + Info = 'info', + Warning = 'warning', +}