Skip to content

Commit

Permalink
10002: Add canReply to CommentThread
Browse files Browse the repository at this point in the history
- 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 <[email protected]>
  • Loading branch information
CamilleLetavernier committed Apr 25, 2022
1 parent 06b848e commit e73a886
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

<a name="breaking_changes_1.25.0">[Breaking Changes:](#breaking_changes_1.25.0)</a>
- [debug]
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ export interface CommentThread {
onDidChangeLabel: TheiaEvent<string | undefined>;
onDidChangeCollapsibleState: TheiaEvent<CommentThreadCollapsibleState | undefined>;
isDisposed: boolean;
canReply: boolean;
onDidChangeCanReply: TheiaEvent<boolean>;
}

export interface CommentThreadChangedEventMain extends CommentThreadChangedEvent {
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-ext/src/common/plugin-api-rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,7 @@ export type CommentThreadChanges = Partial<{
contextValue: string,
comments: Comment[],
collapseState: CommentThreadCollapsibleState;
canReply: boolean;
}>;

export interface CommentsMain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -381,7 +387,7 @@ export class CommentForm<P extends CommentForm.Props = CommentForm.Props> extend
override render(): React.ReactNode {
const { commands, commentThread, contextKeyService } = this.props;
const hasExistingComments = commentThread.comments && commentThread.comments.length > 0;
return <div className={'comment-form' + (this.state.expanded || commentThread.comments && commentThread.comments.length === 0 ? ' expand' : '')}>
return commentThread.canReply ? <div className={'comment-form' + (this.state.expanded || commentThread.comments && commentThread.comments.length === 0 ? ' expand' : '')}>
<div className={'theia-comments-input-message-container'}>
<textarea className={'theia-comments-input-message theia-input'}
spellCheck={false}
Expand Down Expand Up @@ -409,7 +415,7 @@ export class CommentForm<P extends CommentForm.Props = CommentForm.Props> extend
clearInput={this.clearInput}
/>
<button className={'review-thread-reply-button'} title={'Reply...'} onClick={this.expand}>Reply...</button>
</div>;
</div> : null;
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-ext/src/main/browser/comments/comments-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,25 @@ export class CommentThreadImpl implements CommentThread, Disposable {
private readonly onDidChangeCollapsibleStateEmitter = new Emitter<CommentThreadCollapsibleState | undefined>();
readonly onDidChangeCollapsibleState = this.onDidChangeCollapsibleStateEmitter.event;

private readonly onDidChangeCanReplyEmitter = new Emitter<boolean>();
readonly onDidChangeCanReply = this.onDidChangeCanReplyEmitter.event;

private _isDisposed: boolean;

get isDisposed(): boolean {
return this._isDisposed;
}

private _canReply: boolean = true;
get canReply(): boolean {
return this._canReply;
}

set canReply(canReply: boolean) {
this._canReply = canReply;
this.onDidChangeCanReplyEmitter.fire(this._canReply);
}

constructor(
public commentThreadHandle: number,
public controllerHandle: number,
Expand All @@ -150,6 +163,7 @@ export class CommentThreadImpl implements CommentThread, Disposable {
if (modified('contextValue')) { this._contextValue = changes.contextValue; }
if (modified('comments')) { this._comments = changes.comments; }
if (modified('collapseState')) { this._collapsibleState = changes.collapseState; }
if (modified('canReply')) { this._canReply = changes.canReply!; }
}

dispose(): void {
Expand All @@ -159,6 +173,7 @@ export class CommentThreadImpl implements CommentThread, Disposable {
this.onDidChangeInputEmitter.dispose();
this.onDidChangeLabelEmitter.dispose();
this.onDidChangeRangeEmitter.dispose();
this.onDidChangeCanReplyEmitter.dispose();
}
}

Expand Down
15 changes: 15 additions & 0 deletions packages/plugin-ext/src/plugin/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ type CommentThreadModification = Partial<{
contextValue: string | undefined,
comments: theia.Comment[],
collapsibleState: theia.CommentThreadCollapsibleState
canReply: boolean;
}>;

export class ExtHostCommentThread implements theia.CommentThread, theia.Disposable {
Expand Down Expand Up @@ -283,6 +284,17 @@ export class ExtHostCommentThread implements theia.CommentThread, theia.Disposab
return this._isDisposed;
}

private _canReply: boolean = true;
get canReply(): boolean {
return this._canReply;
}

set canReply(canReply: boolean) {
this._canReply = canReply;
this.modifications.canReply = canReply;
this._onDidUpdateCommentThread.fire();
}

private commentsMap: Map<theia.Comment, number> = new Map<theia.Comment, number>();

private acceptInputDisposables = new DisposableCollection();
Expand Down Expand Up @@ -345,6 +357,9 @@ export class ExtHostCommentThread implements theia.CommentThread, theia.Disposab
if (modified('collapsibleState')) {
formattedModifications.collapseState = convertToCollapsibleState(this.collapseState);
}
if (modified('canReply')) {
formattedModifications.canReply = this.canReply;
}
this.modifications = {};

this.proxy.$updateCommentThread(
Expand Down
5 changes: 5 additions & 0 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10941,6 +10941,11 @@ export module '@theia/plugin' {
* Once disposed, this comment thread will be removed from visible editors and Comment Panel when appropriate.
*/
dispose(): void;

/**
* Whether the thread supports reply. Defaults to true.
*/
canReply: boolean;
}

/**
Expand Down

0 comments on commit e73a886

Please sign in to comment.