-
-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
364 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (C) 2020 Nicolas Pelletier | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
import {Button, Col, Collapse, Row} from 'react-bootstrap'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {formatDate} from '../../../helpers/utils'; | ||
|
||
|
||
class EntityAnnotation extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
open: false | ||
}; | ||
} | ||
|
||
handleToggleCollapse = () => { | ||
this.setState(prevState => ({open: !prevState.open})); | ||
}; | ||
|
||
render() { | ||
const {annotation} = this.props.entity; | ||
if (!annotation || !annotation.content) { | ||
return null; | ||
} | ||
const lastModifiedDate = new Date(annotation.lastRevision.createdAt); | ||
return ( | ||
<Row> | ||
<Col md={12}> | ||
<h2>Annotation</h2> | ||
<Collapse in={this.state.open}> | ||
<p className="annotation-content">{annotation.content}</p> | ||
</Collapse> | ||
<Button bsStyle="link" onClick={this.handleToggleCollapse}> | ||
Show {this.state.open ? 'less' : 'more…'} | ||
</Button> | ||
<p className="text-muted">Last modified: <span title={formatDate(lastModifiedDate, true)}>{formatDate(lastModifiedDate)}</span> | ||
<span className="small"> (revision <a href={`/revision/${annotation.lastRevisionId}`}>#{annotation.lastRevisionId}</a>)</span> | ||
</p> | ||
</Col> | ||
</Row> | ||
); | ||
} | ||
} | ||
EntityAnnotation.displayName = 'EntityAnnotation'; | ||
EntityAnnotation.propTypes = { | ||
entity: PropTypes.object.isRequired | ||
}; | ||
|
||
export default EntityAnnotation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright (C) 2020 Nicolas Pelletier | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
// @flow | ||
|
||
export const UPDATE_ANNOTATION = 'UPDATE_ANNOTATION'; | ||
|
||
export type Action = { | ||
type: string, | ||
payload?: mixed, | ||
metadata?: { | ||
debounce?: string | ||
} | ||
}; | ||
|
||
/** | ||
* Produces an action indicating that the annotation for the editing form | ||
* should be updated with the provided value. The action is marked to be | ||
* debounced by the keystroke debouncer defined for redux-debounce. | ||
* | ||
* @param {string} value - The new value to be used for the revision note. | ||
* @returns {Action} The resulting UPDATE_ANNOTATION action. | ||
*/ | ||
export function debounceUpdateAnnotation(value: string): Action { | ||
return { | ||
meta: {debounce: 'keystroke'}, | ||
type: UPDATE_ANNOTATION, | ||
value | ||
}; | ||
} |
99 changes: 99 additions & 0 deletions
99
src/client/entity-editor/annotation-section/annotation-section.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright (C) 2020 Nicolas Pelletier | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
import {Col, Row} from 'react-bootstrap'; | ||
import {convertMapToObject, formatDate} from '../../helpers/utils'; | ||
|
||
import CustomInput from '../../input'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import {connect} from 'react-redux'; | ||
import {debounceUpdateAnnotation} from './actions'; | ||
|
||
/** | ||
* Container component. The AnnotationSection component contains a | ||
* field for entering or modifying annotations for this entity. | ||
* | ||
* @param {Object} props - The properties passed to the component. | ||
* @param {Object} props.annotation - The annotation object containing | ||
* its content and lastRevision info | ||
* @param {Function} props.onAnnotationChange - A function to be called when the | ||
* annotation is changed. | ||
* @returns {ReactElement} React element containing the rendered | ||
* AnnotationSection. | ||
*/ | ||
function AnnotationSection({ | ||
annotation, | ||
onAnnotationChange | ||
}) { | ||
const annotationLabel = ( | ||
<span> | ||
Annotation | ||
<span className="text-muted"> (optional)</span> | ||
</span> | ||
); | ||
|
||
return ( | ||
<div> | ||
<h2> | ||
Annotation | ||
</h2> | ||
<Row> | ||
<Col md={6} mdOffset={3}> | ||
<CustomInput | ||
defaultValue={annotation.content} | ||
label={annotationLabel} | ||
rows="4" | ||
tooltipText="Additional freeform data that does not fit in the above form" | ||
type="textarea" | ||
onChange={onAnnotationChange} | ||
/> | ||
{ | ||
annotation && annotation.lastRevision && | ||
<p className="small text-muted">Last modified: {formatDate(new Date(annotation.lastRevision.createdAt))}</p> | ||
} | ||
<p className="help-block"> | ||
Annotations allow you to enter freeform data that does not otherwise fit in the above form. | ||
<b> Do not submit any copyrighted text here.</b> The contents will be made available to the public under <a href="https://musicbrainz.org/doc/About/Data_License">open licenses</a>. | ||
</p> | ||
</Col> | ||
</Row> | ||
</div> | ||
); | ||
} | ||
AnnotationSection.displayName = 'AnnotationSection'; | ||
AnnotationSection.propTypes = { | ||
annotation: PropTypes.object.isRequired, | ||
onAnnotationChange: PropTypes.func.isRequired | ||
}; | ||
|
||
function mapStateToProps(rootState) { | ||
return { | ||
annotation: convertMapToObject(rootState.get('annotationSection')) | ||
}; | ||
} | ||
|
||
|
||
function mapDispatchToProps(dispatch) { | ||
return { | ||
onAnnotationChange: (event) => | ||
dispatch(debounceUpdateAnnotation(event.target.value)) | ||
}; | ||
} | ||
|
||
export default connect(mapStateToProps, mapDispatchToProps)(AnnotationSection); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2020 Nicolas Pelletier | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License along | ||
* with this program; if not, write to the Free Software Foundation, Inc., | ||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
*/ | ||
|
||
import Immutable from 'immutable'; | ||
import {UPDATE_ANNOTATION} from './actions'; | ||
|
||
|
||
function reducer( | ||
state = Immutable.Map({content: ''}), | ||
action | ||
) { | ||
switch (action.type) { | ||
case UPDATE_ANNOTATION: | ||
return state.set('content', action.value); | ||
// no default | ||
} | ||
return state; | ||
} | ||
|
||
export default reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.