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

Commit 2775886

Browse files
committed
Remove need for CommentTooltip(View/Model/Designer)
Use CommentThreadViewModel as the base for TooltipCommentThreadViewModel. Use ICommentThreadViewModel as the VM interface for TooltipCommentThreadView. Allows null to be passed when `currentUser` isn't required.
1 parent bc4fbfc commit 2775886

11 files changed

+44
-118
lines changed

src/GitHub.InlineReviews/GitHub.InlineReviews.csproj

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@
9797
<DesignTime>True</DesignTime>
9898
<DependentUpon>Resources.resx</DependentUpon>
9999
</Compile>
100-
<Compile Include="SampleData\CommentTooltipViewModelDesigner.cs" />
101100
<Compile Include="SampleData\CommentThreadViewModelDesigner.cs" />
102101
<Compile Include="SampleData\DiffCommentThreadViewModelDesigner.cs" />
103102
<Compile Include="SampleData\PullRequestCommentsViewModelDesigner.cs" />
@@ -108,10 +107,8 @@
108107
<Compile Include="Services\PullRequestSessionManager.cs" />
109108
<Compile Include="InlineCommentMarginProvider.cs" />
110109
<Compile Include="Services\PullRequestSessionService.cs" />
111-
<Compile Include="ViewModels\CommentTooltipViewModel.cs" />
112110
<Compile Include="ViewModels\CommentViewModel.cs" />
113111
<Compile Include="ViewModels\DiffCommentThreadViewModel.cs" />
114-
<Compile Include="ViewModels\ICommentTooltipViewModel.cs" />
115112
<Compile Include="ViewModels\ICommentThreadViewModel.cs" />
116113
<Compile Include="ViewModels\CommentThreadViewModel.cs" />
117114
<Compile Include="ViewModels\IDiffCommentThreadViewModel.cs" />
@@ -122,9 +119,9 @@
122119
<Compile Include="ViewModels\IPullRequestCommentsViewModel.cs" />
123120
<Compile Include="ViewModels\IssueCommentThreadViewModel.cs" />
124121
<Compile Include="ViewModels\PullRequestCommentsViewModel.cs" />
125-
<Compile Include="ViewModels\TooltipCommentViewModel.cs" />
126-
<Compile Include="Views\CommentTooltipView.xaml.cs">
127-
<DependentUpon>CommentTooltipView.xaml</DependentUpon>
122+
<Compile Include="ViewModels\TooltipCommentThreadViewModel.cs" />
123+
<Compile Include="Views\TooltipCommentThreadView.xaml.cs">
124+
<DependentUpon>TooltipCommentThreadView.xaml</DependentUpon>
128125
</Compile>
129126
<Compile Include="Views\DiffCommentThreadView.xaml.cs">
130127
<DependentUpon>DiffCommentThreadView.xaml</DependentUpon>
@@ -402,7 +399,7 @@
402399
</EmbeddedResource>
403400
</ItemGroup>
404401
<ItemGroup>
405-
<Page Include="Views\CommentTooltipView.xaml">
402+
<Page Include="Views\TooltipCommentThreadView.xaml">
406403
<Generator>MSBuild:Compile</Generator>
407404
<SubType>Designer</SubType>
408405
</Page>

src/GitHub.InlineReviews/SampleData/CommentTooltipViewModelDesigner.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/GitHub.InlineReviews/Tags/ShowInlineCommentGlyph.xaml.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Windows.Controls;
33
using GitHub.InlineReviews.Views;
44
using GitHub.InlineReviews.ViewModels;
5+
using System.Linq;
6+
using GitHub.Models;
57

68
namespace GitHub.InlineReviews.Tags
79
{
@@ -15,15 +17,15 @@ public ShowInlineCommentGlyph()
1517
protected override void OnToolTipOpening(ToolTipEventArgs e)
1618
{
1719
var tag = Tag as ShowInlineCommentTag;
18-
19-
var viewModel = new CommentTooltipViewModel();
20-
foreach (var comment in tag.Thread.Comments)
20+
var comments = tag.Thread.Comments.Select(comment => new PullRequestReviewCommentModel
2121
{
22-
var commentViewModel = new TooltipCommentViewModel(comment.User, comment.Body, comment.CreatedAt);
23-
viewModel.Comments.Add(commentViewModel);
24-
}
22+
User = comment.User,
23+
Body = comment.Body,
24+
CreatedAt = comment.CreatedAt
25+
});
2526

26-
var view = new CommentTooltipView();
27+
var viewModel = new TooltipCommentThreadViewModel(comments);
28+
var view = new TooltipCommentThreadView();
2729
view.DataContext = viewModel;
2830

2931
CommentToolTip.Content = view;

src/GitHub.InlineReviews/ViewModels/CommentThreadViewModel.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ public abstract class CommentThreadViewModel : ReactiveObject, ICommentThreadVie
1717
/// <summary>
1818
/// Intializes a new instance of the <see cref="CommentThreadViewModel"/> class.
1919
/// </summary>
20-
/// <param name="currentUser">The current user.</param>
20+
/// <param name="currentUser">The current user on null if not required.</param>
2121
/// <param name="commentModels">The thread comments.</param>
22-
public CommentThreadViewModel(IAccount currentUser)
22+
public CommentThreadViewModel(IAccount currentUser = null)
2323
{
24-
Guard.ArgumentNotNull(currentUser, nameof(currentUser));
25-
2624
Comments = new ObservableCollection<ICommentViewModel>();
2725
CurrentUser = currentUser;
2826
}

src/GitHub.InlineReviews/ViewModels/CommentTooltipViewModel.cs

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class CommentViewModel : ReactiveObject, ICommentViewModel
2525
/// Initializes a new instance of the <see cref="CommentViewModel"/> class.
2626
/// </summary>
2727
/// <param name="thread">The thread that the comment is a part of.</param>
28-
/// <param name="currentUser">The current user.</param>
28+
/// <param name="currentUser">The current user or null if not used.</param>
2929
/// <param name="commentId">The ID of the comment.</param>
3030
/// <param name="body">The comment body.</param>
3131
/// <param name="state">The comment edit state.</param>
@@ -41,7 +41,6 @@ public CommentViewModel(
4141
DateTimeOffset updatedAt)
4242
{
4343
Guard.ArgumentNotNull(thread, nameof(thread));
44-
Guard.ArgumentNotNull(currentUser, nameof(currentUser));
4544
Guard.ArgumentNotNull(body, nameof(body));
4645
Guard.ArgumentNotNull(user, nameof(user));
4746

src/GitHub.InlineReviews/ViewModels/ICommentTooltipViewModel.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using GitHub.Models;
4+
5+
namespace GitHub.InlineReviews.ViewModels
6+
{
7+
public class TooltipCommentThreadViewModel : CommentThreadViewModel
8+
{
9+
public TooltipCommentThreadViewModel(IEnumerable<IPullRequestReviewCommentModel> comments)
10+
{
11+
foreach (var comment in comments)
12+
{
13+
Comments.Add(new CommentViewModel(this, CurrentUser, comment));
14+
}
15+
}
16+
}
17+
}

src/GitHub.InlineReviews/ViewModels/TooltipCommentViewModel.cs

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/GitHub.InlineReviews/Views/CommentTooltipView.xaml renamed to src/GitHub.InlineReviews/Views/TooltipCommentThreadView.xaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<local:GenericCommentTooltipView x:Class="GitHub.InlineReviews.Views.CommentTooltipView"
1+
<UserControl x:Class="GitHub.InlineReviews.Views.TooltipCommentThreadView"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -9,8 +9,8 @@
99
xmlns:sample="clr-namespace:GitHub.InlineReviews.SampleData"
1010
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
1111
<d:DesignProperties.DataContext>
12-
<sample:CommentTooltipViewModelDesigner>
13-
<sample:CommentTooltipViewModelDesigner.Comments>
12+
<sample:CommentThreadViewModelDesigner>
13+
<sample:CommentThreadViewModelDesigner.Comments>
1414
<sample:CommentViewModelDesigner EditState="None">
1515
<sample:CommentViewModelDesigner.Body>
1616
I assume this doesn't do anything if our message isn't showing?
@@ -21,8 +21,8 @@
2121
Nope, does nothing! Also checked the logs.
2222
</sample:CommentViewModelDesigner.Body>
2323
</sample:CommentViewModelDesigner>
24-
</sample:CommentTooltipViewModelDesigner.Comments>
25-
</sample:CommentTooltipViewModelDesigner>
24+
</sample:CommentThreadViewModelDesigner.Comments>
25+
</sample:CommentThreadViewModelDesigner>
2626
</d:DesignProperties.DataContext>
2727

2828
<DockPanel>
@@ -40,4 +40,4 @@
4040
</ItemsControl>
4141
</ScrollViewer>
4242
</DockPanel>
43-
</local:GenericCommentTooltipView>
43+
</UserControl>

0 commit comments

Comments
 (0)