Skip to content

Commit

Permalink
Adding timestamp to comment. fixes eclipse-theia#11702
Browse files Browse the repository at this point in the history
* Adds timestamp comment optional property
* Timestamp displayed in comment thread widget if defined

Contributed by STMicroelectronics

Signed-off-by: Remi SCHNEKENBURGER <rschnekenburger@eclipsesource.com>
Co-authored-by: Lucas Koehler <lkoehler@eclipsesource.com>
  • Loading branch information
rschnekenbu and lucas-koehler committed Dec 20, 2022
1 parent 1cc8376 commit 376dbca
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
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 @@ -660,6 +660,8 @@ export interface Comment {
readonly contextValue?: string;
readonly label?: string;
readonly mode?: CommentMode;
/** Timestamp serialized as ISO date string via Date.prototype.toISOString */
readonly timestamp?: string;
}

export enum CommentThreadCollapsibleState {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ export class ReviewComment<P extends ReviewComment.Props = ReviewComment.Props>
<div className={'review-comment-contents'}>
<div className={'comment-title monaco-mouse-cursor-text'}>
<strong className={'author'}>{comment.userName}</strong>
<small className={'timestamp'}>{this.localeDate(comment.timestamp)}</small>
<span className={'isPending'}>{comment.label}</span>
<div className={'theia-comments-inline-actions-container'}>
<div className={'theia-comments-inline-actions'} role={'toolbar'}>
Expand All @@ -498,6 +499,16 @@ export class ReviewComment<P extends ReviewComment.Props = ReviewComment.Props>
</div>
</div>;
}
localeDate(timestamp: string | undefined): string {
if (timestamp === undefined) {
return '';
}
const date = Date.parse(timestamp);
if (date && !Number.isNaN(date)) {
return new Date(date).toLocaleString();
}
return '';
}
}

namespace CommentBody {
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-ext/src/main/browser/style/comments.css
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@
line-height: var(--theia-content-line-height);
}

.monaco-editor .review-widget .body .review-comment .review-comment-contents .timestamp {
line-height: var(--theia-content-line-height);
margin: 0 5px 0 5px;
padding: 0 2px 0 2px;
}

.monaco-editor .review-widget .body .review-comment .review-comment-contents .isPending {
margin: 0 5px 0 5px;
padding: 0 2px 0 2px;
Expand Down
2 changes: 2 additions & 0 deletions packages/plugin-ext/src/plugin/comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ function convertToModeComment(thread: ExtHostCommentThread, commentController: C
}

const iconPath = theiaComment.author && theiaComment.author.iconPath ? theiaComment.author.iconPath.toString() : undefined;
const date = theiaComment.timestamp ? theiaComment.timestamp.toISOString() : undefined;

return {
mode: theiaComment.mode,
Expand All @@ -500,6 +501,7 @@ function convertToModeComment(thread: ExtHostCommentThread, commentController: C
userName: theiaComment.author.name,
userIconPath: iconPath,
label: theiaComment.label,
timestamp: date,
};
}

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 @@ -12084,6 +12084,11 @@ export module '@theia/plugin' {
* Label will be rendered next to authorName if exists.
*/
label?: string;

/**
* Optional timestamp.
*/
timestamp?: Date;
}

/**
Expand Down

0 comments on commit 376dbca

Please sign in to comment.