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 | ChangeDecimalPlacesAction
| UpdateFieldOptionsAction | UpdateFieldOptionsAction
export interface ShowCellEditorOverlayAction { export type ShowCellEditorOverlayActionCreator = (
cell: Cell
) => ShowCellEditorOverlayAction
interface ShowCellEditorOverlayAction {
type: 'SHOW_CELL_EDITOR_OVERLAY' type: 'SHOW_CELL_EDITOR_OVERLAY'
payload: { payload: {
cell: Cell cell: Cell
} }
} }
export const showCellEditorOverlay = ( export const showCellEditorOverlay: ShowCellEditorOverlayActionCreator = (
cell: Cell cell: Cell
): ShowCellEditorOverlayAction => ({ ): ShowCellEditorOverlayAction => ({
type: 'SHOW_CELL_EDITOR_OVERLAY', 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' type: 'HIDE_CELL_EDITOR_OVERLAY'
} }
export const hideCellEditorOverlay = (): HideCellEditorOverlayAction => ({ export const hideCellEditorOverlay = (): HideCellEditorOverlayAction => ({

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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