mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-12 12:22:13 +00:00
fix-list-bug
This commit is contained in:
parent
b4e2460ff7
commit
133bb27d01
@ -3,13 +3,14 @@ import PropTypes from 'prop-types';
|
|||||||
import { Button } from 'reactstrap';
|
import { Button } from 'reactstrap';
|
||||||
import { seafileAPI } from '../../utils/seafile-api';
|
import { seafileAPI } from '../../utils/seafile-api';
|
||||||
import { reviewID, gettext } from '../../utils/constants';
|
import { reviewID, gettext } from '../../utils/constants';
|
||||||
|
import { processor } from '../../utils/seafile-markdown2html';
|
||||||
|
|
||||||
import '../../css/review-comment-dialog.css';
|
import '../../css/review-comment-dialog.css';
|
||||||
|
|
||||||
const commentDialogPropTypes = {
|
const commentDialogPropTypes = {
|
||||||
onCommentAdded: PropTypes.func.isRequired,
|
onCommentAdded: PropTypes.func.isRequired,
|
||||||
toggleCommentDialog: PropTypes.func.isRequired,
|
toggleCommentDialog: PropTypes.func.isRequired,
|
||||||
selectedText: PropTypes.string,
|
quote: PropTypes.string,
|
||||||
newIndex: PropTypes.number,
|
newIndex: PropTypes.number,
|
||||||
oldIndex: PropTypes.number,
|
oldIndex: PropTypes.number,
|
||||||
};
|
};
|
||||||
@ -21,6 +22,7 @@ class ReviewCommentDialog extends React.Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
comment: '',
|
comment: '',
|
||||||
userName: '',
|
userName: '',
|
||||||
|
quote: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +44,9 @@ class ReviewCommentDialog extends React.Component {
|
|||||||
submitComment = () => {
|
submitComment = () => {
|
||||||
let comment = this.state.comment.trim();
|
let comment = this.state.comment.trim();
|
||||||
if (comment.length > 0) {
|
if (comment.length > 0) {
|
||||||
if (this.props.selectedText.length > 0) {
|
if (this.props.quote.length > 0) {
|
||||||
let detail = {
|
let detail = {
|
||||||
selectedText: this.props.selectedText.slice(0, 10),
|
quote: this.props.quote,
|
||||||
newIndex: this.props.newIndex,
|
newIndex: this.props.newIndex,
|
||||||
oldIndex: this.props.oldIndex
|
oldIndex: this.props.oldIndex
|
||||||
};
|
};
|
||||||
@ -64,12 +66,15 @@ class ReviewCommentDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setQuoteText = (text) => {
|
setQuoteText = (mdQuote) => {
|
||||||
if (text.length > 0) {
|
processor.process(mdQuote).then(
|
||||||
this.setState({
|
(result) => {
|
||||||
comment: text
|
let quote = String(result);
|
||||||
});
|
this.setState({
|
||||||
}
|
quote: quote
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
@ -77,12 +82,12 @@ class ReviewCommentDialog extends React.Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.setQuoteText(this.props.selectedText);
|
this.setQuoteText(this.props.quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
if (this.props.selectedText !== nextProps.selectedText) {
|
if (this.props.quote !== nextProps.quote) {
|
||||||
this.setQuoteText(nextProps.selectedText);
|
this.setQuoteText(nextProps.quote);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +95,9 @@ class ReviewCommentDialog extends React.Component {
|
|||||||
return (
|
return (
|
||||||
<div className="review-comment-dialog">
|
<div className="review-comment-dialog">
|
||||||
<div>{this.state.userName}</div>
|
<div>{this.state.userName}</div>
|
||||||
|
<blockquote className="review-comment-dialog-quote">
|
||||||
|
<div dangerouslySetInnerHTML={{ __html: this.state.quote}}></div>
|
||||||
|
</blockquote>
|
||||||
<textarea value={this.state.comment} onChange={this.handleCommentChange}></textarea>
|
<textarea value={this.state.comment} onChange={this.handleCommentChange}></textarea>
|
||||||
<div className="button-group">
|
<div className="button-group">
|
||||||
<Button size="sm" color="primary" onClick={this.submitComment}>{gettext('Submit')}</Button>
|
<Button size="sm" color="primary" onClick={this.submitComment}>{gettext('Submit')}</Button>
|
||||||
|
@ -132,8 +132,8 @@ class ReviewComments extends React.Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
scrollToQuote = (newIndex, oldIndex, selectedText) => {
|
scrollToQuote = (newIndex, oldIndex, quote) => {
|
||||||
this.props.scrollToQuote(newIndex, oldIndex, selectedText);
|
this.props.scrollToQuote(newIndex, oldIndex, quote);
|
||||||
this.setState({
|
this.setState({
|
||||||
comment: ''
|
comment: ''
|
||||||
});
|
});
|
||||||
@ -227,7 +227,8 @@ class CommentItem extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
dropdownOpen: false,
|
dropdownOpen: false,
|
||||||
html: '',
|
comment: '',
|
||||||
|
quote: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -237,66 +238,74 @@ class CommentItem extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
convertComment = (mdFile) => {
|
convertComment = (item) => {
|
||||||
processor.process(mdFile).then(
|
processor.process(item.comment).then(
|
||||||
(result) => {
|
(result) => {
|
||||||
let html = String(result);
|
let comment = String(result);
|
||||||
this.setState({
|
this.setState({
|
||||||
html: html
|
comment: comment
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
processor.process(item.quote).then(
|
||||||
|
(result) => {
|
||||||
|
let quote = String(result);
|
||||||
|
this.setState({
|
||||||
|
quote: quote
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToQuote = () => {
|
scrollToQuote = () => {
|
||||||
this.props.scrollToQuote(this.props.item.newIndex, this.props.item.oldIndex,
|
const item = this.props.item;
|
||||||
this.props.item.selectedText);
|
this.props.scrollToQuote(item.newIndex, item.oldIndex, item.quote);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
this.convertComment(this.props.item.comment);
|
this.convertComment(this.props.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps(nextProps) {
|
componentWillReceiveProps(nextProps) {
|
||||||
this.convertComment(nextProps.item.comment);
|
this.convertComment(nextProps.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
if (this.props.item.resolved && !this.props.showResolvedComment) {
|
const item = this.props.item;
|
||||||
|
if (item.resolved && !this.props.showResolvedComment) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return (
|
return (
|
||||||
<li className={this.props.item.resolved ? 'seafile-comment-item seafile-comment-item-resolved'
|
<li className={item.resolved ? 'seafile-comment-item seafile-comment-item-resolved'
|
||||||
: 'seafile-comment-item'} id={this.props.item.id}>
|
: 'seafile-comment-item'} id={item.id}>
|
||||||
<div className="seafile-comment-info">
|
<div className="seafile-comment-info">
|
||||||
<img className="avatar" src={this.props.item.avatarUrl} alt=""/>
|
<img className="avatar" src={item.avatarUrl} alt=""/>
|
||||||
<div className="reviewer-info">
|
<div className="reviewer-info">
|
||||||
<div className="reviewer-name">{this.props.item.name}</div>
|
<div className="reviewer-name">{item.name}</div>
|
||||||
<div className="review-time">{this.props.item.time}</div>
|
<div className="review-time">{item.time}</div>
|
||||||
</div>
|
</div>
|
||||||
{ !this.props.item.resolved &&
|
{ !item.resolved &&
|
||||||
<Dropdown isOpen={this.state.dropdownOpen} size="sm"
|
<Dropdown isOpen={this.state.dropdownOpen} size="sm"
|
||||||
className="seafile-comment-dropdown" toggle={this.toggleDropDownMenu}>
|
className="seafile-comment-dropdown" toggle={this.toggleDropDownMenu}>
|
||||||
<DropdownToggle className="seafile-comment-dropdown-btn">
|
<DropdownToggle className="seafile-comment-dropdown-btn">
|
||||||
<i className="fas fa-ellipsis-v"></i>
|
<i className="fas fa-ellipsis-v"></i>
|
||||||
</DropdownToggle>
|
</DropdownToggle>
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
{ (this.props.item.userEmail === this.props.accountInfo.email) &&
|
{ (item.userEmail === this.props.accountInfo.email) &&
|
||||||
<DropdownItem onClick={this.props.deleteComment}
|
<DropdownItem onClick={this.props.deleteComment}
|
||||||
className="delete-comment" id={this.props.item.id}>{gettext('Delete')}</DropdownItem>}
|
className="delete-comment" id={item.id}>{gettext('Delete')}</DropdownItem>}
|
||||||
<DropdownItem onClick={this.props.resolveComment}
|
<DropdownItem onClick={this.props.resolveComment}
|
||||||
className="seafile-comment-resolved" id={this.props.item.id}>{gettext('Mark as resolved')}</DropdownItem>
|
className="seafile-comment-resolved" id={item.id}>{gettext('Mark as resolved')}</DropdownItem>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
{ (this.props.item.newIndex >= -1 && this.props.item.oldIndex >= -1)?
|
{ (item.newIndex >= -1 && item.oldIndex >= -1) &&
|
||||||
<div className="seafile-comment-content" onClick={this.scrollToQuote}
|
<blockquote className="seafile-comment-content">
|
||||||
dangerouslySetInnerHTML={{ __html: this.state.html }}></div>
|
<div onClick={this.scrollToQuote} dangerouslySetInnerHTML={{ __html: this.state.quote }}></div>
|
||||||
:
|
</blockquote>
|
||||||
<div className="seafile-comment-content"
|
|
||||||
dangerouslySetInnerHTML={{ __html: this.state.html }}></div>
|
|
||||||
}
|
}
|
||||||
|
<div className="seafile-comment-content" dangerouslySetInnerHTML={{ __html: this.state.comment }}></div>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
top: 30%;
|
top: 30%;
|
||||||
right: 0;
|
right: 0;
|
||||||
padding: 10px;
|
padding: 15px;
|
||||||
background-color: #fafafa;
|
background-color: #fafafa;
|
||||||
border: 1px solid rgba(0,0,0,.2);
|
border: 1px solid rgba(0,0,0,.2);
|
||||||
border-radius: .3rem;
|
border-radius: .3rem;
|
||||||
@ -24,9 +24,14 @@
|
|||||||
}
|
}
|
||||||
.review-comment-dialog textarea {
|
.review-comment-dialog textarea {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
min-height: 200px;
|
min-height: 100px;
|
||||||
max-height: 300px;
|
max-height: 300px;
|
||||||
}
|
}
|
||||||
.review-comment-dialog .button-group .btn {
|
.review-comment-dialog .button-group .btn {
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
}
|
||||||
|
.review-comment-dialog .review-comment-dialog-quote {
|
||||||
|
margin-top: 10px;
|
||||||
|
max-height: 4rem;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
@ -96,10 +96,11 @@
|
|||||||
.seafile-comment-item .seafile-comment-content td {
|
.seafile-comment-item .seafile-comment-content td {
|
||||||
border: 1px solid #333;
|
border: 1px solid #333;
|
||||||
}
|
}
|
||||||
.seafile-comment-item .seafile-comment-content blockquote {
|
.seafile-comment-item blockquote {
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
.seafile-comment-row-resize {
|
.seafile-comment-row-resize {
|
||||||
height: 5px;
|
height: 5px;
|
||||||
|
@ -10,7 +10,6 @@ import { siteRoot, gettext, reviewID, draftOriginFilePath, draftFilePath, draftO
|
|||||||
import { seafileAPI } from './utils/seafile-api';
|
import { seafileAPI } from './utils/seafile-api';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import DiffViewer from '@seafile/seafile-editor/dist/viewer/diff-viewer';
|
import DiffViewer from '@seafile/seafile-editor/dist/viewer/diff-viewer';
|
||||||
import { htmlSerializer } from '@seafile/seafile-editor/dist/utils/serialize-html';
|
|
||||||
import { serialize } from '@seafile/seafile-editor/dist/utils/slate2markdown/serialize';
|
import { serialize } from '@seafile/seafile-editor/dist/utils/slate2markdown/serialize';
|
||||||
import Loading from './components/loading';
|
import Loading from './components/loading';
|
||||||
import toaster from './components/toast';
|
import toaster from './components/toast';
|
||||||
@ -22,7 +21,7 @@ import { findRange } from '@seafile/slate-react';
|
|||||||
import { Nav, NavItem, NavLink, TabContent, TabPane } from 'reactstrap';
|
import { Nav, NavItem, NavLink, TabContent, TabPane } from 'reactstrap';
|
||||||
import classnames from 'classnames';
|
import classnames from 'classnames';
|
||||||
import HistoryList from './pages/review/history-list';
|
import HistoryList from './pages/review/history-list';
|
||||||
import { Document, Block, Value } from 'slate';
|
import { Value } from 'slate';
|
||||||
|
|
||||||
import './assets/css/fa-solid.css';
|
import './assets/css/fa-solid.css';
|
||||||
import './assets/css/fa-regular.css';
|
import './assets/css/fa-regular.css';
|
||||||
@ -55,7 +54,7 @@ class DraftReview extends React.Component {
|
|||||||
changedNodes: [],
|
changedNodes: [],
|
||||||
isShowCommentDialog: false,
|
isShowCommentDialog: false,
|
||||||
};
|
};
|
||||||
this.selectedText = '';
|
this.quote = '';
|
||||||
this.newIndex = null;
|
this.newIndex = null;
|
||||||
this.oldIndex = null;
|
this.oldIndex = null;
|
||||||
this.changeIndex = -1;
|
this.changeIndex = -1;
|
||||||
@ -246,34 +245,8 @@ class DraftReview extends React.Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getSelectedText = () => {
|
getQuote = () => {
|
||||||
const native = window.getSelection();
|
this.quote = '';
|
||||||
const nativeRange = native.getRangeAt(0);
|
|
||||||
let contents = nativeRange.cloneContents();
|
|
||||||
const div = window.document.createElement('div');
|
|
||||||
div.appendChild(contents);
|
|
||||||
div.setAttribute('contenteditable', true);
|
|
||||||
let fragmentDOM = htmlSerializer.deserialize(div.innerHTML).document;
|
|
||||||
let nodes = [];
|
|
||||||
fragmentDOM.nodes.map(node => {
|
|
||||||
let newNode = Block.create({
|
|
||||||
data: node.data,
|
|
||||||
key: node.key,
|
|
||||||
nodes: node.nodes,
|
|
||||||
type: 'blockquote'
|
|
||||||
});
|
|
||||||
nodes.push(newNode);
|
|
||||||
});
|
|
||||||
let newDocument = Document.create({
|
|
||||||
nodes: nodes
|
|
||||||
});
|
|
||||||
let newValue = Value.create({
|
|
||||||
document: newDocument
|
|
||||||
});
|
|
||||||
this.selectedText = serialize(newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
getIndexs = () => {
|
|
||||||
let range = this.setBtnPosition();
|
let range = this.setBtnPosition();
|
||||||
if (!range) {
|
if (!range) {
|
||||||
return;
|
return;
|
||||||
@ -306,6 +279,11 @@ class DraftReview extends React.Component {
|
|||||||
range = range.moveFocusTo(nextText.key, 0);
|
range = range.moveFocusTo(nextText.key, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let fragment = document.getFragmentAtRange(range);
|
||||||
|
let newValue = Value.create({
|
||||||
|
document: fragment
|
||||||
|
});
|
||||||
|
this.quote = serialize(newValue.toJSON());
|
||||||
let blockPath = document.createSelection(range).anchor.path.slice(0, 1);
|
let blockPath = document.createSelection(range).anchor.path.slice(0, 1);
|
||||||
let node = document.getNode(blockPath);
|
let node = document.getNode(blockPath);
|
||||||
this.newIndex = node.data.get('new_index');
|
this.newIndex = node.data.get('new_index');
|
||||||
@ -314,8 +292,10 @@ class DraftReview extends React.Component {
|
|||||||
|
|
||||||
addComment = (e) => {
|
addComment = (e) => {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
this.getSelectedText();
|
this.getQuote();
|
||||||
this.getIndexs();
|
if (!this.quote) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
isShowCommentDialog: true
|
isShowCommentDialog: true
|
||||||
});
|
});
|
||||||
@ -341,7 +321,7 @@ class DraftReview extends React.Component {
|
|||||||
return scroller;
|
return scroller;
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToQuote = (newIndex, oldIndex, selectedText) => {
|
scrollToQuote = (newIndex, oldIndex, quote) => {
|
||||||
const nodes = this.refs.diffViewer.value.document.nodes;
|
const nodes = this.refs.diffViewer.value.document.nodes;
|
||||||
let key;
|
let key;
|
||||||
nodes.map((node) => {
|
nodes.map((node) => {
|
||||||
@ -351,7 +331,7 @@ class DraftReview extends React.Component {
|
|||||||
});
|
});
|
||||||
if (typeof(key) !== 'string') {
|
if (typeof(key) !== 'string') {
|
||||||
nodes.map((node) => {
|
nodes.map((node) => {
|
||||||
if (node.text.indexOf(selectedText) > 0) {
|
if (node.text.indexOf(quote) > 0) {
|
||||||
key = node.key;
|
key = node.key;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -633,7 +613,7 @@ class DraftReview extends React.Component {
|
|||||||
<ReviewCommentDialog
|
<ReviewCommentDialog
|
||||||
toggleCommentDialog={this.toggleCommentDialog}
|
toggleCommentDialog={this.toggleCommentDialog}
|
||||||
onCommentAdded={this.onCommentAdded}
|
onCommentAdded={this.onCommentAdded}
|
||||||
selectedText={this.selectedText}
|
quote={this.quote}
|
||||||
newIndex={this.newIndex}
|
newIndex={this.newIndex}
|
||||||
oldIndex={this.oldIndex}
|
oldIndex={this.oldIndex}
|
||||||
/>
|
/>
|
||||||
|
Loading…
Reference in New Issue
Block a user