提交 d15c0dce 编写于 作者: R Rachel Macfarlane

Display message when PR has no comments

上级 0d39d57d
......@@ -209,6 +209,7 @@ export class PRProvider implements vscode.TreeDataProvider<PRGroupTreeItem | Pul
ret.push({
threadId: comment.id,
resource: document.uri,
range,
comments: comments.map(comment => {
return {
......
......@@ -74,6 +74,7 @@ export class MainThreadComments extends Disposable implements MainThreadComments
$unregisterCommentProvider(handle: number): void {
this._providers.delete(handle);
this._panelService.setPanelEnablement(COMMENTS_PANEL_ID, false);
this._commentService.removeAllComments();
}
dispose(): void {
......
......@@ -9,6 +9,7 @@ import URI from 'vs/base/common/uri';
import { IRange } from 'vs/editor/common/core/range';
import { Comment, CommentThread } from 'vs/editor/common/modes';
import { groupBy } from 'vs/base/common/arrays';
import { localize } from 'vs/nls';
export class CommentNode {
threadId: string;
......@@ -56,36 +57,33 @@ export class ResourceCommentThreads {
export class CommentsModel {
commentThreads: ResourceCommentThreads[];
commentThreadsByResource: Map<string, ResourceCommentThreads>;
constructor() {
this.commentThreads = [];
this.commentThreadsByResource = new Map<string, ResourceCommentThreads>();
}
public setCommentThreadsForResource(resource: URI, commentThreads: CommentThread[]): boolean {
if (!commentThreads.length || this.commentThreadsByResource.get(resource.toString())) {
return false;
public setCommentThreads(commentThreads: CommentThread[]): void {
const commentThreadsByResource = new Map<string, ResourceCommentThreads>();
for (const group of groupBy(commentThreads, CommentsModel._compareURIs)) {
commentThreadsByResource.set(group[0].resource, new ResourceCommentThreads(URI.parse(group[0].resource), group));
}
this.commentThreadsByResource.set(resource.toString(), new ResourceCommentThreads(resource, commentThreads));
this.commentThreads = [];
this.commentThreadsByResource.forEach((v, i, m) => {
commentThreadsByResource.forEach((v, i, m) => {
this.commentThreads.push(v);
});
}
return true;
public hasCommentThreads(): boolean {
return !!this.commentThreads.length;
}
public setCommentThreads(commentThreads: CommentThread[]) {
for (const group of groupBy(commentThreads, CommentsModel._compareURIs)) {
this.commentThreadsByResource.set(group[0].resource, new ResourceCommentThreads(URI.parse(group[0].resource), group));
public getMessage(): string {
if (!this.commentThreads.length) {
return localize('noComments', "There are no comments on this review.");
} else {
return '';
}
this.commentThreadsByResource.forEach((v, i, m) => {
this.commentThreads.push(v);
});
}
private static _compareURIs(a: CommentThread, b: CommentThread) {
......
......@@ -166,6 +166,8 @@ interface ICommentTemplateData {
export class CommentsPanel extends Panel {
private tree: WorkbenchTree;
private treeContainer: HTMLElement;
private messageBoxContainer: HTMLElement;
private messageBox: HTMLElement;
private commentsModel: CommentsModel;
constructor(
......@@ -188,6 +190,7 @@ export class CommentsPanel extends Panel {
this.commentsModel = new CommentsModel();
this.createTree();
this.createMessageBox(container);
this.commentService.onDidSetAllCommentThreads(this.onAllCommentsChanged, this);
......@@ -196,16 +199,19 @@ export class CommentsPanel extends Panel {
private onAllCommentsChanged(e: CommentThread[]) {
this.commentsModel.setCommentThreads(e);
dom.toggleClass(this.treeContainer, 'hidden', !this.commentsModel.hasCommentThreads());
this.tree.refresh().then(() => {
console.log('tree refreshed');
this.renderMessage();
}, (e) => {
console.log(e);
});
}
private render(): TPromise<void> {
dom.toggleClass(this.treeContainer, 'hidden', false);
return this.tree.setInput(this.commentsModel);
dom.toggleClass(this.treeContainer, 'hidden', !this.commentsModel.hasCommentThreads());
return this.tree.setInput(this.commentsModel).then(() => {
this.renderMessage();
});
}
public layout(dimensions: dom.Dimension): void {
......@@ -216,6 +222,17 @@ export class CommentsPanel extends Panel {
return COMMENTS_PANEL_TITLE;
}
private createMessageBox(parent: HTMLElement): void {
this.messageBoxContainer = dom.append(parent, dom.$('.message-box-container'));
this.messageBox = dom.append(this.messageBoxContainer, dom.$('span'));
this.messageBox.setAttribute('tabindex', '0');
}
private renderMessage(): void {
this.messageBox.textContent = this.commentsModel.getMessage();
dom.toggleClass(this.messageBoxContainer, 'hidden', this.commentsModel.hasCommentThreads());
}
private createTree(): void {
this.tree = this.instantiationService.createInstance(WorkbenchTree, this.treeContainer, {
dataSource: new CommentsDataSource(),
......
......@@ -36,4 +36,13 @@
display: inline-flex;
text-overflow: ellipsis;
overflow: hidden;
}
.comments-panel .comments-panel-container .message-box-container {
line-height: 22px;
padding-left: 20px;
}
.comments-panel .comments-panel-container .message-box-container span:focus {
outline: none;
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ export interface ICommentService {
readonly onDidSetAllCommentThreads: Event<CommentThread[]>;
setComments(resource: URI, commentThreads: CommentThread[]): void;
setAllComments(commentsByResource: CommentThread[]): void;
removeAllComments(): void;
}
export class CommentService extends Disposable implements ICommentService {
......@@ -47,4 +48,8 @@ export class CommentService extends Disposable implements ICommentService {
setAllComments(commentsByResource: CommentThread[]): void {
this._onDidSetAllCommentThreads.fire(commentsByResource);
}
removeAllComments(): void {
this._onDidSetAllCommentThreads.fire([]);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册