Refactor annotations types file structure & imports to new style

pull/10616/head
Jared Scheib 2018-06-22 18:02:06 -07:00
parent e23049946c
commit a0b2ee4aea
6 changed files with 114 additions and 100 deletions

View File

@ -61,7 +61,7 @@ import {
} from 'src/types' } from 'src/types'
import {DashboardName} from 'src/types/dashboard' import {DashboardName} from 'src/types/dashboard'
import {ColorNumber, ColorString} from 'src/types/colors' 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 AppActions from 'src/shared/actions/app'
import * as CellEditorOverlayActions from 'src/dashboards/actions/cellEditorOverlay' import * as CellEditorOverlayActions from 'src/dashboards/actions/cellEditorOverlay'
import * as DashboardActions from 'src/types/actions/dashboard' import * as DashboardActions from 'src/types/actions/dashboard'

View File

@ -1,125 +1,66 @@
import * as api from 'src/shared/apis/annotation' import * as api from 'src/shared/apis/annotation'
import {AnnotationInterface} from 'src/types'
import {Dispatch} from 'redux' import {Dispatch} from 'redux'
import * as AnnotationData from 'src/types/annotations'
import * as AnnotationActions from 'src/types/actions/annotations'
export type Action = export const editingAnnotation = (): AnnotationActions.EditingAnnotationAction => ({
| EditingAnnotationAction
| DismissEditingAnnotationAction
| AddingAnnotationAction
| AddingAnnotationSuccessAction
| DismissAddingAnnotationAction
| MouseEnterTempAnnotationAction
| MouseLeaveTempAnnotationAction
| LoadAnnotationsAction
| UpdateAnnotationAction
| DeleteAnnotationAction
| AddAnnotationAction
export interface EditingAnnotationAction {
type: 'EDITING_ANNOTATION'
}
export const editingAnnotation = (): EditingAnnotationAction => ({
type: 'EDITING_ANNOTATION', type: 'EDITING_ANNOTATION',
}) })
export type DismissEditingAnnotationActionCreator = () => DismissEditingAnnotationAction export const dismissEditingAnnotation = (): AnnotationActions.DismissEditingAnnotationAction => ({
interface DismissEditingAnnotationAction {
type: 'DISMISS_EDITING_ANNOTATION'
}
export const dismissEditingAnnotation = (): DismissEditingAnnotationAction => ({
type: 'DISMISS_EDITING_ANNOTATION', type: 'DISMISS_EDITING_ANNOTATION',
}) })
export interface AddingAnnotationAction { export const addingAnnotation = (): AnnotationActions.AddingAnnotationAction => ({
type: 'ADDING_ANNOTATION'
}
export const addingAnnotation = (): AddingAnnotationAction => ({
type: 'ADDING_ANNOTATION', type: 'ADDING_ANNOTATION',
}) })
export interface AddingAnnotationSuccessAction { export const addingAnnotationSuccess = (): AnnotationActions.AddingAnnotationSuccessAction => ({
type: 'ADDING_ANNOTATION_SUCCESS'
}
export const addingAnnotationSuccess = (): AddingAnnotationSuccessAction => ({
type: 'ADDING_ANNOTATION_SUCCESS', type: 'ADDING_ANNOTATION_SUCCESS',
}) })
export interface DismissAddingAnnotationAction { export const dismissAddingAnnotation = (): AnnotationActions.DismissAddingAnnotationAction => ({
type: 'DISMISS_ADDING_ANNOTATION'
}
export const dismissAddingAnnotation = (): DismissAddingAnnotationAction => ({
type: 'DISMISS_ADDING_ANNOTATION', type: 'DISMISS_ADDING_ANNOTATION',
}) })
export interface MouseEnterTempAnnotationAction { export const mouseEnterTempAnnotation = (): AnnotationActions.MouseEnterTempAnnotationAction => ({
type: 'MOUSEENTER_TEMP_ANNOTATION'
}
export const mouseEnterTempAnnotation = (): MouseEnterTempAnnotationAction => ({
type: 'MOUSEENTER_TEMP_ANNOTATION', type: 'MOUSEENTER_TEMP_ANNOTATION',
}) })
export interface MouseLeaveTempAnnotationAction { export const mouseLeaveTempAnnotation = (): AnnotationActions.MouseLeaveTempAnnotationAction => ({
type: 'MOUSELEAVE_TEMP_ANNOTATION'
}
export const mouseLeaveTempAnnotation = (): MouseLeaveTempAnnotationAction => ({
type: 'MOUSELEAVE_TEMP_ANNOTATION', type: 'MOUSELEAVE_TEMP_ANNOTATION',
}) })
export interface LoadAnnotationsAction {
type: 'LOAD_ANNOTATIONS'
payload: {
annotations: AnnotationInterface[]
}
}
export const loadAnnotations = ( export const loadAnnotations = (
annotations: AnnotationInterface[] annotations: AnnotationData.AnnotationInterface[]
): LoadAnnotationsAction => ({ ): AnnotationActions.LoadAnnotationsAction => ({
type: 'LOAD_ANNOTATIONS', type: 'LOAD_ANNOTATIONS',
payload: { payload: {
annotations, annotations,
}, },
}) })
export interface UpdateAnnotationAction {
type: 'UPDATE_ANNOTATION'
payload: {
annotation: AnnotationInterface
}
}
export const updateAnnotation = ( export const updateAnnotation = (
annotation: AnnotationInterface annotation: AnnotationData.AnnotationInterface
): UpdateAnnotationAction => ({ ): AnnotationActions.UpdateAnnotationAction => ({
type: 'UPDATE_ANNOTATION', type: 'UPDATE_ANNOTATION',
payload: { payload: {
annotation, annotation,
}, },
}) })
export interface DeleteAnnotationAction {
type: 'DELETE_ANNOTATION'
payload: {
annotation: AnnotationInterface
}
}
export const deleteAnnotation = ( export const deleteAnnotation = (
annotation: AnnotationInterface annotation: AnnotationData.AnnotationInterface
): DeleteAnnotationAction => ({ ): AnnotationActions.DeleteAnnotationAction => ({
type: 'DELETE_ANNOTATION', type: 'DELETE_ANNOTATION',
payload: { payload: {
annotation, annotation,
}, },
}) })
export interface AddAnnotationAction {
type: 'ADD_ANNOTATION'
payload: {
annotation: AnnotationInterface
}
}
export const addAnnotation = ( export const addAnnotation = (
annotation: AnnotationInterface annotation: AnnotationData.AnnotationInterface
): AddAnnotationAction => ({ ): AnnotationActions.AddAnnotationAction => ({
type: 'ADD_ANNOTATION', type: 'ADD_ANNOTATION',
payload: { payload: {
annotation, annotation,
@ -128,7 +69,7 @@ export const addAnnotation = (
export const addAnnotationAsync = ( export const addAnnotationAsync = (
createUrl: string, createUrl: string,
annotation: AnnotationInterface annotation: AnnotationData.AnnotationInterface
) => async dispatch => { ) => async dispatch => {
dispatch(addAnnotation(annotation)) dispatch(addAnnotation(annotation))
const savedAnnotation = await api.createAnnotation(createUrl, annotation) const savedAnnotation = await api.createAnnotation(createUrl, annotation)
@ -136,39 +77,25 @@ export const addAnnotationAsync = (
dispatch(deleteAnnotation(annotation)) dispatch(deleteAnnotation(annotation))
} }
export interface AnnotationRange { export const getAnnotationsAsync: AnnotationActions.GetAnnotationsDispatcher = (
since: number
until: number
}
export type GetAnnotationsDispatcher = (
indexUrl: string, indexUrl: string,
annotationRange: AnnotationRange {since, until}: AnnotationData.AnnotationRange
) => GetAnnotationsThunk ): AnnotationActions.GetAnnotationsThunk => async (
dispatch: Dispatch<AnnotationActions.LoadAnnotationsAction>
type GetAnnotationsThunk = (
dispatch: Dispatch<LoadAnnotationsAction>
) => Promise<void>
export const getAnnotationsAsync: GetAnnotationsDispatcher = (
indexUrl: string,
{since, until}: AnnotationRange
): GetAnnotationsThunk => async (
dispatch: Dispatch<LoadAnnotationsAction>
): Promise<void> => { ): Promise<void> => {
const annotations = await api.getAnnotations(indexUrl, since, until) const annotations = await api.getAnnotations(indexUrl, since, until)
dispatch(loadAnnotations(annotations)) dispatch(loadAnnotations(annotations))
} }
export const deleteAnnotationAsync = ( export const deleteAnnotationAsync = (
annotation: AnnotationInterface annotation: AnnotationData.AnnotationInterface
) => async dispatch => { ) => async dispatch => {
await api.deleteAnnotation(annotation) await api.deleteAnnotation(annotation)
dispatch(deleteAnnotation(annotation)) dispatch(deleteAnnotation(annotation))
} }
export const updateAnnotationAsync = ( export const updateAnnotationAsync = (
annotation: AnnotationInterface annotation: AnnotationData.AnnotationInterface
) => async dispatch => { ) => async dispatch => {
await api.updateAnnotation(annotation) await api.updateAnnotation(annotation)
dispatch(updateAnnotation(annotation)) dispatch(updateAnnotation(annotation))

View File

@ -18,7 +18,7 @@ import {visibleAnnotations} from 'src/shared/annotations/helpers'
import {ErrorHandling} from 'src/shared/decorators/errors' import {ErrorHandling} from 'src/shared/decorators/errors'
import {AnnotationInterface, DygraphClass, Source} from 'src/types' import {AnnotationInterface, DygraphClass, Source} from 'src/types'
import {UpdateAnnotationAction} from 'src/shared/actions/annotations' import {UpdateAnnotationAction} from 'src/types/actions/annotations'
interface Props { interface Props {
dWidth: number dWidth: number

View File

@ -1,6 +1,6 @@
import {ADDING, EDITING, TEMP_ANNOTATION} from 'src/shared/annotations/helpers' 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' import {AnnotationInterface} from 'src/types'
export interface AnnotationState { export interface AnnotationState {

View File

@ -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<LoadAnnotationsAction>
) => Promise<void>

View File

@ -6,3 +6,8 @@ export interface AnnotationInterface {
type: string type: string
links: {self: string} links: {self: string}
} }
export interface AnnotationRange {
since: number
until: number
}