diff --git a/ui/src/authorizations/actions/index.ts b/ui/src/authorizations/actions/index.ts index 7a1ad98cd7..b84676f269 100644 --- a/ui/src/authorizations/actions/index.ts +++ b/ui/src/authorizations/actions/index.ts @@ -20,7 +20,7 @@ import { // Types import {RemoteDataState, GetState} from 'src/types' import {Authorization} from '@influxdata/influx' -import {PublishNotificationAction} from 'src/types/actions/notifications' +import {PublishNotificationAction} from 'src/shared/actions/notifications' export type Action = | SetAuthorizations diff --git a/ui/src/dashboards/actions/index.ts b/ui/src/dashboards/actions/index.ts index c0d0b3526e..88d82fb7be 100644 --- a/ui/src/dashboards/actions/index.ts +++ b/ui/src/dashboards/actions/index.ts @@ -18,7 +18,10 @@ import { import {createDashboardFromTemplate as createDashboardFromTemplateAJAX} from 'src/templates/api' // Actions -import {notify} from 'src/shared/actions/notifications' +import { + notify, + PublishNotificationAction, +} from 'src/shared/actions/notifications' import { deleteTimeRange, updateTimeRangeFromQueryParams, @@ -57,7 +60,6 @@ import {DEFAULT_DASHBOARD_NAME} from 'src/dashboards/constants/index' // Types import {RemoteDataState} from 'src/types' -import {PublishNotificationAction} from 'src/types/actions/notifications' import {CreateCell, ILabel} from '@influxdata/influx' import { Dashboard, @@ -85,7 +87,6 @@ export type Action = | SetDashboardAction | EditDashboardAction | RemoveCellAction - | PublishNotificationAction | SetViewAction | DeleteTimeRangeAction | DeleteDashboardFailedAction @@ -377,7 +378,7 @@ export const getDashboardAsync = (dashboardID: string) => async ( } export const updateDashboardAsync = (dashboard: Dashboard) => async ( - dispatch: Dispatch + dispatch: Dispatch ): Promise => { try { const updatedDashboard = await updateDashboardAJAX(dashboard) @@ -485,7 +486,9 @@ export const deleteCellAsync = (dashboard: Dashboard, cell: Cell) => async ( export const copyDashboardCellAsync = ( dashboard: Dashboard, cell: Cell -) => async (dispatch: Dispatch): Promise => { +) => async ( + dispatch: Dispatch +): Promise => { try { const clonedCell = getClonedDashboardCell(dashboard, cell) const updatedDashboard = { @@ -503,7 +506,7 @@ export const copyDashboardCellAsync = ( export const addDashboardLabelsAsync = ( dashboardID: string, labels: ILabel[] -) => async (dispatch: Dispatch) => { +) => async (dispatch: Dispatch) => { try { const newLabels = await client.dashboards.addLabels( dashboardID, @@ -520,7 +523,7 @@ export const addDashboardLabelsAsync = ( export const removeDashboardLabelsAsync = ( dashboardID: string, labels: ILabel[] -) => async (dispatch: Dispatch) => { +) => async (dispatch: Dispatch) => { try { await client.dashboards.removeLabels(dashboardID, labels.map(l => l.id)) diff --git a/ui/src/dashboards/components/DashboardPage.tsx b/ui/src/dashboards/components/DashboardPage.tsx index 3ef83a757a..0663a137a7 100644 --- a/ui/src/dashboards/components/DashboardPage.tsx +++ b/ui/src/dashboards/components/DashboardPage.tsx @@ -17,7 +17,6 @@ import VariablesControlBar from 'src/dashboards/components/variablesControlBar/V import * as dashboardActions from 'src/dashboards/actions' import * as rangesActions from 'src/dashboards/actions/ranges' import * as appActions from 'src/shared/actions/app' -import * as notifyActions from 'src/shared/actions/notifications' import {setActiveTimeMachine} from 'src/timeMachine/actions' import { setAutoRefreshInterval, @@ -52,7 +51,6 @@ import {ManualRefreshProps} from 'src/shared/components/ManualRefresh' import {Location} from 'history' import * as AppActions from 'src/types/actions/app' import * as ColorsModels from 'src/types/colors' -import * as NotificationsActions from 'src/types/actions/notifications' import {toggleShowVariablesControls} from 'src/userSettings/actions' import {Organization} from '@influxdata/influx' import LimitChecker from 'src/cloud/components/LimitChecker' @@ -81,7 +79,6 @@ interface DispatchProps { handleChooseAutoRefresh: typeof setAutoRefreshInterval onSetAutoRefreshStatus: typeof setAutoRefreshStatus handleClickPresentationButton: AppActions.DelayEnablePresentationModeDispatcher - notify: NotificationsActions.PublishNotificationActionCreator onCreateCellWithView: typeof dashboardActions.createCellWithView onUpdateView: typeof dashboardActions.updateView onSetActiveTimeMachine: typeof setActiveTimeMachine @@ -395,7 +392,6 @@ const mdtp: DispatchProps = { handleChooseAutoRefresh: setAutoRefreshInterval, onSetAutoRefreshStatus: setAutoRefreshStatus, handleClickPresentationButton: appActions.delayEnablePresentationMode, - notify: notifyActions.notify, setDashTimeV1: rangesActions.setDashTimeV1, updateQueryParams: rangesActions.updateQueryParams, setZoomedTimeRange: rangesActions.setZoomedTimeRange, diff --git a/ui/src/members/containers/MembersIndex.tsx b/ui/src/members/containers/MembersIndex.tsx index ede761b125..88f2f72996 100644 --- a/ui/src/members/containers/MembersIndex.tsx +++ b/ui/src/members/containers/MembersIndex.tsx @@ -12,23 +12,15 @@ import TabbedPageSection from 'src/shared/components/tabbed_page/TabbedPageSecti import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' import Members from 'src/members/components/Members' -//Actions -import * as NotificationsActions from 'src/types/actions/notifications' -import * as notifyActions from 'src/shared/actions/notifications' - // Types import {Organization} from '@influxdata/influx' import {AppState} from 'src/types' -interface DispatchProps { - notify: NotificationsActions.PublishNotificationActionCreator -} - interface StateProps { org: Organization } -type Props = WithRouterProps & StateProps & DispatchProps +type Props = WithRouterProps & StateProps @ErrorHandling class MembersIndex extends Component { @@ -73,11 +65,7 @@ const mstp = ({orgs: {items}}: AppState, props: Props) => { } } -const mdtp: DispatchProps = { - notify: notifyActions.notify, -} - export default connect( mstp, - mdtp + null )(withRouter<{}>(MembersIndex)) diff --git a/ui/src/organizations/actions/orgs.ts b/ui/src/organizations/actions/orgs.ts index c527f6de45..2818f26556 100644 --- a/ui/src/organizations/actions/orgs.ts +++ b/ui/src/organizations/actions/orgs.ts @@ -24,7 +24,7 @@ import { // Types import {Bucket} from '@influxdata/influx' import {Organization, RemoteDataState} from 'src/types' -import {PublishNotificationAction} from 'src/types/actions/notifications' +import {PublishNotificationAction} from 'src/shared/actions/notifications' export enum ActionTypes { SetOrgs = 'SET_ORGS', diff --git a/ui/src/shared/actions/notifications.ts b/ui/src/shared/actions/notifications.ts index 2b9d0f6955..f05887bf4c 100644 --- a/ui/src/shared/actions/notifications.ts +++ b/ui/src/shared/actions/notifications.ts @@ -1,20 +1,43 @@ -import * as NotificationsActions from 'src/types/actions/notifications' -import * as NotificationsModels from 'src/types/notifications' +import {Notification} from 'src/types' -export const notify: NotificationsActions.PublishNotificationActionCreator = ( - notification: NotificationsModels.Notification -): NotificationsActions.PublishNotificationAction => ({ - type: 'PUBLISH_NOTIFICATION', +export type Action = + | PublishNotificationAction + | DismissNotificationAction + | DismissAllNotificationsAction + +export enum ActionTypes { + PUBLISH_NOTIFICATION = 'PUBLISH_NOTIFICATION', + DISMISS_NOTIFICATION = 'DISMISS_NOTIFICATION', + DISMISS_ALL_NOTIFICATIONS = 'DISMISS_ALL_NOTIFICATIONS', +} + +export interface PublishNotificationAction { + type: ActionTypes.PUBLISH_NOTIFICATION + payload: { + notification: Notification + } +} +export const notify = ( + notification: Notification +): PublishNotificationAction => ({ + type: ActionTypes.PUBLISH_NOTIFICATION, payload: {notification}, }) -export const dismissNotification = ( - id: string -): NotificationsActions.DismissNotificationAction => ({ - type: 'DISMISS_NOTIFICATION', +export interface DismissNotificationAction { + type: ActionTypes.DISMISS_NOTIFICATION + payload: { + id: string + } +} +export const dismissNotification = (id: string): DismissNotificationAction => ({ + type: ActionTypes.DISMISS_NOTIFICATION, payload: {id}, }) -export const dismissAllNotifications = (): NotificationsActions.DismissAllNotificationsAction => ({ - type: 'DISMISS_ALL_NOTIFICATIONS', +export interface DismissAllNotificationsAction { + type: ActionTypes.DISMISS_ALL_NOTIFICATIONS +} +export const dismissAllNotifications = (): DismissAllNotificationsAction => ({ + type: ActionTypes.DISMISS_ALL_NOTIFICATIONS, }) diff --git a/ui/src/shared/reducers/notifications.ts b/ui/src/shared/reducers/notifications.ts index 1fa3877e52..4f4e4d2006 100644 --- a/ui/src/shared/reducers/notifications.ts +++ b/ui/src/shared/reducers/notifications.ts @@ -1,12 +1,12 @@ import uuid from 'uuid' -import {Action} from 'src/types/actions/notifications' +import {Action, ActionTypes} from 'src/shared/actions/notifications' import {Notification} from 'src/types' export const initialState: Notification[] = [] export const notifications = (state = initialState, action: Action) => { switch (action.type) { - case 'PUBLISH_NOTIFICATION': { + case ActionTypes.PUBLISH_NOTIFICATION: { const {notification} = action.payload const publishedNotification = { ...notification, @@ -16,11 +16,12 @@ export const notifications = (state = initialState, action: Action) => { return [publishedNotification, ...state] } - case 'DISMISS_NOTIFICATION': { + case ActionTypes.DISMISS_NOTIFICATION: { const {id} = action.payload return state.filter(n => n.id !== id) } - case 'DISMISS_ALL_NOTIFICATIONS': { + + case ActionTypes.DISMISS_ALL_NOTIFICATIONS: { return [] } } diff --git a/ui/src/types/actions/notifications.ts b/ui/src/types/actions/notifications.ts deleted file mode 100644 index 6615299786..0000000000 --- a/ui/src/types/actions/notifications.ts +++ /dev/null @@ -1,30 +0,0 @@ -import {Notification} from 'src/types' - -export type Action = - | PublishNotificationAction - | DismissNotificationAction - | DismissAllNotificationsAction - -export type PublishNotificationActionCreator = ( - n: Notification -) => PublishNotificationAction - -export interface PublishNotificationAction { - type: 'PUBLISH_NOTIFICATION' - payload: { - notification: Notification - } -} - -export type DismissNotification = (id: string) => DismissNotificationAction - -export interface DismissNotificationAction { - type: 'DISMISS_NOTIFICATION' - payload: { - id: string - } -} - -export interface DismissAllNotificationsAction { - type: 'DISMISS_ALL_NOTIFICATIONS' -}