From acf083e5b6326c6a727aa567d89aa9c79cae1f67 Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Fri, 4 May 2018 17:14:44 -0700 Subject: [PATCH] Centralize Notification types & make usage consistent --- ui/src/CheckSources.tsx | 4 ++-- ui/src/admin/containers/chronograf/AllUsersPage.tsx | 11 +++++++++-- ui/src/kapacitor/components/AlertOutputs.tsx | 12 +----------- ui/src/kapacitor/components/KapacitorForm.tsx | 12 +----------- ui/src/kapacitor/components/config/KafkaConfig.tsx | 3 +++ ui/src/kapacitor/containers/KapacitorPage.tsx | 12 +----------- ui/src/kapacitor/containers/TickscriptPage.tsx | 11 +++++++++-- ui/src/types/index.ts | 3 ++- 8 files changed, 28 insertions(+), 40 deletions(-) diff --git a/ui/src/CheckSources.tsx b/ui/src/CheckSources.tsx index dfe6d2abcf..03fa5bd0e2 100644 --- a/ui/src/CheckSources.tsx +++ b/ui/src/CheckSources.tsx @@ -24,7 +24,7 @@ import {DEFAULT_HOME_PAGE} from 'src/shared/constants' import * as copy from 'src/shared/copy/notifications' -import {Source, Me} from 'src/types' +import {Source, Me, Notification, NotificationFunc} from 'src/types' interface Auth { isUsingAuth: boolean @@ -47,7 +47,7 @@ interface Props { router: InjectedRouter location: Location auth: Auth - notify: () => void + notify: (message: Notification | NotificationFunc) => void errorThrown: () => void } diff --git a/ui/src/admin/containers/chronograf/AllUsersPage.tsx b/ui/src/admin/containers/chronograf/AllUsersPage.tsx index 4f74b6683e..8f42680e5e 100644 --- a/ui/src/admin/containers/chronograf/AllUsersPage.tsx +++ b/ui/src/admin/containers/chronograf/AllUsersPage.tsx @@ -8,10 +8,17 @@ import {notify as notifyAction} from 'src/shared/actions/notifications' import {ErrorHandling} from 'src/shared/decorators/errors' import AllUsersTable from 'src/admin/components/chronograf/AllUsersTable' -import {AuthLinks, Organization, Role, User} from 'src/types' +import { + AuthLinks, + Organization, + Role, + User, + Notification, + NotificationFunc, +} from 'src/types' interface Props { - notify: () => void + notify: (message: Notification | NotificationFunc) => void links: AuthLinks meID: string users: User[] diff --git a/ui/src/kapacitor/components/AlertOutputs.tsx b/ui/src/kapacitor/components/AlertOutputs.tsx index 235d6b031d..e2d85754fe 100644 --- a/ui/src/kapacitor/components/AlertOutputs.tsx +++ b/ui/src/kapacitor/components/AlertOutputs.tsx @@ -2,17 +2,7 @@ import React, {SFC} from 'react' import AlertTabs from 'src/kapacitor/components/AlertTabs' -import {Kapacitor, Source} from 'src/types' - -export interface Notification { - id?: string - type: string - icon: string - duration: number - message: string -} - -type NotificationFunc = () => Notification +import {Kapacitor, Source, Notification, NotificationFunc} from 'src/types' interface AlertOutputProps { exists: boolean diff --git a/ui/src/kapacitor/components/KapacitorForm.tsx b/ui/src/kapacitor/components/KapacitorForm.tsx index 3bbbb95a10..436775eeea 100644 --- a/ui/src/kapacitor/components/KapacitorForm.tsx +++ b/ui/src/kapacitor/components/KapacitorForm.tsx @@ -3,19 +3,9 @@ import React, {ChangeEvent, MouseEvent, PureComponent} from 'react' import AlertOutputs from 'src/kapacitor/components/AlertOutputs' import Input from 'src/kapacitor/components/KapacitorFormInput' import FancyScrollbar from 'src/shared/components/FancyScrollbar' - -import {Kapacitor, Source} from 'src/types' import KapacitorFormSkipVerify from 'src/kapacitor/components/KapacitorFormSkipVerify' -export interface Notification { - id?: string - type: string - icon: string - duration: number - message: string -} - -type NotificationFunc = () => Notification +import {Kapacitor, Source, Notification, NotificationFunc} from 'src/types' interface Props { kapacitor: Kapacitor diff --git a/ui/src/kapacitor/components/config/KafkaConfig.tsx b/ui/src/kapacitor/components/config/KafkaConfig.tsx index 131baf3aa6..d3dfc1f050 100644 --- a/ui/src/kapacitor/components/config/KafkaConfig.tsx +++ b/ui/src/kapacitor/components/config/KafkaConfig.tsx @@ -3,6 +3,8 @@ import React, {PureComponent} from 'react' import TagInput from 'src/shared/components/TagInput' import {ErrorHandling} from 'src/shared/decorators/errors' +import {Notification, NotificationFunc} from 'src/types' + interface Properties { brokers: string[] timeout: string @@ -30,6 +32,7 @@ interface Props { onSave: (properties: Properties) => void onTest: (event: React.MouseEvent) => void enabled: boolean + notify: (message: Notification | NotificationFunc) => void } interface State { diff --git a/ui/src/kapacitor/containers/KapacitorPage.tsx b/ui/src/kapacitor/containers/KapacitorPage.tsx index 54953b6d61..a2f73e7ccb 100644 --- a/ui/src/kapacitor/containers/KapacitorPage.tsx +++ b/ui/src/kapacitor/containers/KapacitorPage.tsx @@ -5,7 +5,7 @@ import {bindActionCreators} from 'redux' import {notify as notifyAction} from 'src/shared/actions/notifications' -import {Source} from 'src/types' +import {Source, Notification, NotificationFunc} from 'src/types' import { createKapacitor, @@ -29,16 +29,6 @@ import {ErrorHandling} from 'src/shared/decorators/errors' export const defaultName = 'My Kapacitor' export const kapacitorPort = '9092' -export interface Notification { - id?: string - type: string - icon: string - duration: number - message: string -} - -export type NotificationFunc = () => Notification - interface Kapacitor { url: string name: string diff --git a/ui/src/kapacitor/containers/TickscriptPage.tsx b/ui/src/kapacitor/containers/TickscriptPage.tsx index fc5219e79f..294822e8a4 100644 --- a/ui/src/kapacitor/containers/TickscriptPage.tsx +++ b/ui/src/kapacitor/containers/TickscriptPage.tsx @@ -10,7 +10,14 @@ import {getActiveKapacitor} from 'src/shared/apis' import {getLogStreamByRuleID, pingKapacitorVersion} from 'src/kapacitor/apis' import {notify as notifyAction} from 'src/shared/actions/notifications' -import {Source, Kapacitor, Task, AlertRule} from 'src/types' +import { + Source, + Kapacitor, + Task, + AlertRule, + Notification, + NotificationFunc, +} from 'src/types' import { notifyTickscriptLoggingUnavailable, @@ -55,7 +62,7 @@ interface Props { router: Router params: Params rules: AlertRule[] - notify: any + notify: (message: Notification | NotificationFunc) => void } interface State { diff --git a/ui/src/types/index.ts b/ui/src/types/index.ts index b36075edf6..2ed881ce8d 100644 --- a/ui/src/types/index.ts +++ b/ui/src/types/index.ts @@ -11,7 +11,7 @@ import { import {AlertRule, Kapacitor, Task} from './kapacitor' import {Source, SourceLinks} from './sources' import {DropdownAction, DropdownItem} from './shared' -import {Notification} from 'src/kapacitor/components/AlertOutputs' +import {Notification, NotificationFunc} from './notifications' export { Me, @@ -37,4 +37,5 @@ export { TimeRange, Task, Notification, + NotificationFunc, }