diff --git a/ui/src/dashboards/containers/DashboardPage.tsx b/ui/src/dashboards/containers/DashboardPage.tsx index c6d10e7d49..bfe93fb7c6 100644 --- a/ui/src/dashboards/containers/DashboardPage.tsx +++ b/ui/src/dashboards/containers/DashboardPage.tsx @@ -61,7 +61,7 @@ import { } from 'src/types' import {DashboardName} from 'src/types/dashboard' import {ColorNumber, ColorString} from 'src/types/colors' -import * as AnnotationActions from 'src/shared/actions/annotations' +import * as AnnotationActions from 'src/types/actions/annotations' import * as AppActions from 'src/shared/actions/app' import * as CellEditorOverlayActions from 'src/dashboards/actions/cellEditorOverlay' import * as DashboardActions from 'src/types/actions/dashboard' diff --git a/ui/src/shared/actions/annotations.ts b/ui/src/shared/actions/annotations.ts index 25feab26a7..4f4eb18ede 100644 --- a/ui/src/shared/actions/annotations.ts +++ b/ui/src/shared/actions/annotations.ts @@ -1,125 +1,66 @@ import * as api from 'src/shared/apis/annotation' -import {AnnotationInterface} from 'src/types' import {Dispatch} from 'redux' +import * as AnnotationData from 'src/types/annotations' +import * as AnnotationActions from 'src/types/actions/annotations' -export type Action = - | EditingAnnotationAction - | DismissEditingAnnotationAction - | AddingAnnotationAction - | AddingAnnotationSuccessAction - | DismissAddingAnnotationAction - | MouseEnterTempAnnotationAction - | MouseLeaveTempAnnotationAction - | LoadAnnotationsAction - | UpdateAnnotationAction - | DeleteAnnotationAction - | AddAnnotationAction - -export interface EditingAnnotationAction { - type: 'EDITING_ANNOTATION' -} -export const editingAnnotation = (): EditingAnnotationAction => ({ +export const editingAnnotation = (): AnnotationActions.EditingAnnotationAction => ({ type: 'EDITING_ANNOTATION', }) -export type DismissEditingAnnotationActionCreator = () => DismissEditingAnnotationAction - -interface DismissEditingAnnotationAction { - type: 'DISMISS_EDITING_ANNOTATION' -} -export const dismissEditingAnnotation = (): DismissEditingAnnotationAction => ({ +export const dismissEditingAnnotation = (): AnnotationActions.DismissEditingAnnotationAction => ({ type: 'DISMISS_EDITING_ANNOTATION', }) -export interface AddingAnnotationAction { - type: 'ADDING_ANNOTATION' -} -export const addingAnnotation = (): AddingAnnotationAction => ({ +export const addingAnnotation = (): AnnotationActions.AddingAnnotationAction => ({ type: 'ADDING_ANNOTATION', }) -export interface AddingAnnotationSuccessAction { - type: 'ADDING_ANNOTATION_SUCCESS' -} -export const addingAnnotationSuccess = (): AddingAnnotationSuccessAction => ({ +export const addingAnnotationSuccess = (): AnnotationActions.AddingAnnotationSuccessAction => ({ type: 'ADDING_ANNOTATION_SUCCESS', }) -export interface DismissAddingAnnotationAction { - type: 'DISMISS_ADDING_ANNOTATION' -} -export const dismissAddingAnnotation = (): DismissAddingAnnotationAction => ({ +export const dismissAddingAnnotation = (): AnnotationActions.DismissAddingAnnotationAction => ({ type: 'DISMISS_ADDING_ANNOTATION', }) -export interface MouseEnterTempAnnotationAction { - type: 'MOUSEENTER_TEMP_ANNOTATION' -} -export const mouseEnterTempAnnotation = (): MouseEnterTempAnnotationAction => ({ +export const mouseEnterTempAnnotation = (): AnnotationActions.MouseEnterTempAnnotationAction => ({ type: 'MOUSEENTER_TEMP_ANNOTATION', }) -export interface MouseLeaveTempAnnotationAction { - type: 'MOUSELEAVE_TEMP_ANNOTATION' -} -export const mouseLeaveTempAnnotation = (): MouseLeaveTempAnnotationAction => ({ +export const mouseLeaveTempAnnotation = (): AnnotationActions.MouseLeaveTempAnnotationAction => ({ type: 'MOUSELEAVE_TEMP_ANNOTATION', }) -export interface LoadAnnotationsAction { - type: 'LOAD_ANNOTATIONS' - payload: { - annotations: AnnotationInterface[] - } -} export const loadAnnotations = ( - annotations: AnnotationInterface[] -): LoadAnnotationsAction => ({ + annotations: AnnotationData.AnnotationInterface[] +): AnnotationActions.LoadAnnotationsAction => ({ type: 'LOAD_ANNOTATIONS', payload: { annotations, }, }) -export interface UpdateAnnotationAction { - type: 'UPDATE_ANNOTATION' - payload: { - annotation: AnnotationInterface - } -} export const updateAnnotation = ( - annotation: AnnotationInterface -): UpdateAnnotationAction => ({ + annotation: AnnotationData.AnnotationInterface +): AnnotationActions.UpdateAnnotationAction => ({ type: 'UPDATE_ANNOTATION', payload: { annotation, }, }) -export interface DeleteAnnotationAction { - type: 'DELETE_ANNOTATION' - payload: { - annotation: AnnotationInterface - } -} export const deleteAnnotation = ( - annotation: AnnotationInterface -): DeleteAnnotationAction => ({ + annotation: AnnotationData.AnnotationInterface +): AnnotationActions.DeleteAnnotationAction => ({ type: 'DELETE_ANNOTATION', payload: { annotation, }, }) -export interface AddAnnotationAction { - type: 'ADD_ANNOTATION' - payload: { - annotation: AnnotationInterface - } -} export const addAnnotation = ( - annotation: AnnotationInterface -): AddAnnotationAction => ({ + annotation: AnnotationData.AnnotationInterface +): AnnotationActions.AddAnnotationAction => ({ type: 'ADD_ANNOTATION', payload: { annotation, @@ -128,7 +69,7 @@ export const addAnnotation = ( export const addAnnotationAsync = ( createUrl: string, - annotation: AnnotationInterface + annotation: AnnotationData.AnnotationInterface ) => async dispatch => { dispatch(addAnnotation(annotation)) const savedAnnotation = await api.createAnnotation(createUrl, annotation) @@ -136,39 +77,25 @@ export const addAnnotationAsync = ( dispatch(deleteAnnotation(annotation)) } -export interface AnnotationRange { - since: number - until: number -} - -export type GetAnnotationsDispatcher = ( +export const getAnnotationsAsync: AnnotationActions.GetAnnotationsDispatcher = ( indexUrl: string, - annotationRange: AnnotationRange -) => GetAnnotationsThunk - -type GetAnnotationsThunk = ( - dispatch: Dispatch -) => Promise - -export const getAnnotationsAsync: GetAnnotationsDispatcher = ( - indexUrl: string, - {since, until}: AnnotationRange -): GetAnnotationsThunk => async ( - dispatch: Dispatch + {since, until}: AnnotationData.AnnotationRange +): AnnotationActions.GetAnnotationsThunk => async ( + dispatch: Dispatch ): Promise => { const annotations = await api.getAnnotations(indexUrl, since, until) dispatch(loadAnnotations(annotations)) } export const deleteAnnotationAsync = ( - annotation: AnnotationInterface + annotation: AnnotationData.AnnotationInterface ) => async dispatch => { await api.deleteAnnotation(annotation) dispatch(deleteAnnotation(annotation)) } export const updateAnnotationAsync = ( - annotation: AnnotationInterface + annotation: AnnotationData.AnnotationInterface ) => async dispatch => { await api.updateAnnotation(annotation) dispatch(updateAnnotation(annotation)) diff --git a/ui/src/shared/components/Annotations.tsx b/ui/src/shared/components/Annotations.tsx index 6190530f93..31ff68a337 100644 --- a/ui/src/shared/components/Annotations.tsx +++ b/ui/src/shared/components/Annotations.tsx @@ -18,7 +18,7 @@ import {visibleAnnotations} from 'src/shared/annotations/helpers' import {ErrorHandling} from 'src/shared/decorators/errors' import {AnnotationInterface, DygraphClass, Source} from 'src/types' -import {UpdateAnnotationAction} from 'src/shared/actions/annotations' +import {UpdateAnnotationAction} from 'src/types/actions/annotations' interface Props { dWidth: number diff --git a/ui/src/shared/reducers/annotations.ts b/ui/src/shared/reducers/annotations.ts index f1c3ebb657..b8c0b29b23 100644 --- a/ui/src/shared/reducers/annotations.ts +++ b/ui/src/shared/reducers/annotations.ts @@ -1,6 +1,6 @@ import {ADDING, EDITING, TEMP_ANNOTATION} from 'src/shared/annotations/helpers' -import {Action} from 'src/shared/actions/annotations' +import {Action} from 'src/types/actions/annotations' import {AnnotationInterface} from 'src/types' export interface AnnotationState { diff --git a/ui/src/types/actions/annotations.ts b/ui/src/types/actions/annotations.ts new file mode 100644 index 0000000000..12f99f0546 --- /dev/null +++ b/ui/src/types/actions/annotations.ts @@ -0,0 +1,82 @@ +import {Dispatch} from 'redux' +import * as AnnotationData from 'src/types/annotations' + +export type Action = + | EditingAnnotationAction + | DismissEditingAnnotationAction + | AddingAnnotationAction + | AddingAnnotationSuccessAction + | DismissAddingAnnotationAction + | MouseEnterTempAnnotationAction + | MouseLeaveTempAnnotationAction + | LoadAnnotationsAction + | UpdateAnnotationAction + | DeleteAnnotationAction + | AddAnnotationAction + +export interface EditingAnnotationAction { + type: 'EDITING_ANNOTATION' +} + +export type DismissEditingAnnotationActionCreator = () => DismissEditingAnnotationAction + +export interface DismissEditingAnnotationAction { + type: 'DISMISS_EDITING_ANNOTATION' +} + +export interface AddingAnnotationAction { + type: 'ADDING_ANNOTATION' +} + +export interface AddingAnnotationSuccessAction { + type: 'ADDING_ANNOTATION_SUCCESS' +} + +export interface DismissAddingAnnotationAction { + type: 'DISMISS_ADDING_ANNOTATION' +} + +export interface MouseEnterTempAnnotationAction { + type: 'MOUSEENTER_TEMP_ANNOTATION' +} + +export interface MouseLeaveTempAnnotationAction { + type: 'MOUSELEAVE_TEMP_ANNOTATION' +} + +export interface LoadAnnotationsAction { + type: 'LOAD_ANNOTATIONS' + payload: { + annotations: AnnotationData.AnnotationInterface[] + } +} + +export interface UpdateAnnotationAction { + type: 'UPDATE_ANNOTATION' + payload: { + annotation: AnnotationData.AnnotationInterface + } +} + +export interface DeleteAnnotationAction { + type: 'DELETE_ANNOTATION' + payload: { + annotation: AnnotationData.AnnotationInterface + } +} + +export interface AddAnnotationAction { + type: 'ADD_ANNOTATION' + payload: { + annotation: AnnotationData.AnnotationInterface + } +} + +export type GetAnnotationsDispatcher = ( + indexUrl: string, + annotationRange: AnnotationData.AnnotationRange +) => GetAnnotationsThunk + +export type GetAnnotationsThunk = ( + dispatch: Dispatch +) => Promise diff --git a/ui/src/types/annotations.ts b/ui/src/types/annotations.ts index e35bb06285..595a641814 100644 --- a/ui/src/types/annotations.ts +++ b/ui/src/types/annotations.ts @@ -6,3 +6,8 @@ export interface AnnotationInterface { type: string links: {self: string} } + +export interface AnnotationRange { + since: number + until: number +}