From 9a5dfcb57d2c0cf089e345b586edfdd7d401bf2e Mon Sep 17 00:00:00 2001 From: Jared Scheib Date: Sat, 23 Jun 2018 12:54:24 -0700 Subject: [PATCH] Create global Types module & consume in DashboardPage for single import --- .../dashboards/containers/DashboardPage.tsx | 114 +++++++++--------- ui/src/types/modules/annotations.ts | 3 + ui/src/types/modules/app.ts | 3 + ui/src/types/modules/cellEditorOverlay.ts | 3 + ui/src/types/modules/colors.ts | 3 + ui/src/types/modules/dashboards.ts | 6 + ui/src/types/modules/errors.ts | 3 + ui/src/types/modules/index.ts | 23 ++++ ui/src/types/modules/notifications.ts | 3 + ui/src/types/modules/queries.ts | 3 + ui/src/types/modules/sources.ts | 3 + ui/src/types/modules/tempVars.ts | 3 + 12 files changed, 111 insertions(+), 59 deletions(-) create mode 100644 ui/src/types/modules/annotations.ts create mode 100644 ui/src/types/modules/app.ts create mode 100644 ui/src/types/modules/cellEditorOverlay.ts create mode 100644 ui/src/types/modules/colors.ts create mode 100644 ui/src/types/modules/dashboards.ts create mode 100644 ui/src/types/modules/errors.ts create mode 100644 ui/src/types/modules/index.ts create mode 100644 ui/src/types/modules/notifications.ts create mode 100644 ui/src/types/modules/queries.ts create mode 100644 ui/src/types/modules/sources.ts create mode 100644 ui/src/types/modules/tempVars.ts diff --git a/ui/src/dashboards/containers/DashboardPage.tsx b/ui/src/dashboards/containers/DashboardPage.tsx index 17bd703392..2ed19f9907 100644 --- a/ui/src/dashboards/containers/DashboardPage.tsx +++ b/ui/src/dashboards/containers/DashboardPage.tsx @@ -41,82 +41,72 @@ import {WithRouterProps} from 'react-router' import {ManualRefreshProps} from 'src/shared/components/ManualRefresh' import {Location} from 'history' import {InjectedRouter} from 'react-router' -import * as SourceData from 'src/types/sources' -import * as TempVarData from 'src/types/tempVars' -import * as DashboardData from 'src/types/dashboards' -import * as QueryData from 'src/types/query' -import * as ColorData from 'src/types/colors' -import * as AnnotationActions from 'src/types/actions/annotations' -import * as AppActions from 'src/types/actions/app' -import * as CellEditorOverlayActions from 'src/types/actions/cellEditorOverlay' -import * as DashboardActions from 'src/types/actions/dashboards' -import * as ErrorActions from 'src/types/actions/errors' -import * as NotificationActions from 'src/types/actions/notifications' +import * as Types from 'src/types/modules' interface DashboardActions { - setDashTimeV1: DashboardActions.SetDashTimeV1ActionCreator - updateDashboard: DashboardActions.UpdateDashboardActionCreator - syncURLQueryParamsFromQueryParamsObject: DashboardActions.SyncURLQueryFromQueryParamsObjectDispatcher - putDashboard: DashboardActions.PutDashboardDispatcher - putDashboardByID: DashboardActions.PutDashboardByIDDispatcher - getDashboardsNamesAsync: DashboardActions.GetDashboardsNamesDispatcher - getDashboardWithHydratedAndSyncedTempVarsAsync: DashboardActions.GetDashboardWithHydratedAndSyncedTempVarsAsyncDispatcher - setTimeRange: DashboardActions.SetTimeRangeActionCreator - addDashboardCellAsync: DashboardActions.AddDashboardCellDispatcher - editCellQueryStatus: DashboardActions.EditCellQueryStatusActionCreator - updateDashboardCell: DashboardActions.UpdateDashboardCellDispatcher - cloneDashboardCellAsync: DashboardActions.CloneDashboardCellDispatcher - deleteDashboardCellAsync: DashboardActions.DeleteDashboardCellDispatcher - templateVariableSelected: DashboardActions.TemplateVariableSelectedActionCreator - syncURLQueryFromTempVars: DashboardActions.SyncURLQueryFromTempVarsDispatcher - setZoomedTimeRangeAsync: DashboardActions.SetZoomedTimeRangeDispatcher + setDashTimeV1: Types.Dashboards.Actions.SetDashTimeV1ActionCreator + updateDashboard: Types.Dashboards.Actions.UpdateDashboardActionCreator + syncURLQueryParamsFromQueryParamsObject: Types.Dashboards.Actions.SyncURLQueryFromQueryParamsObjectDispatcher + putDashboard: Types.Dashboards.Actions.PutDashboardDispatcher + putDashboardByID: Types.Dashboards.Actions.PutDashboardByIDDispatcher + getDashboardsNamesAsync: Types.Dashboards.Actions.GetDashboardsNamesDispatcher + getDashboardWithHydratedAndSyncedTempVarsAsync: Types.Dashboards.Actions.GetDashboardWithHydratedAndSyncedTempVarsAsyncDispatcher + setTimeRange: Types.Dashboards.Actions.SetTimeRangeActionCreator + addDashboardCellAsync: Types.Dashboards.Actions.AddDashboardCellDispatcher + editCellQueryStatus: Types.Dashboards.Actions.EditCellQueryStatusActionCreator + updateDashboardCell: Types.Dashboards.Actions.UpdateDashboardCellDispatcher + cloneDashboardCellAsync: Types.Dashboards.Actions.CloneDashboardCellDispatcher + deleteDashboardCellAsync: Types.Dashboards.Actions.DeleteDashboardCellDispatcher + templateVariableSelected: Types.Dashboards.Actions.TemplateVariableSelectedActionCreator + syncURLQueryFromTempVars: Types.Dashboards.Actions.SyncURLQueryFromTempVarsDispatcher + setZoomedTimeRangeAsync: Types.Dashboards.Actions.SetZoomedTimeRangeDispatcher } interface Props extends DashboardActions, ManualRefreshProps, WithRouterProps { - source: SourceData.Source - sources: SourceData.Source[] + source: Types.Sources.Data.Source + sources: Types.Sources.Data.Source[] params: { sourceID: string dashboardID: string } location: Location dashboardID: number - dashboard: DashboardData.Dashboard - dashboards: DashboardData.Dashboard[] - handleChooseAutoRefresh: AppActions.SetAutoRefreshActionCreator + dashboard: Types.Dashboards.Data.Dashboard + dashboards: Types.Dashboards.Data.Dashboard[] + handleChooseAutoRefresh: Types.App.Actions.SetAutoRefreshActionCreator autoRefresh: number - templateControlBarVisibilityToggled: () => AppActions.TemplateControlBarVisibilityToggledActionCreator - timeRange: QueryData.TimeRange - zoomedTimeRange: QueryData.TimeRange + templateControlBarVisibilityToggled: () => Types.App.Actions.TemplateControlBarVisibilityToggledActionCreator + timeRange: Types.Queries.Data.TimeRange + zoomedTimeRange: Types.Queries.Data.TimeRange showTemplateControlBar: boolean inPresentationMode: boolean - handleClickPresentationButton: AppActions.DelayEnablePresentationModeDispatcher + handleClickPresentationButton: Types.App.Actions.DelayEnablePresentationModeDispatcher cellQueryStatus: { queryID: string status: object } - errorThrown: ErrorActions.ErrorThrownActionCreator + errorThrown: Types.Errors.Actions.ErrorThrownActionCreator meRole: string isUsingAuth: boolean router: InjectedRouter - notify: NotificationActions.PublishNotificationActionCreator - getAnnotationsAsync: AnnotationActions.GetAnnotationsDispatcher - handleShowCellEditorOverlay: CellEditorOverlayActions.ShowCellEditorOverlayActionCreator - handleHideCellEditorOverlay: CellEditorOverlayActions.HideCellEditorOverlayActionCreator - handleDismissEditingAnnotation: AnnotationActions.DismissEditingAnnotationActionCreator - selectedCell: DashboardData.Cell + notify: Types.Notifications.Actions.PublishNotificationActionCreator + getAnnotationsAsync: Types.Annotations.Actions.GetAnnotationsDispatcher + handleShowCellEditorOverlay: Types.CellEditorOverlay.Actions.ShowCellEditorOverlayActionCreator + handleHideCellEditorOverlay: Types.CellEditorOverlay.Actions.HideCellEditorOverlayActionCreator + handleDismissEditingAnnotation: Types.Annotations.Actions.DismissEditingAnnotationActionCreator + selectedCell: Types.Dashboards.Data.Cell thresholdsListType: string - thresholdsListColors: ColorData.ColorNumber[] - gaugeColors: ColorData.ColorNumber[] - lineColors: ColorData.ColorString[] + thresholdsListColors: Types.Colors.Data.ColorNumber[] + gaugeColors: Types.Colors.Data.ColorNumber[] + lineColors: Types.Colors.Data.ColorString[] } interface State { isEditMode: boolean - selectedCell: DashboardData.Cell | null + selectedCell: Types.Dashboards.Data.Cell | null scrollTop: number windowHeight: number - dashboardsNames: DashboardData.DashboardName[] + dashboardsNames: Types.Dashboards.Data.DashboardName[] } @ErrorHandling @@ -353,7 +343,7 @@ class DashboardPage extends Component { } private getDashboard = async (): Promise< - DashboardActions.GetDashboardWithHydratedAndSyncedTempVarsAsyncThunk + Types.Dashboards.Actions.GetDashboardWithHydratedAndSyncedTempVarsAsyncThunk > => { const {dashboardID, source, router, location} = this.props @@ -378,7 +368,7 @@ class DashboardPage extends Component { this.setState({dashboardsNames}) } - private inView = (cell: DashboardData.Cell): boolean => { + private inView = (cell: Types.Dashboards.Data.Cell): boolean => { const {scrollTop, windowHeight} = this.state const bufferValue = 600 const cellTop = cell.y * DASHBOARD_LAYOUT_ROW_HEIGHT @@ -392,14 +382,16 @@ class DashboardPage extends Component { } private handleSaveEditedCell = async ( - newCell: DashboardData.Cell + newCell: Types.Dashboards.Data.Cell ): Promise => { const {dashboard, handleHideCellEditorOverlay} = this.props await this.props.updateDashboardCell(dashboard, newCell) handleHideCellEditorOverlay() } - private handleChooseTimeRange = (timeRange: QueryData.TimeRange): void => { + private handleChooseTimeRange = ( + timeRange: Types.Queries.Data.TimeRange + ): void => { const { dashboard, @@ -422,7 +414,9 @@ class DashboardPage extends Component { getAnnotationsAsync(source.links.annotations, annotationRange) } - private handleUpdatePosition = (cells: DashboardData.Cell[]): void => { + private handleUpdatePosition = ( + cells: Types.Dashboards.Data.Cell[] + ): void => { const {dashboard, meRole, isUsingAuth} = this.props const newDashboard = {...dashboard, cells} @@ -440,7 +434,7 @@ class DashboardPage extends Component { this.props.addDashboardCellAsync(dashboard) } - private handleCloneCell = (cell: DashboardData.Cell): void => { + private handleCloneCell = (cell: Types.Dashboards.Data.Cell): void => { const {dashboard} = this.props this.props.cloneDashboardCellAsync(dashboard, cell) } @@ -463,15 +457,17 @@ class DashboardPage extends Component { this.getDashboardsNames() } - private handleDeleteDashboardCell = (cell: DashboardData.Cell): void => { + private handleDeleteDashboardCell = ( + cell: Types.Dashboards.Data.Cell + ): void => { const {dashboard} = this.props this.props.deleteDashboardCellAsync(dashboard, cell) } private handleSelectTemplate = ( templateID: string - ): ((value: TempVarData.TemplateValue) => void) => ( - value: TempVarData.TemplateValue + ): ((value: Types.TempVars.Data.TemplateValue) => void) => ( + value: Types.TempVars.Data.TemplateValue ): void => { const {dashboard, dashboardID, location} = this.props @@ -495,7 +491,7 @@ class DashboardPage extends Component { } private handleSaveTemplateVariables = async ( - templates: TempVarData.Template[] + templates: Types.TempVars.Data.Template[] ): Promise => { const {location, dashboard} = this.props @@ -519,7 +515,7 @@ class DashboardPage extends Component { } private handleZoomedTimeRange = ( - zoomedTimeRange: QueryData.TimeRange + zoomedTimeRange: Types.Queries.Data.TimeRange ): void => { const {location} = this.props this.props.setZoomedTimeRangeAsync(zoomedTimeRange, location) diff --git a/ui/src/types/modules/annotations.ts b/ui/src/types/modules/annotations.ts new file mode 100644 index 0000000000..ca5d216b7a --- /dev/null +++ b/ui/src/types/modules/annotations.ts @@ -0,0 +1,3 @@ +import * as Actions from 'src/types/actions/annotations' + +export {Actions} diff --git a/ui/src/types/modules/app.ts b/ui/src/types/modules/app.ts new file mode 100644 index 0000000000..40444116cb --- /dev/null +++ b/ui/src/types/modules/app.ts @@ -0,0 +1,3 @@ +import * as Actions from 'src/types/actions/app' + +export {Actions} diff --git a/ui/src/types/modules/cellEditorOverlay.ts b/ui/src/types/modules/cellEditorOverlay.ts new file mode 100644 index 0000000000..c7515f387b --- /dev/null +++ b/ui/src/types/modules/cellEditorOverlay.ts @@ -0,0 +1,3 @@ +import * as Actions from 'src/types/actions/cellEditorOverlay' + +export {Actions} diff --git a/ui/src/types/modules/colors.ts b/ui/src/types/modules/colors.ts new file mode 100644 index 0000000000..1efb057641 --- /dev/null +++ b/ui/src/types/modules/colors.ts @@ -0,0 +1,3 @@ +import * as Data from 'src/types/colors' + +export {Data} diff --git a/ui/src/types/modules/dashboards.ts b/ui/src/types/modules/dashboards.ts new file mode 100644 index 0000000000..3d5653cae0 --- /dev/null +++ b/ui/src/types/modules/dashboards.ts @@ -0,0 +1,6 @@ +import * as Data from 'src/types/dashboards' +import * as Actions from 'src/types/actions/dashboards' +import * as Apis from 'src/types/apis/dashboard' +import * as Reducers from 'src/types/reducers/dashboards' + +export {Data, Actions, Apis, Reducers} diff --git a/ui/src/types/modules/errors.ts b/ui/src/types/modules/errors.ts new file mode 100644 index 0000000000..a360b7c560 --- /dev/null +++ b/ui/src/types/modules/errors.ts @@ -0,0 +1,3 @@ +import * as Actions from 'src/types/actions/errors' + +export {Actions} diff --git a/ui/src/types/modules/index.ts b/ui/src/types/modules/index.ts new file mode 100644 index 0000000000..8b19214c38 --- /dev/null +++ b/ui/src/types/modules/index.ts @@ -0,0 +1,23 @@ +import * as Sources from 'src/types/modules/sources' +import * as Dashboards from 'src/types/modules/dashboards' +import * as TempVars from 'src/types/modules/tempVars' +import * as Queries from 'src/types/modules/queries' +import * as Colors from 'src/types/modules/colors' +import * as Annotations from 'src/types/modules/annotations' +import * as App from 'src/types/modules/app' +import * as CellEditorOverlay from 'src/types/modules/cellEditorOverlay' +import * as Errors from 'src/types/modules/errors' +import * as Notifications from 'src/types/modules/notifications' + +export { + Sources, + Dashboards, + TempVars, + Queries, + Colors, + Annotations, + App, + CellEditorOverlay, + Errors, + Notifications, +} diff --git a/ui/src/types/modules/notifications.ts b/ui/src/types/modules/notifications.ts new file mode 100644 index 0000000000..f73f6d9dc3 --- /dev/null +++ b/ui/src/types/modules/notifications.ts @@ -0,0 +1,3 @@ +import * as Actions from 'src/types/actions/notifications' + +export {Actions} diff --git a/ui/src/types/modules/queries.ts b/ui/src/types/modules/queries.ts new file mode 100644 index 0000000000..6478f29538 --- /dev/null +++ b/ui/src/types/modules/queries.ts @@ -0,0 +1,3 @@ +import * as Data from 'src/types/query' + +export {Data} diff --git a/ui/src/types/modules/sources.ts b/ui/src/types/modules/sources.ts new file mode 100644 index 0000000000..297fb23c1e --- /dev/null +++ b/ui/src/types/modules/sources.ts @@ -0,0 +1,3 @@ +import * as Data from 'src/types/sources' + +export {Data} diff --git a/ui/src/types/modules/tempVars.ts b/ui/src/types/modules/tempVars.ts new file mode 100644 index 0000000000..21a65c818c --- /dev/null +++ b/ui/src/types/modules/tempVars.ts @@ -0,0 +1,3 @@ +import * as Data from 'src/types/tempVars' + +export {Data}