This repository was archived by the owner on Jun 21, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +37
-40
lines changed
GitHub.Exports.Reactive/ViewModels
test/GitHub.App.UnitTests/ViewModels/Documents Expand file tree Collapse file tree 10 files changed +37
-40
lines changed Original file line number Diff line number Diff line change @@ -9,11 +9,11 @@ namespace GitHub.SampleData.Documents
99{
1010 public class IssueishCommentThreadViewModelDesigner : ViewModelBase , IIssueishCommentThreadViewModel
1111 {
12- public IReadOnlyReactiveList < ICommentViewModel > Comments { get ; set ; }
1312 public IActorViewModel CurrentUser { get ; } = new ActorViewModelDesigner ( "grokys" ) ;
1413 public Task DeleteComment ( int pullRequestId , int commentId ) => Task . CompletedTask ;
1514 public Task EditComment ( string id , string body ) => Task . CompletedTask ;
1615 public Task InitializeAsync ( ActorModel currentUser , IssueishDetailModel model , bool addPlaceholder ) => Task . CompletedTask ;
1716 public Task PostComment ( string body ) => Task . CompletedTask ;
17+ public Task CloseIssueish ( string body ) => Task . CompletedTask ;
1818 }
1919}
Original file line number Diff line number Diff line change @@ -11,8 +11,6 @@ namespace GitHub.ViewModels
1111 /// </summary>
1212 public abstract class CommentThreadViewModel : ReactiveObject , ICommentThreadViewModel
1313 {
14- readonly ReactiveList < ICommentViewModel > comments = new ReactiveList < ICommentViewModel > ( ) ;
15-
1614 /// <summary>
1715 /// Initializes a new instance of the <see cref="CommentThreadViewModel"/> class.
1816 /// </summary>
@@ -32,15 +30,9 @@ protected Task InitializeAsync(ActorModel currentUser)
3230 return Task . CompletedTask ;
3331 }
3432
35- /// <inheritdoc/>
36- public IReactiveList < ICommentViewModel > Comments => comments ;
37-
3833 /// <inheritdoc/>
3934 public IActorViewModel CurrentUser { get ; private set ; }
4035
41- /// <inheritdoc/>
42- IReadOnlyReactiveList < ICommentViewModel > ICommentThreadViewModel . Comments => comments ;
43-
4436 /// <inheritdoc/>
4537 public abstract Task PostComment ( string body ) ;
4638
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public interface IIssueishCommentViewModel : ICommentViewModel
3737 /// close the issue/pr from this comment.
3838 /// </param>
3939 Task InitializeAsync (
40- ICommentThreadViewModel thread ,
40+ IIssueishCommentThreadViewModel thread ,
4141 ActorModel currentUser ,
4242 CommentModel comment ,
4343 string closeCaption ) ;
Original file line number Diff line number Diff line change @@ -26,6 +26,9 @@ public class IssueishCommentViewModel : CommentViewModel, IIssueishCommentViewMo
2626 public IssueishCommentViewModel ( ICommentService commentService )
2727 : base ( commentService )
2828 {
29+ CloseIssueish = ReactiveCommand . CreateFromTask (
30+ DoCloseIssueish ,
31+ this . WhenAnyValue ( x => x . CanCloseIssueish ) ) ;
2932 }
3033
3134 /// <inheritdoc/>
@@ -39,7 +42,7 @@ public IssueishCommentViewModel(ICommentService commentService)
3942
4043 /// <inheritdoc/>
4144 public async Task InitializeAsync (
42- ICommentThreadViewModel thread ,
45+ IIssueishCommentThreadViewModel thread ,
4346 ActorModel currentUser ,
4447 CommentModel comment ,
4548 string closeCaption )
@@ -60,5 +63,10 @@ await base.InitializeAsync(
6063 . ToProperty ( this , x => x . CloseIssueishCaption ) ;
6164 }
6265 }
66+
67+ Task DoCloseIssueish ( )
68+ {
69+ return Task . CompletedTask ;
70+ }
6371 }
6472}
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ namespace GitHub.ViewModels.Documents
1717 /// </summary>
1818 [ Export ( typeof ( IPullRequestPageViewModel ) ) ]
1919 [ PartCreationPolicy ( CreationPolicy . NonShared ) ]
20- public class PullRequestPageViewModel : PullRequestViewModelBase , IPullRequestPageViewModel , ICommentThreadViewModel
20+ public class PullRequestPageViewModel : PullRequestViewModelBase , IPullRequestPageViewModel , IIssueishCommentThreadViewModel
2121 {
2222 readonly IViewViewModelFactory factory ;
2323 readonly IPullRequestService service ;
@@ -59,9 +59,6 @@ public PullRequestPageViewModel(
5959 /// <inheritdoc/>
6060 public ReactiveCommand < string , Unit > ShowCommit { get ; }
6161
62- /// <inheritdoc/>
63- IReadOnlyReactiveList < ICommentViewModel > ICommentThreadViewModel . Comments => throw new NotImplementedException ( ) ;
64-
6562 /// <inheritdoc/>
6663 public async Task InitializeAsync (
6764 IRemoteRepositoryModel repository ,
@@ -129,6 +126,11 @@ Task ICommentThreadViewModel.EditComment(string id, string body)
129126 throw new NotImplementedException ( ) ;
130127 }
131128
129+ Task IIssueishCommentThreadViewModel . CloseIssueish ( string body )
130+ {
131+ throw new NotImplementedException ( ) ;
132+ }
133+
132134 async Task AddComment ( CommentModel comment )
133135 {
134136 var vm = factory . CreateViewModel < IIssueishCommentViewModel > ( ) ;
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ namespace GitHub.ViewModels
1717 [ PartCreationPolicy ( CreationPolicy . NonShared ) ]
1818 public class PullRequestReviewCommentThreadViewModel : CommentThreadViewModel , IPullRequestReviewCommentThreadViewModel
1919 {
20+ readonly ReactiveList < ICommentViewModel > comments = new ReactiveList < ICommentViewModel > ( ) ;
2021 readonly IViewViewModelFactory factory ;
2122 readonly ObservableAsPropertyHelper < bool > needsPush ;
2223 IPullRequestSessionFile file ;
@@ -40,6 +41,9 @@ public PullRequestReviewCommentThreadViewModel(IViewViewModelFactory factory)
4041 . ToProperty ( this , x => x . NeedsPush ) ;
4142 }
4243
44+ /// <inheritdoc/>
45+ public IReactiveList < ICommentViewModel > Comments => comments ;
46+
4347 /// <inheritdoc/>
4448 public IPullRequestSession Session { get ; private set ; }
4549
@@ -65,6 +69,9 @@ public bool IsNewThread
6569 /// <inheritdoc/>
6670 public bool NeedsPush => needsPush . Value ;
6771
72+ /// <inheritdoc/>
73+ IReadOnlyReactiveList < ICommentViewModel > IPullRequestReviewCommentThreadViewModel . Comments => comments ;
74+
6875 /// <inheritdoc/>
6976 public async Task InitializeAsync (
7077 IPullRequestSession session ,
Original file line number Diff line number Diff line change 11using System ;
22using System . Threading . Tasks ;
3- using GitHub . Models ;
43
54namespace GitHub . ViewModels . Documents
65{
@@ -10,16 +9,9 @@ namespace GitHub.ViewModels.Documents
109 public interface IIssueishCommentThreadViewModel : ICommentThreadViewModel
1110 {
1211 /// <summary>
13- /// Initializes the view model with data .
12+ /// Called by a comment in the thread to close the issue or pull request .
1413 /// </summary>
15- /// <param name="currentUser">The currently logged in user.</param>
16- /// <param name="model">The issue or pull request model.</param>
17- /// <param name="addPlaceholder">
18- /// Whether to add a placeholder comment at the end of the thread.
19- /// </param>
20- Task InitializeAsync (
21- ActorModel currentUser ,
22- IssueishDetailModel model ,
23- bool addPlaceholder ) ;
14+ /// <param name="body">The body of a comment to submit before closing.</param>
15+ Task CloseIssueish ( string body ) ;
2416 }
2517}
Original file line number Diff line number Diff line change @@ -10,12 +10,7 @@ namespace GitHub.ViewModels
1010 public interface ICommentThreadViewModel : IViewModel
1111 {
1212 /// <summary>
13- /// Gets the comments in the thread.
14- /// </summary>
15- IReadOnlyReactiveList < ICommentViewModel > Comments { get ; }
16-
17- /// <summary>
18- /// Gets the current user under whos account new comments will be created.
13+ /// Gets the current user under whose account new comments will be created.
1914 /// </summary>
2015 IActorViewModel CurrentUser { get ; }
2116
Original file line number Diff line number Diff line change 11using System . Threading . Tasks ;
22using GitHub . Models ;
33using GitHub . Services ;
4+ using ReactiveUI ;
45
56namespace GitHub . ViewModels
67{
@@ -9,6 +10,11 @@ namespace GitHub.ViewModels
910 /// </summary>
1011 public interface IPullRequestReviewCommentThreadViewModel : ICommentThreadViewModel
1112 {
13+ /// <summary>
14+ /// Gets the comments in the thread.
15+ /// </summary>
16+ IReadOnlyReactiveList < ICommentViewModel > Comments { get ; }
17+
1218 /// <summary>
1319 /// Gets the current pull request review session.
1420 /// </summary>
Original file line number Diff line number Diff line change 1- using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
1+ using System . Threading . Tasks ;
62using GitHub . Models ;
73using GitHub . Services ;
8- using GitHub . ViewModels ;
94using GitHub . ViewModels . Documents ;
105using NSubstitute ;
116using NUnit . Framework ;
@@ -40,10 +35,10 @@ async Task<IssueishCommentViewModel> CreateAndInitializeTarget(
4035 CommentModel comment ,
4136 string closeCaption ,
4237 ICommentService commentService = null ,
43- ICommentThreadViewModel thread = null ,
38+ IIssueishCommentThreadViewModel thread = null ,
4439 ActorModel currentUser = null )
4540 {
46- thread = thread ?? Substitute . For < ICommentThreadViewModel > ( ) ;
41+ thread = thread ?? Substitute . For < IIssueishCommentThreadViewModel > ( ) ;
4742 currentUser = currentUser ?? new ActorModel { Login = "grokys" } ;
4843
4944 var target = CreateTarget ( commentService ) ;
You can’t perform that action at this time.
0 commit comments