Move notifications action types back in to actions file

pull/13638/head
Deniz Kusefoglu 2019-04-25 12:26:16 -07:00
parent dcd6dea97a
commit c4f3580e0b
8 changed files with 54 additions and 73 deletions

View File

@ -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

View File

@ -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<Action>
dispatch: Dispatch<Action | PublishNotificationAction>
): Promise<void> => {
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<Action>): Promise<void> => {
) => async (
dispatch: Dispatch<Action | PublishNotificationAction>
): Promise<void> => {
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<Action>) => {
) => async (dispatch: Dispatch<Action | PublishNotificationAction>) => {
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<Action>) => {
) => async (dispatch: Dispatch<Action | PublishNotificationAction>) => {
try {
await client.dashboards.removeLabels(dashboardID, labels.map(l => l.id))

View File

@ -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,

View File

@ -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<Props> {
@ -73,11 +65,7 @@ const mstp = ({orgs: {items}}: AppState, props: Props) => {
}
}
const mdtp: DispatchProps = {
notify: notifyActions.notify,
}
export default connect<StateProps>(
mstp,
mdtp
null
)(withRouter<{}>(MembersIndex))

View File

@ -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',

View File

@ -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,
})

View File

@ -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 []
}
}

View File

@ -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'
}