Skip to content
Snippets Groups Projects
Commit cd9140d3 authored by Antoine Roy's avatar Antoine Roy
Browse files

add close annotation pannel function to plugin's context and start implementing some logic

parent 0a33481c
No related branches found
No related tags found
No related merge requests found
Pipeline #1795 failed
...@@ -6,6 +6,7 @@ import ToggleButton from '@mui/material/ToggleButton'; ...@@ -6,6 +6,7 @@ import ToggleButton from '@mui/material/ToggleButton';
import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup';
import flatten from 'lodash/flatten'; import flatten from 'lodash/flatten';
import AnnotationActionsContext from './AnnotationActionsContext'; import AnnotationActionsContext from './AnnotationActionsContext';
import * as actions from "mirador/dist/es/src/state/actions";
/** */ /** */
class CanvasListItem extends Component { class CanvasListItem extends Component {
...@@ -15,6 +16,9 @@ class CanvasListItem extends Component { ...@@ -15,6 +16,9 @@ class CanvasListItem extends Component {
this.state = { this.state = {
isHovering: false, isHovering: false,
isEditAnnotationPanelOpen: false,
id: "",
payload:{}
}; };
this.handleMouseHover = this.handleMouseHover.bind(this); this.handleMouseHover = this.handleMouseHover.bind(this);
...@@ -37,7 +41,7 @@ class CanvasListItem extends Component { ...@@ -37,7 +41,7 @@ class CanvasListItem extends Component {
/** */ /** */
handleEdit() { handleEdit() {
const { const {
addCompanionWindow, canvases, annotationsOnCanvases, addCompanionWindow, canvases, annotationsOnCanvases,closeCompanionWindow
} = this.context; } = this.context;
const { annotationid } = this.props; const { annotationid } = this.props;
let annotation; let annotation;
...@@ -51,10 +55,28 @@ class CanvasListItem extends Component { ...@@ -51,10 +55,28 @@ class CanvasListItem extends Component {
} }
return (annotation); return (annotation);
}); });
addCompanionWindow('annotationCreation', { console.log('closeCompanionWindow',closeCompanionWindow)
console.log('this props', this.props)
console.log('this context', this.context)
if(!this.state.isEditAnnotationPanelOpen){
const myAnnotationPannel = addCompanionWindow('annotationCreation', {
annotationid, annotationid,
position: 'right', position: 'right',
}); });
this.setState({isEditAnnotationPanelOpen:true})
this.setState({id: myAnnotationPannel.id})
this.setState({payload: myAnnotationPannel.payload})
}else{
closeCompanionWindow(this.state.id)
this.setState({creationAnnotationIsOpen: false})
const myAnnotationPannel = addCompanionWindow('annotationCreation', {
annotationid,
position: 'right',
});
this.setState({isEditAnnotationPanelOpen:true})
this.setState({id: myAnnotationPannel.id})
this.setState({payload: myAnnotationPannel.payload})
}
} }
/** */ /** */
...@@ -137,8 +159,10 @@ CanvasListItem.propTypes = { ...@@ -137,8 +159,10 @@ CanvasListItem.propTypes = {
PropTypes.func, PropTypes.func,
PropTypes.node, PropTypes.node,
]).isRequired, ]).isRequired,
closeCompanionWindow: PropTypes.func.isRequired,
}; };
CanvasListItem.contextType = AnnotationActionsContext; CanvasListItem.contextType = AnnotationActionsContext;
export default forwardRef((props, ref) => <CanvasListItem {...props} containerRef={ref} />); export default forwardRef((props, ref) => <CanvasListItem {...props} containerRef={ref} />);
...@@ -30,7 +30,7 @@ class CanvasAnnotationsWrapper extends Component { ...@@ -30,7 +30,7 @@ class CanvasAnnotationsWrapper extends Component {
render() { render() {
const { const {
addCompanionWindow, annotationsOnCanvases, canvases, config, receiveAnnotation, addCompanionWindow, annotationsOnCanvases, canvases, config, receiveAnnotation,
switchToSingleCanvasView, TargetComponent, targetProps, windowViewType, containerRef, switchToSingleCanvasView, TargetComponent, targetProps, windowViewType, containerRef,closeCompanionWindow
} = this.props; } = this.props;
const { singleCanvasDialogOpen } = this.state; const { singleCanvasDialogOpen } = this.state;
...@@ -51,6 +51,7 @@ class CanvasAnnotationsWrapper extends Component { ...@@ -51,6 +51,7 @@ class CanvasAnnotationsWrapper extends Component {
toggleSingleCanvasDialogOpen: this.toggleSingleCanvasDialogOpen, toggleSingleCanvasDialogOpen: this.toggleSingleCanvasDialogOpen,
windowId: targetProps.windowId, windowId: targetProps.windowId,
windowViewType, windowViewType,
closeCompanionWindow
}} }}
> >
<TargetComponent <TargetComponent
...@@ -92,6 +93,8 @@ CanvasAnnotationsWrapper.propTypes = { ...@@ -92,6 +93,8 @@ CanvasAnnotationsWrapper.propTypes = {
]).isRequired, ]).isRequired,
targetProps: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types targetProps: PropTypes.object.isRequired, // eslint-disable-line react/forbid-prop-types
windowViewType: PropTypes.string.isRequired, windowViewType: PropTypes.string.isRequired,
closeCompanionWindow: PropTypes.func.isRequired,
}; };
CanvasAnnotationsWrapper.defaultProps = { CanvasAnnotationsWrapper.defaultProps = {
...@@ -117,6 +120,7 @@ function mapStateToProps(state, { targetProps: { windowId } }) { ...@@ -117,6 +120,7 @@ function mapStateToProps(state, { targetProps: { windowId } }) {
config: state.config, config: state.config,
windowViewType: getWindowViewType(state, { windowId }), windowViewType: getWindowViewType(state, { windowId }),
}; };
} }
/** */ /** */
...@@ -130,6 +134,9 @@ const mapDispatchToProps = (dispatch, props) => ({ ...@@ -130,6 +134,9 @@ const mapDispatchToProps = (dispatch, props) => ({
switchToSingleCanvasView: () => dispatch( switchToSingleCanvasView: () => dispatch(
actions.setWindowViewType(props.targetProps.windowId, 'single'), actions.setWindowViewType(props.targetProps.windowId, 'single'),
), ),
closeCompanionWindow: (id) => dispatch(
actions.removeCompanionWindow(props.targetProps.windowId, id),
)
}); });
export default { export default {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment