From e73a8866c82ce898af77f6ae46f349cf909198d5 Mon Sep 17 00:00:00 2001 From: Camille Letavernier Date: Fri, 25 Mar 2022 09:35:04 +0100 Subject: [PATCH] 10002: Add canReply to CommentThread - Add canReply to the CommentThread API - Show or Hide the Comment Reply widget based on the CommentThread.canReply value fixes #10002 Contributed on behalf of STMicroelectronics Signed-off-by: Camille Letavernier --- CHANGELOG.md | 1 + .../plugin-ext/src/common/plugin-api-rpc-model.ts | 2 ++ packages/plugin-ext/src/common/plugin-api-rpc.ts | 1 + .../browser/comments/comment-thread-widget.tsx | 10 ++++++++-- .../src/main/browser/comments/comments-main.ts | 15 +++++++++++++++ packages/plugin-ext/src/plugin/comments.ts | 15 +++++++++++++++ packages/plugin/src/theia.d.ts | 5 +++++ 7 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa03a2dccfcd5..e563a2b15f751 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ - [plugin] added support for `SnippetString.appendChoice` [#10969](https://github.com/eclipse-theia/theia/pull/10969) - Contributed on behalf of STMicroelectronics - [plugin] added support for `AccessibilityInformation` [#10961](https://github.com/eclipse-theia/theia/pull/10961) - Contributed on behalf of STMicroelectronics - [plugin] added missing properties `id`, `name` and `backgroundColor` to `StatusBarItem` [#11026](https://github.com/eclipse-theia/theia/pull/11026) - Contributed on behalf of STMicroelectronics +- [plugin] Add `canReply` to `CommentThread` [#11062](https://github.com/eclipse-theia/theia/pull/11062) - Contributed on behalf of STMicroelectronics [Breaking Changes:](#breaking_changes_1.25.0) - [debug] diff --git a/packages/plugin-ext/src/common/plugin-api-rpc-model.ts b/packages/plugin-ext/src/common/plugin-api-rpc-model.ts index e0191427a60e9..f17d630f22c31 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc-model.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc-model.ts @@ -654,6 +654,8 @@ export interface CommentThread { onDidChangeLabel: TheiaEvent; onDidChangeCollapsibleState: TheiaEvent; isDisposed: boolean; + canReply: boolean; + onDidChangeCanReply: TheiaEvent; } export interface CommentThreadChangedEventMain extends CommentThreadChangedEvent { diff --git a/packages/plugin-ext/src/common/plugin-api-rpc.ts b/packages/plugin-ext/src/common/plugin-api-rpc.ts index 8aa4c89fd09b1..533a4e3c16537 100644 --- a/packages/plugin-ext/src/common/plugin-api-rpc.ts +++ b/packages/plugin-ext/src/common/plugin-api-rpc.ts @@ -1789,6 +1789,7 @@ export type CommentThreadChanges = Partial<{ contextValue: string, comments: Comment[], collapseState: CommentThreadCollapsibleState; + canReply: boolean; }>; export interface CommentsMain { diff --git a/packages/plugin-ext/src/main/browser/comments/comment-thread-widget.tsx b/packages/plugin-ext/src/main/browser/comments/comment-thread-widget.tsx index a7007f4d2bc11..9e934d428d476 100644 --- a/packages/plugin-ext/src/main/browser/comments/comment-thread-widget.tsx +++ b/packages/plugin-ext/src/main/browser/comments/comment-thread-widget.tsx @@ -89,6 +89,12 @@ export class CommentThreadWidget extends BaseWidget { commentForm.update(); } })); + this.toDispose.push(this._commentThread.onDidChangeCanReply(_canReply => { + const commentForm = this.commentFormRef.current; + if (commentForm) { + commentForm.update(); + } + })); this.contextMenu = this.menus.getMenu(COMMENT_THREAD_CONTEXT); this.contextMenu.children.map(node => node instanceof ActionMenuNode && node.action.when).forEach(exp => { if (typeof exp === 'string') { @@ -381,7 +387,7 @@ export class CommentForm

extend override render(): React.ReactNode { const { commands, commentThread, contextKeyService } = this.props; const hasExistingComments = commentThread.comments && commentThread.comments.length > 0; - return

+ return commentThread.canReply ?