Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 50b04ac

Browse files
committed
Display PR details in document pane.
Next need to refactor out a common base class and create 2 different PR detail view models.
1 parent 38cae06 commit 50b04ac

File tree

13 files changed

+158
-15
lines changed

13 files changed

+158
-15
lines changed

src/GitHub.App/ViewModels/CommentViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ protected Task InitializeAsync(
195195
CurrentUser = new ActorViewModel(currentUser);
196196
Id = comment?.Id;
197197
DatabaseId = comment?.DatabaseId ?? 0;
198-
PullRequestId = comment?.PullRequestId ?? 0;
198+
PullRequestId = (comment as PullRequestReviewCommentModel)?.PullRequestId ?? 0;
199199
Body = comment?.Body;
200200
EditState = state;
201201
Author = comment != null ? new ActorViewModel(comment.Author) : CurrentUser;
Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,67 @@
11
using System;
22
using System.ComponentModel.Composition;
33
using System.Threading.Tasks;
4+
using GitHub.Extensions;
5+
using GitHub.Factories;
46
using GitHub.Models;
7+
using GitHub.Services;
8+
using GitHub.ViewModels.GitHubPane;
9+
using ReactiveUI;
510

611
namespace GitHub.ViewModels.Documents
712
{
813
[Export(typeof(IIssueishPaneViewModel))]
914
[PartCreationPolicy(CreationPolicy.NonShared)]
1015
public class IssueishPaneViewModel : ViewModelBase, IIssueishPaneViewModel
1116
{
17+
readonly IViewViewModelFactory factory;
18+
readonly IPullRequestSessionManager sessionManager;
19+
IViewModel content;
20+
21+
[ImportingConstructor]
22+
public IssueishPaneViewModel(
23+
IViewViewModelFactory factory,
24+
IPullRequestSessionManager sessionManager)
25+
{
26+
Guard.ArgumentNotNull(factory, nameof(factory));
27+
Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
28+
29+
this.factory = factory;
30+
this.sessionManager = sessionManager;
31+
}
32+
33+
public IViewModel Content
34+
{
35+
get => content;
36+
private set => this.RaiseAndSetIfChanged(ref content, value);
37+
}
38+
1239
public Task InitializeAsync(IServiceProvider paneServiceProvider)
1340
{
1441
return Task.CompletedTask;
1542
}
1643

17-
public Task Load(IConnection connection, string owner, string name, int number)
44+
public async Task Load(IConnection connection, string owner, string name, int number)
1845
{
19-
return Task.CompletedTask;
46+
Content = new SpinnerViewModel();
47+
48+
// TODO: We will eventually support loading issues here as well.
49+
try
50+
{
51+
var session = await sessionManager.GetSession(owner, name, number).ConfigureAwait(true);
52+
var vm = factory.CreateViewModel<IPullRequestDetailViewModel>();
53+
await vm.InitializeAsync(
54+
session.LocalRepository,
55+
connection,
56+
owner,
57+
name,
58+
number).ConfigureAwait(true);
59+
Content = vm;
60+
}
61+
catch (Exception ex)
62+
{
63+
// TODO: Show exception.
64+
}
2065
}
2166
}
2267
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.ComponentModel.Composition;
3+
4+
namespace GitHub.ViewModels
5+
{
6+
/// <summary>
7+
/// View model which displays a spinner.
8+
/// </summary>
9+
[Export(typeof(ISpinnerViewModel))]
10+
[PartCreationPolicy(CreationPolicy.NonShared)]
11+
public class SpinnerViewModel : ViewModelBase, ISpinnerViewModel
12+
{
13+
}
14+
}

src/GitHub.Exports/Models/CommentModel.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,6 @@ public class CommentModel
1717
/// </summary>
1818
public int DatabaseId { get; set; }
1919

20-
/// <summary>
21-
/// Gets the PullRequestId of the comment.
22-
/// </summary>
23-
public int PullRequestId { get; set; }
24-
// The GraphQL Api does not allow for deleting of pull request comments.
25-
// REST Api must be used, and PullRequestId is needed to reload the pull request.
26-
// This field should be removed with better GraphQL support.
27-
2820
/// <summary>
2921
/// Gets the author of the comment.
3022
/// </summary>

src/GitHub.Exports/Models/PullRequestDetailModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ public class PullRequestDetailModel
7878
/// </summary>
7979
public IReadOnlyList<PullRequestFileModel> ChangedFiles { get; set; }
8080

81+
/// <summary>
82+
/// Gets or sets a collection of comments on the pull request.
83+
/// </summary>
84+
public IReadOnlyList<CommentModel> Comments { get; set; }
85+
8186
/// <summary>
8287
/// Gets or sets a collection of pull request reviews.
8388
/// </summary>

src/GitHub.Exports/Models/PullRequestReviewCommentModel.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@ namespace GitHub.Models
77
/// </summary>
88
public class PullRequestReviewCommentModel : CommentModel
99
{
10+
/// <summary>
11+
/// Gets the PullRequestId of the comment.
12+
/// </summary>
13+
/// <remarks>
14+
/// The GraphQL Api does not allow for deleting of pull request comments.
15+
/// REST Api must be used, and PullRequestId is needed to reload the pull request.
16+
/// This field should be removed with better GraphQL support.
17+
/// </remarks>
18+
public int PullRequestId { get; set; }
19+
1020
/// <summary>
1121
/// Gets or sets the associated thread that contains the comment.
1222
/// </summary>

src/GitHub.Exports/ViewModels/Documents/IIssueishPaneViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ namespace GitHub.ViewModels.Documents
99
/// </summary>
1010
public interface IIssueishPaneViewModel : IPaneViewModel
1111
{
12+
/// <summary>
13+
/// Gets the content to display in the document pane.
14+
/// </summary>
15+
IViewModel Content { get; }
16+
1217
/// <summary>
1318
/// Loads an issue or pull request into the view model.
1419
/// </summary>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace GitHub.ViewModels
4+
{
5+
/// <summary>
6+
/// View model which displays a spinner.
7+
/// </summary>
8+
public interface ISpinnerViewModel : IViewModel
9+
{
10+
}
11+
}

src/GitHub.InlineReviews/Services/PullRequestSessionService.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,19 @@ public virtual async Task<PullRequestDetailModel> ReadPullRequestDetail(HostAddr
304304
HeadRepositoryOwner = pr.HeadRepositoryOwner != null ? pr.HeadRepositoryOwner.Login : null,
305305
State = pr.State.FromGraphQl(),
306306
UpdatedAt = pr.UpdatedAt,
307+
Comments = pr.Comments(null, null, null, null).AllPages().Select(comment => new CommentModel
308+
{
309+
Id = comment.Id.Value,
310+
Author = new ActorModel
311+
{
312+
Login = comment.Author.Login,
313+
AvatarUrl = comment.Author.AvatarUrl(null),
314+
},
315+
Body = comment.Body,
316+
CreatedAt = comment.CreatedAt,
317+
DatabaseId = comment.DatabaseId.Value,
318+
Url = comment.Url,
319+
}).ToList(),
307320
Reviews = pr.Reviews(null, null, null, null, null, null).AllPages().Select(review => new PullRequestReviewModel
308321
{
309322
Id = review.Id.Value,

src/GitHub.VisualStudio.UI/GitHub.VisualStudio.UI.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,8 @@
2929
<PackageReference Include="Microsoft.VisualStudio.ImageCatalog" version="14.3.25407" />
3030
<PackageReference Include="Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime" version="14.3.25407" />
3131
</ItemGroup>
32+
33+
<ItemGroup>
34+
<Folder Include="Views\Documents\" />
35+
</ItemGroup>
3236
</Project>

0 commit comments

Comments
 (0)