deleteAnnotationAsync from tooltip

pull/2829/head
Luke Morris 2018-02-19 16:21:43 -08:00
parent 4e91f21c9b
commit d059314556
5 changed files with 21 additions and 22 deletions

View File

@ -67,3 +67,8 @@ export const getAnnotationsAsync = (indexUrl, since) => async dispatch => {
const annotations = await api.getAnnotations(indexUrl, since)
annotations.forEach(a => dispatch(addAnnotation(a)))
}
export const deleteAnnotationAsync = annotation => async dispatch => {
await api.deleteAnnotation(annotation)
dispatch(deleteAnnotation(annotation))
}

View File

@ -27,3 +27,8 @@ export const getAnnotations = async (url, since) => {
})
return data.annotations.map(annoToMillisecond)
}
export const deleteAnnotation = async annotation => {
const url = annotation.links.self
await AJAX({method: 'DELETE', url})
}

View File

@ -122,18 +122,6 @@ class Annotation extends Component {
onUpdateAnnotation(annotation)
}
handleDeleteAnnotation = () => {
const {annotation, annotations, onDeleteAnnotation} = this.props
if (this.isEndpoint()) {
const startAnnotation = annotations.find(a => a.id === this.getStartID())
return onDeleteAnnotation(startAnnotation)
}
return onDeleteAnnotation(annotation)
}
render() {
const {dygraph, annotation, mode} = this.props
const {isDragging, isMouseOver} = this.state
@ -176,7 +164,6 @@ class Annotation extends Component {
onMouseLeave={this.handleMouseLeave}
annotationState={this.state}
onConfirmUpdate={this.handleConfirmUpdate}
onDelete={this.handleDeleteAnnotation}
/>
</div>
)
@ -191,7 +178,6 @@ Annotation.propTypes = {
annotation: schema.annotation.isRequired,
dygraph: shape({}).isRequired,
onUpdateAnnotation: func.isRequired,
onDeleteAnnotation: func.isRequired,
}
export default Annotation

View File

@ -1,8 +1,10 @@
import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import moment from 'moment'
import AnnotationInput from 'src/shared/components/AnnotationInput'
import * as schema from 'shared/schemas'
import * as actions from 'shared/actions/annotations'
import {
tooltipStyle,
@ -35,6 +37,10 @@ class AnnotationTooltip extends Component {
this.setState({annotation: this.props.annotation})
}
handleDelete = () => {
this.props.deleteAnnotationAsync(this.props.annotation)
}
render() {
const {annotation} = this.state
const {
@ -57,7 +63,7 @@ class AnnotationTooltip extends Component {
{isEditing &&
<button
className="annotation-tooltip--delete"
onClick={this.props.onDelete}
onClick={this.handleDelete}
>
<span className="icon remove" />
</button>}
@ -89,7 +95,9 @@ AnnotationTooltip.propTypes = {
onMouseLeave: func.isRequired,
annotationState: shape({}),
onConfirmUpdate: func.isRequired,
onDelete: func.isRequired,
deleteAnnotationAsync: func.isRequired,
}
export default AnnotationTooltip
export default connect(null, {
deleteAnnotationAsync: actions.deleteAnnotationAsync,
})(AnnotationTooltip)

View File

@ -11,7 +11,6 @@ import {ADDING, TEMP_ANNOTATION} from 'src/shared/annotations/helpers'
import {
updateAnnotation,
deleteAnnotation,
addingAnnotationSuccess,
dismissAddingAnnotation,
mouseEnterTempAnnotation,
@ -34,7 +33,6 @@ class Annotations extends Component {
mode,
isTempHovering,
handleUpdateAnnotation,
handleDeleteAnnotation,
handleDismissAddingAnnotation,
handleAddingAnnotationSuccess,
handleMouseEnterTempAnnotation,
@ -72,7 +70,6 @@ class Annotations extends Component {
dygraph={dygraph}
annotations={annotations}
onUpdateAnnotation={handleUpdateAnnotation}
onDeleteAnnotation={handleDeleteAnnotation}
/>
)}
{annotations.filter(a => !a.id.includes('-end')).map((a, i) => {
@ -93,7 +90,6 @@ Annotations.propTypes = {
mode: string,
isTempHovering: bool,
annotationsRef: func,
handleDeleteAnnotation: func.isRequired,
handleUpdateAnnotation: func.isRequired,
handleDismissAddingAnnotation: func.isRequired,
handleAddingAnnotationSuccess: func.isRequired,
@ -127,7 +123,6 @@ const mapDispatchToProps = dispatch => ({
dispatch
),
handleUpdateAnnotation: bindActionCreators(updateAnnotation, dispatch),
handleDeleteAnnotation: bindActionCreators(deleteAnnotation, dispatch),
})
export default connect(mapStateToProps, mapDispatchToProps)(Annotations)