Refactor annotations types file structure & imports to new style
parent
e23049946c
commit
a0b2ee4aea
|
@ -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'
|
||||
|
|
|
@ -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<LoadAnnotationsAction>
|
||||
) => Promise<void>
|
||||
|
||||
export const getAnnotationsAsync: GetAnnotationsDispatcher = (
|
||||
indexUrl: string,
|
||||
{since, until}: AnnotationRange
|
||||
): GetAnnotationsThunk => async (
|
||||
dispatch: Dispatch<LoadAnnotationsAction>
|
||||
{since, until}: AnnotationData.AnnotationRange
|
||||
): AnnotationActions.GetAnnotationsThunk => async (
|
||||
dispatch: Dispatch<AnnotationActions.LoadAnnotationsAction>
|
||||
): Promise<void> => {
|
||||
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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>
|
|
@ -6,3 +6,8 @@ export interface AnnotationInterface {
|
|||
type: string
|
||||
links: {self: string}
|
||||
}
|
||||
|
||||
export interface AnnotationRange {
|
||||
since: number
|
||||
until: number
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue