-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Review summary (a global comment that is not attached to any file:lin…
…e) added.
- Loading branch information
1 parent
666c4b9
commit e5ccc23
Showing
13 changed files
with
293 additions
and
96 deletions.
There are no files selected for viewing
125 changes: 125 additions & 0 deletions
125
src/components/Solutions/ReviewSummary/ReviewSummary.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,125 @@ | ||
import React, { Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { FormattedMessage } from 'react-intl'; | ||
|
||
import ReviewCommentForm, { newCommentFormInitialValues } from '../../forms/ReviewCommentForm'; | ||
import SourceCodeComment from '../../helpers/SourceCodeViewer/SourceCodeComment'; | ||
import Button from '../../widgets/TheButton'; | ||
import Box from '../../widgets/Box'; | ||
import { AddIcon } from '../../icons'; | ||
|
||
class ReviewSummary extends Component { | ||
state = { add: false, edit: null, editInitialValues: null }; | ||
|
||
startCreation = () => this.setState({ add: true }); | ||
close = () => this.setState({ add: false, edit: null }); | ||
|
||
createNewComment = ({ text, issue, suppressNotification = false }) => { | ||
const { addComment } = this.props; | ||
text = text.trim(); | ||
return addComment({ | ||
text, | ||
issue, | ||
suppressNotification, | ||
file: '', | ||
line: 0, | ||
}).then(this.close); | ||
}; | ||
|
||
startEditting = ({ id, text, issue }) => { | ||
this.setState({ edit: id, editInitialValues: { text, issue, suppressNotification: false } }); | ||
}; | ||
|
||
editComment = ({ text, issue, suppressNotification = false }) => { | ||
const { updateComment } = this.props; | ||
text = text.trim(); | ||
if (!text || !this.state.edit) { | ||
this.close(); | ||
return Promise.resove(); | ||
} | ||
|
||
return updateComment({ | ||
id: this.state.edit, | ||
text, | ||
issue, | ||
suppressNotification, | ||
}).then(this.close); | ||
}; | ||
|
||
render() { | ||
const { | ||
reviewComments = [], | ||
reviewClosed = false, | ||
authorView = false, | ||
restrictCommentAuthor = null, | ||
addComment = null, | ||
updateComment = null, | ||
removeComment = null, | ||
} = this.props; | ||
|
||
return ( | ||
<Box | ||
title={<FormattedMessage id="app.solutionSourceCodes.reviewSummary.title" defaultMessage="Review summary" />} | ||
noPadding | ||
unlimitedHeight | ||
isOpen> | ||
<div className="sourceCodeViewerComments reviewSummary"> | ||
{reviewComments.map(comment => | ||
this.state.edit === comment.id && updateComment ? ( | ||
<ReviewCommentForm | ||
key={comment.id} | ||
form={`review-summary-${comment.id}`} | ||
initialValues={this.state.editInitialValues} | ||
createdAt={comment.createdAt} | ||
authorId={comment.author} | ||
onCancel={this.close} | ||
onSubmit={this.editComment} | ||
showSuppressor={this.props.reviewClosed} | ||
/> | ||
) : ( | ||
<SourceCodeComment | ||
key={comment.id} | ||
comment={comment} | ||
authorView={authorView} | ||
restrictCommentAuthor={restrictCommentAuthor} | ||
startEditting={updateComment ? this.startEditting : null} | ||
removeComment={removeComment} | ||
/> | ||
) | ||
)} | ||
|
||
{reviewComments.length === 0 && this.state.add && addComment && ( | ||
<ReviewCommentForm | ||
form="review-summary-new" | ||
initialValues={newCommentFormInitialValues} | ||
onCancel={this.close} | ||
onSubmit={this.createNewComment} | ||
showSuppressor={reviewClosed} | ||
/> | ||
)} | ||
|
||
{reviewComments.length === 0 && addComment && !this.state.add && ( | ||
<div className="text-center p-3"> | ||
<Button onClick={this.startCreation} size="sm" variant="success"> | ||
<AddIcon gapRight /> | ||
<FormattedMessage id="generic.create" defaultMessage="Create" /> | ||
</Button> | ||
</div> | ||
)} | ||
</div> | ||
</Box> | ||
); | ||
} | ||
} | ||
|
||
ReviewSummary.propTypes = { | ||
reviewComments: PropTypes.array, | ||
reviewClosed: PropTypes.bool, | ||
authorView: PropTypes.bool, | ||
restrictCommentAuthor: PropTypes.string, | ||
addComment: PropTypes.func, | ||
updateComment: PropTypes.func, | ||
removeComment: PropTypes.func, | ||
}; | ||
|
||
export default ReviewSummary; |
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 @@ | ||
export { default } from './ReviewSummary'; |
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 |
---|---|---|
@@ -1,2 +1 @@ | ||
import ReviewCommentForm from './ReviewCommentForm'; | ||
export default ReviewCommentForm; | ||
export { default, newCommentFormInitialValues } from './ReviewCommentForm'; |
92 changes: 92 additions & 0 deletions
92
src/components/helpers/SourceCodeViewer/SourceCodeComment.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,92 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { OverlayTrigger, Tooltip } from 'react-bootstrap'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import classnames from 'classnames'; | ||
|
||
import UsersNameContainer from '../../../containers/UsersNameContainer'; | ||
import Confirm from '../../forms/Confirm'; | ||
import DateTime from '../../widgets/DateTime'; | ||
import Markdown from '../../widgets/Markdown'; | ||
import Icon, { DeleteIcon, EditIcon, LoadingIcon, WarningIcon } from '../../icons'; | ||
|
||
import './SourceCodeViewer.css'; | ||
|
||
const SourceCodeComment = ({ | ||
comment, | ||
authorView = false, | ||
startEditting = null, | ||
removeComment = null, | ||
restrictCommentAuthor = null, | ||
}) => { | ||
return ( | ||
<div className={classnames({ issue: comment.issue, 'half-opaque': comment.removing })}> | ||
<span className="icon"> | ||
{comment.issue ? ( | ||
<OverlayTrigger | ||
placement="bottom" | ||
overlay={ | ||
<Tooltip id={`issue-${comment.id}`}> | ||
{authorView ? ( | ||
<FormattedMessage | ||
id="app.sourceCodeViewer.issueTooltipForAuthor" | ||
defaultMessage="This comment is marked as an issue, which means you are expected to fix it in your next submission." | ||
/> | ||
) : ( | ||
<FormattedMessage | ||
id="app.sourceCodeViewer.issueTooltip" | ||
defaultMessage="This comment is marked as an issue, which means the author is expected to fix it in the next submission." | ||
/> | ||
)} | ||
</Tooltip> | ||
}> | ||
<WarningIcon className="text-danger" gapRight /> | ||
</OverlayTrigger> | ||
) : ( | ||
<Icon icon={['far', 'comment']} className="almost-transparent" gapRight /> | ||
)} | ||
</span> | ||
|
||
<small> | ||
<UsersNameContainer userId={comment.author} showEmail="icon" /> | ||
<span className="actions"> | ||
{comment.removing && <LoadingIcon />} | ||
|
||
{startEditting && | ||
!comment.removing && | ||
(!restrictCommentAuthor || restrictCommentAuthor === comment.author) && ( | ||
<EditIcon className="text-warning" gapRight onClick={() => startEditting(comment)} /> | ||
)} | ||
{removeComment && !comment.removing && (!restrictCommentAuthor || restrictCommentAuthor === comment.author) && ( | ||
<Confirm | ||
id={`delcfrm-${comment.id}`} | ||
onConfirmed={() => removeComment(comment.id)} | ||
question={ | ||
<FormattedMessage | ||
id="app.sourceCodeViewer.deleteCommentConfirm" | ||
defaultMessage="Do you really wish to remove this comment? This operation cannot be undone." | ||
/> | ||
}> | ||
<DeleteIcon className="text-danger" gapRight /> | ||
</Confirm> | ||
)} | ||
</span> | ||
</small> | ||
|
||
<small className="float-right mr-2"> | ||
<DateTime unixts={comment.createdAt} showRelative /> | ||
</small> | ||
<Markdown source={comment.text} /> | ||
</div> | ||
); | ||
}; | ||
|
||
SourceCodeComment.propTypes = { | ||
comment: PropTypes.object.isRequired, | ||
startEditting: PropTypes.func, | ||
removeComment: PropTypes.func, | ||
authorView: PropTypes.bool, | ||
restrictCommentAuthor: PropTypes.string, | ||
}; | ||
|
||
export default SourceCodeComment; |
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.