Add & fix consumption of Dashboard ActionCreator types

pull/10616/head
Jared Scheib 2018-06-20 14:45:07 -07:00
parent 680c0e58f2
commit 0fd89449bd
8 changed files with 81 additions and 39 deletions

View File

@ -23,13 +23,17 @@ export type Action =
| ChangeDecimalPlacesAction
| UpdateFieldOptionsAction
export interface ShowCellEditorOverlayAction {
export type ShowCellEditorOverlayActionCreator = (
cell: Cell
) => ShowCellEditorOverlayAction
interface ShowCellEditorOverlayAction {
type: 'SHOW_CELL_EDITOR_OVERLAY'
payload: {
cell: Cell
}
}
export const showCellEditorOverlay = (
export const showCellEditorOverlay: ShowCellEditorOverlayActionCreator = (
cell: Cell
): ShowCellEditorOverlayAction => ({
type: 'SHOW_CELL_EDITOR_OVERLAY',
@ -38,7 +42,9 @@ export const showCellEditorOverlay = (
},
})
export interface HideCellEditorOverlayAction {
export type HideCellEditorOverlayActionCreator = () => HideCellEditorOverlayAction
interface HideCellEditorOverlayAction {
type: 'HIDE_CELL_EDITOR_OVERLAY'
}
export const hideCellEditorOverlay = (): HideCellEditorOverlayAction => ({

View File

@ -68,10 +68,15 @@ import {
} from 'src/types'
import {CellType, DashboardName} from 'src/types/dashboard'
import {TimeRangeOption} from 'src/shared/data/timeRanges'
import {ActionPublishNotification} from 'src/shared/actions/notifications'
import {ErrorThrownAction} from 'src/shared/actions/errors'
import {PublishNotificationActionCreator} from 'src/shared/actions/notifications'
import * as ErrorActions from 'src/shared/actions/errors'
import {LocationAction} from 'react-router-redux'
export type LoadDashboardsActionCreator = (
dashboards: Dashboard[],
dashboardID?: number
) => LoadDashboardsAction
interface LoadDashboardsAction {
type: 'LOAD_DASHBOARDS'
payload: {
@ -79,7 +84,7 @@ interface LoadDashboardsAction {
dashboardID: number
}
}
export const loadDashboards = (
export const loadDashboards: LoadDashboardsActionCreator = (
dashboards: Dashboard[],
dashboardID?: number
): LoadDashboardsAction => ({
@ -388,14 +393,16 @@ export const setActiveCell = (activeCellID: string): SetActiveCellAction => ({
// Async Action Creators
type GetDashboardsDispatcher = () => GetDashboardsThunk
export type GetDashboardsDispatcher = () => GetDashboardsThunk
type GetDashboardsThunk = (
dispatch: Dispatch<ErrorThrownAction>
dispatch: Dispatch<ErrorActions.ErrorThrownActionCreator>
) => Promise<Dashboard[] | void>
export const getDashboardsAsync = (): GetDashboardsThunk => async (
dispatch: Dispatch<LoadDashboardsAction | ErrorThrownAction>
dispatch: Dispatch<
LoadDashboardsActionCreator | ErrorActions.ErrorThrownActionCreator
>
): Promise<Dashboard[] | void> => {
try {
const {
@ -414,7 +421,7 @@ export type GetDashboardsNamesDispatcher = (
) => GetDashboardsNamesThunk
type GetDashboardsNamesThunk = (
dispatch: Dispatch<ErrorThrownAction>
dispatch: Dispatch<ErrorActions.ErrorThrownActionCreator>
) => Promise<DashboardName[] | void>
// gets update-to-date names of dashboards, but does not dispatch action
@ -422,7 +429,7 @@ type GetDashboardsNamesThunk = (
export const getDashboardsNamesAsync = (
sourceID: string
): GetDashboardsNamesThunk => async (
dispatch: Dispatch<ErrorThrownAction>
dispatch: Dispatch<ErrorActions.ErrorThrownActionCreator>
): Promise<DashboardName[] | void> => {
try {
// TODO: change this from getDashboardsAJAX to getDashboardsNamesAJAX
@ -487,11 +494,15 @@ const removeUnselectedTemplateValues = (dashboard: Dashboard): Template[] => {
export type PutDashboardDispatcher = (dashboard: Dashboard) => PutDashboardThunk
type PutDashboardThunk = (
dispatch: Dispatch<UpdateDashboardAction | ErrorThrownAction>
dispatch: Dispatch<
UpdateDashboardAction | ErrorActions.ErrorThrownActionCreator
>
) => Promise<void>
export const putDashboard = (dashboard: Dashboard): PutDashboardThunk => async (
dispatch: Dispatch<UpdateDashboardAction | ErrorThrownAction>
dispatch: Dispatch<
UpdateDashboardAction | ErrorActions.ErrorThrownActionCreator
>
): Promise<void> => {
try {
// save only selected template values to server
@ -522,7 +533,7 @@ interface DashboardsReducerState {
}
type PutDashboardByIDThunk = (
dispatch: Dispatch<ErrorThrownAction>,
dispatch: Dispatch<ErrorActions.ErrorThrownActionCreator>,
getState: () => DashboardsReducerState
) => Promise<void>
@ -533,7 +544,7 @@ export type PutDashboardByIDDispatcher = (
export const putDashboardByID = (
dashboardID: number
): PutDashboardByIDThunk => async (
dispatch: Dispatch<ErrorThrownAction>,
dispatch: Dispatch<ErrorActions.ErrorThrownActionCreator>,
getState: () => DashboardsReducerState
): Promise<void> => {
try {
@ -586,7 +597,9 @@ export type AddDashboardCellDispatcher = (
type AddDashboardCellThunk = (
dispatch: Dispatch<
AddDashboardCellAction | ActionPublishNotification | ErrorThrownAction
| AddDashboardCellAction
| PublishNotificationActionCreator
| ErrorActions.ErrorThrownActionCreator
>
) => Promise<void>
@ -595,7 +608,9 @@ export const addDashboardCellAsync = (
cellType: CellType
): AddDashboardCellThunk => async (
dispatch: Dispatch<
AddDashboardCellAction | ActionPublishNotification | ErrorThrownAction
| AddDashboardCellAction
| PublishNotificationActionCreator
| ErrorActions.ErrorThrownActionCreator
>
): Promise<void> => {
try {
@ -789,7 +804,7 @@ interface AuthReducerState {
}
type SyncDashboardTempVarsFromURLQueryParamsDispatcher = (
dispatch: Dispatch<
ActionPublishNotification | TemplateVariableSelectedAction
PublishNotificationActionCreator | TemplateVariableSelectedAction
>,
getState: () => DashboardsReducerState & AuthReducerState
) => void
@ -798,7 +813,7 @@ const syncDashboardTempVarsFromURLQueryParams = (
urlQueryParams: URLQueryParams
): SyncDashboardTempVarsFromURLQueryParamsDispatcher => (
dispatch: Dispatch<
ActionPublishNotification | TemplateVariableSelectedAction
PublishNotificationActionCreator | TemplateVariableSelectedAction
>,
getState: () => DashboardsReducerState & AuthReducerState
): void => {
@ -838,7 +853,7 @@ interface DashTimeV1ReducerState {
}
type SyncDashboardTimeRangeFromURLQueryParamsDispatcher = (
dispatch: Dispatch<ActionPublishNotification>,
dispatch: Dispatch<PublishNotificationActionCreator>,
getState: () => DashboardsReducerState & DashTimeV1ReducerState
) => void
@ -847,7 +862,7 @@ const syncDashboardTimeRangeFromURLQueryParams = (
urlQueryParams: URLQueryParams,
location: Location
): SyncDashboardTimeRangeFromURLQueryParamsDispatcher => (
dispatch: Dispatch<ActionPublishNotification>,
dispatch: Dispatch<PublishNotificationActionCreator>,
getState: () => DashboardsReducerState & DashTimeV1ReducerState
): void => {
const {
@ -940,7 +955,7 @@ export type GetDashboardWithHydratedAndSyncedTempVarsAsyncDispatcher = (
) => GetDashboardWithHydratedAndSyncedTempVarsAsyncActionCreator
type GetDashboardWithHydratedAndSyncedTempVarsAsyncActionCreator = (
dispatch: Dispatch<ActionPublishNotification>
dispatch: Dispatch<PublishNotificationActionCreator>
) => Promise<void>
export const getDashboardWithHydratedAndSyncedTempVarsAsync = (
@ -949,7 +964,7 @@ export const getDashboardWithHydratedAndSyncedTempVarsAsync = (
router: InjectedRouter,
location: Location
): GetDashboardWithHydratedAndSyncedTempVarsAsyncActionCreator => async (
dispatch: Dispatch<ActionPublishNotification>
dispatch: Dispatch<PublishNotificationActionCreator>
): Promise<void> => {
const dashboard = await bindActionCreators(getDashboardAsync, dispatch)(
dashboardID

View File

@ -112,7 +112,7 @@ interface Props {
meRole: string
isUsingAuth: boolean
router: Router
notify: NotificationActions.ActionCreatorPublishNotification
notify: NotificationActions.PublishNotificationActionCreator
getAnnotationsAsync: AnnotationActions.GetAnnotationsDispatcher
handleShowCellEditorOverlay: CellEditorOverlayActions.ShowCellEditorOverlayActionCreator
handleHideCellEditorOverlay: CellEditorOverlayActions.HideCellEditorOverlayActionCreator

View File

@ -22,7 +22,9 @@ export const editingAnnotation = (): EditingAnnotationAction => ({
type: 'EDITING_ANNOTATION',
})
export interface DismissEditingAnnotationAction {
export type DismissEditingAnnotationActionCreator = () => DismissEditingAnnotationAction
interface DismissEditingAnnotationAction {
type: 'DISMISS_EDITING_ANNOTATION'
}
export const dismissEditingAnnotation = (): DismissEditingAnnotationAction => ({
@ -138,15 +140,16 @@ export interface AnnotationRange {
since: number
until: number
}
type GetAnnotationsThunk = (
dispatch: Dispatch<LoadAnnotationsAction>
) => Promise<void>
export type GetAnnotationsDispatcher = (
indexUrl: string,
annotationRange: AnnotationRange
) => GetAnnotationsThunk
type GetAnnotationsThunk = (
dispatch: Dispatch<LoadAnnotationsAction>
) => Promise<void>
export const getAnnotationsAsync = (
indexUrl: string,
{since, until}: AnnotationRange

View File

@ -6,7 +6,9 @@ import {notifyPresentationMode} from 'src/shared/copy/notifications'
import {Dispatch} from 'redux'
// ephemeral state action creators
export interface EnablePresentationModeAction {
export type EnablePresentationModeActionCreator = () => EnablePresentationModeAction
interface EnablePresentationModeAction {
type: 'ENABLE_PRESENTATION_MODE'
}
export const enablePresentationMode = (): EnablePresentationModeAction => ({
@ -29,7 +31,11 @@ export const delayEnablePresentationMode = async (
}, PRESENTATION_MODE_ANIMATION_DELAY)
// persistent state action creators
export interface SetAutoRefreshAction {
export type SetAutoRefreshActionCreator = (
milliseconds: number
) => SetAutoRefreshAction
interface SetAutoRefreshAction {
type: 'SET_AUTOREFRESH'
payload: {
milliseconds: number
@ -42,7 +48,9 @@ export const setAutoRefresh = (milliseconds: number): SetAutoRefreshAction => ({
},
})
export interface TemplateControlBarVisibilityToggledAction {
export type TemplateControlBarVisibilityToggledActionCreator = () => TemplateControlBarVisibilityToggledAction
interface TemplateControlBarVisibilityToggledAction {
type: 'TEMPLATE_CONTROL_BAR_VISIBILITY_TOGGLED'
}
export const templateControlBarVisibilityToggled = (): TemplateControlBarVisibilityToggledAction => ({

View File

@ -1,7 +1,14 @@
enum AlertType {
'info',
}
export interface ErrorThrownAction {
export type ErrorThrownActionCreator = (
error: Error,
altText?: string,
alertType?: AlertType
) => ErrorThrownAction
interface ErrorThrownAction {
type: 'ERROR_THROWN'
error: Error
altText?: string

View File

@ -1,19 +1,22 @@
import {Notification} from 'src/types'
export type Action = ActionPublishNotification | ActionDismissNotification
export type Action = PublishNotificationAction | ActionDismissNotification
// Publish notification
export type PublishNotification = (n: Notification) => ActionPublishNotification
export interface ActionPublishNotification {
export type PublishNotificationActionCreator = (
n: Notification
) => PublishNotificationAction
export interface PublishNotificationAction {
type: 'PUBLISH_NOTIFICATION'
payload: {
notification: Notification
}
}
export const notify = (
export const notify: PublishNotificationActionCreator = (
notification: Notification
): ActionPublishNotification => ({
): PublishNotificationAction => ({
type: 'PUBLISH_NOTIFICATION',
payload: {notification},
})

View File

@ -11,7 +11,7 @@ import {
} from 'src/shared/actions/sources'
import {
notify as notifyAction,
PublishNotification,
PublishNotificationActionCreator,
} from 'src/shared/actions/notifications'
import {connect} from 'react-redux'
@ -34,7 +34,7 @@ import {
import {ErrorHandling} from 'src/shared/decorators/errors'
interface Props extends WithRouterProps {
notify: PublishNotification
notify: PublishNotificationActionCreator
addSource: AddSource
updateSource: UpdateSource
}