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

Commit 7b6a032

Browse files
committed
Finish off display of commit list w/caption.
1 parent 8340942 commit 7b6a032

File tree

15 files changed

+260
-100
lines changed

15 files changed

+260
-100
lines changed

src/GitHub.App/SampleData/Documents/PullRequestPageViewModelDesigner.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Depends on #1993
5656
Fixes #1905";
5757
Timeline = new IViewModel[]
5858
{
59-
new CommitSummariesViewModel(
59+
new CommitListViewModel(
6060
new CommitSummaryViewModel(new CommitModel
6161
{
6262
Author = new ActorModel { Login = "grokys" },
@@ -65,7 +65,7 @@ Depends on #1993
6565
}),
6666
new CommitSummaryViewModel(new CommitModel
6767
{
68-
Author = new ActorModel { Login = "grokys" },
68+
Author = new ActorModel { Login = "shana" },
6969
AbbreviatedOid = "04e6a90",
7070
MessageHeadline = "Refactor comment view models.",
7171
})),
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
6+
namespace GitHub.ViewModels.Documents
7+
{
8+
/// <summary>
9+
/// Displays a list of commit summaries in a pull request timeline.
10+
/// </summary>
11+
public class CommitListViewModel : ViewModelBase, ICommitListViewModel
12+
{
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="CommitListViewModel"/> class.
15+
/// </summary>
16+
/// <param name="commits">The commits to display.</param>
17+
public CommitListViewModel(params ICommitSummaryViewModel[] commits)
18+
{
19+
if (commits.Length == 0)
20+
{
21+
throw new NotSupportedException("Cannot create a CommitListViewModel with 0 commits.");
22+
}
23+
24+
Commits = commits;
25+
Author = Commits[0].Author;
26+
AuthorCaption = BuildAuthorCaption();
27+
}
28+
29+
/// <summary>
30+
/// Initializes a new instance of the <see cref="CommitListViewModel"/> class.
31+
/// </summary>
32+
/// <param name="commits">The commits to display.</param>
33+
public CommitListViewModel(IEnumerable<ICommitSummaryViewModel> commits)
34+
{
35+
Commits = commits.ToList();
36+
37+
if (Commits.Count == 0)
38+
{
39+
throw new NotSupportedException("Cannot create a CommitListViewModel with 0 commits.");
40+
}
41+
42+
Author = Commits[0].Author;
43+
AuthorCaption = BuildAuthorCaption();
44+
}
45+
46+
/// <inheritdoc/>
47+
public IActorViewModel Author { get; }
48+
49+
/// <inheritdoc/>
50+
public string AuthorCaption { get; }
51+
52+
/// <inheritdoc/>
53+
public IReadOnlyList<ICommitSummaryViewModel> Commits { get; }
54+
55+
string BuildAuthorCaption()
56+
{
57+
var result = new StringBuilder();
58+
59+
if (Commits.Any(x => x.Author.Login != Author.Login))
60+
{
61+
result.Append(Resources.AndOthers);
62+
result.Append(' ');
63+
}
64+
65+
result.Append(Resources.AddedSomeCommits);
66+
return result.ToString();
67+
}
68+
}
69+
}

src/GitHub.App/ViewModels/Documents/CommitSummariesViewModel.cs

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

src/GitHub.App/ViewModels/Documents/CommitSummaryViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
namespace GitHub.ViewModels.Documents
44
{
5-
public class CommitSummaryViewModel : ViewModelBase
5+
/// <summary>
6+
/// Displays a one-line summary of a commit in a pull request timeline.
7+
/// </summary>
8+
public class CommitSummaryViewModel : ViewModelBase, ICommitSummaryViewModel
69
{
710
/// <summary>
811
/// Initializes a new instance of the <see cref="CommitSummaryViewModel"/> class.

src/GitHub.App/ViewModels/Documents/PullRequestPageViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public async Task InitializeAsync(
8484
{
8585
if (!(i is CommitModel) && commits.Count > 0)
8686
{
87-
timeline.Add(new CommitSummariesViewModel(commits));
87+
timeline.Add(new CommitListViewModel(commits));
8888
commits.Clear();
8989
}
9090

@@ -102,7 +102,7 @@ public async Task InitializeAsync(
102102

103103
if (commits.Count > 0)
104104
{
105-
timeline.Add(new CommitSummariesViewModel(commits));
105+
timeline.Add(new CommitListViewModel(commits));
106106
}
107107

108108
await AddPlaceholder().ConfigureAwait(true);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace GitHub.ViewModels.Documents
5+
{
6+
/// <summary>
7+
/// Displays a list of commit summaries in a pull request timeline.
8+
/// </summary>
9+
public interface ICommitListViewModel : IViewModel
10+
{
11+
/// <summary>
12+
/// Gets the first author of the commits in the list.
13+
/// </summary>
14+
IActorViewModel Author { get; }
15+
16+
/// <summary>
17+
/// Gets a string to display next to the author in the view.
18+
/// </summary>
19+
string AuthorCaption { get; }
20+
21+
/// <summary>
22+
/// Gets the commits.
23+
/// </summary>
24+
IReadOnlyList<ICommitSummaryViewModel> Commits { get; }
25+
}
26+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace GitHub.ViewModels.Documents
2+
{
3+
/// <summary>
4+
/// Displays a one-line summary of a commit in a pull request timeline.
5+
/// </summary>
6+
public interface ICommitSummaryViewModel : IViewModel
7+
{
8+
/// <summary>
9+
/// Gets the abbreviated OID (SHA) of the commit.
10+
/// </summary>
11+
string AbbreviatedOid { get; }
12+
13+
/// <summary>
14+
/// Gets the commit author.
15+
/// </summary>
16+
IActorViewModel Author { get; }
17+
18+
/// <summary>
19+
/// Gets the commit message header.
20+
/// </summary>
21+
string Header { get; }
22+
23+
/// <summary>
24+
/// Gets the OID (SHA) of the commit.
25+
/// </summary>
26+
string Oid { get; }
27+
}
28+
}

src/GitHub.Resources/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.Resources/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,4 +863,10 @@ https://git-scm.com/download/win</value>
863863
<data name="CommitCountFormat" xml:space="preserve">
864864
<value>{0} commits</value>
865865
</data>
866+
<data name="AddedSomeCommits" xml:space="preserve">
867+
<value>added some commits</value>
868+
</data>
869+
<data name="AndOthers" xml:space="preserve">
870+
<value>and others</value>
871+
</data>
866872
</root>
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<UserControl x:Class="GitHub.VisualStudio.Views.Documents.CommitListView"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
6+
xmlns:ghfvs="https://github.com/github/VisualStudio"
7+
xmlns:v="clr-namespace:GitHub.VisualStudio.Views"
8+
mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800">
9+
<Control.Resources>
10+
<ResourceDictionary>
11+
<ResourceDictionary.MergedDictionaries>
12+
<ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.VisualStudio.UI;component/SharedDictionary.xaml" />
13+
<ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
14+
<ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI.Reactive;component/SharedDictionary.xaml" />
15+
<ghfvs:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/Assets/Markdown.xaml" />
16+
</ResourceDictionary.MergedDictionaries>
17+
</ResourceDictionary>
18+
</Control.Resources>
19+
20+
<StackPanel Orientation="Vertical">
21+
<StackPanel Orientation="Horizontal" Margin="0,8">
22+
<ghfvs:OcticonImage DockPanel.Dock="Left"
23+
Margin="2 0 4 0"
24+
Width="16"
25+
Icon="repo_push"
26+
Grid.Column="0"
27+
HorizontalAlignment="Center" />
28+
29+
<v:ActorAvatarView Width="16"
30+
Height="16"
31+
Grid.Column="1"
32+
ViewModel="{Binding Author}"/>
33+
34+
<TextBlock Margin="4 0" Grid.Column="2">
35+
<Run FontWeight="Bold" Text="{Binding Author.Login, Mode=OneWay}" />
36+
<Run Text="{Binding AuthorCaption, Mode=OneWay}" />
37+
</TextBlock>
38+
</StackPanel>
39+
40+
<ItemsControl ItemsSource="{Binding Commits}">
41+
<Control.Resources>
42+
<DataTemplate DataType="{x:Type ghfvs:CommitSummaryViewModel}">
43+
<Border Padding="24 0 8 0">
44+
<DockPanel>
45+
<ghfvs:OcticonImage DockPanel.Dock="Left"
46+
Foreground="{DynamicResource VsBrush.GrayText}"
47+
Margin="0,0,2,0"
48+
Icon="git_commit"/>
49+
<v:ActorAvatarView DockPanel.Dock="Left"
50+
Width="16"
51+
Height="16"
52+
Margin="2"
53+
ViewModel="{Binding Author}"/>
54+
<TextBlock DockPanel.Dock="Right"
55+
FontFamily="Consolas"
56+
Margin="0,0,0,2"
57+
VerticalAlignment="Center">
58+
<Hyperlink Command="{Binding DataContext.ShowCommit, ElementName=timeline}"
59+
CommandParameter="{Binding Oid}">
60+
<Run Text="{Binding AbbreviatedOid, Mode=OneWay}"/>
61+
</Hyperlink>
62+
</TextBlock>
63+
<TextBlock Margin="0,0,0,2"
64+
Foreground="{DynamicResource VsBrush.WindowText}"
65+
Text="{Binding Header}"
66+
VerticalAlignment="Center"/>
67+
</DockPanel>
68+
</Border>
69+
</DataTemplate>
70+
</Control.Resources>
71+
</ItemsControl>
72+
73+
<Border BorderThickness="0,1,0,0"
74+
BorderBrush="{DynamicResource GitHubHeaderSeparatorBrush}"
75+
DockPanel.Dock="Bottom"
76+
Margin="0,8,0,0"
77+
Padding="0,4,0,0" />
78+
</StackPanel>
79+
</UserControl>

0 commit comments

Comments
 (0)