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

Commit f45b329

Browse files
Switching to a dictionary based on file path
1 parent e2e4b6c commit f45b329

File tree

4 files changed

+103
-72
lines changed

4 files changed

+103
-72
lines changed

src/GitHub.App/SampleData/PullRequestAnnotationsViewModelDesigner.cs

Lines changed: 53 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,63 @@ public sealed class PullRequestAnnotationsViewModelDesigner : PanePageViewModelB
2020
public ReactiveCommand<Unit, Unit> NavigateToPullRequest { get; }
2121
public string PullRequestTitle { get; } = "Fixing stuff in this PR";
2222
public string CheckSuiteName { get; } = "Awesome Check Suite";
23-
public string CheckRunName { get; } = "Psuedo Check Run";
24-
public IReadOnlyList<IPullRequestAnnotationItemViewModel> Annotations { get; } = new[]
25-
{
26-
new PullRequestAnnotationItemViewModelDesigner{
27-
Annotation = new CheckRunAnnotationModel
23+
public IReadOnlyDictionary<string, IReadOnlyList<IPullRequestAnnotationItemViewModel>> AnnotationsDictionary { get; }
24+
= new Dictionary<string, IReadOnlyList<IPullRequestAnnotationItemViewModel>>
25+
{
2826
{
29-
AnnotationLevel = CheckAnnotationLevel.Notice,
30-
StartLine = 3,
31-
EndLine = 4,
32-
Path = "asdf/asdf.cs",
33-
Message = "; is expected",
34-
Title = "CS 12345"
27+
"asdf/asdf.cs",
28+
new IPullRequestAnnotationItemViewModel[]
29+
{
30+
new PullRequestAnnotationItemViewModelDesigner
31+
{
32+
Annotation = new CheckRunAnnotationModel
33+
{
34+
AnnotationLevel = CheckAnnotationLevel.Notice,
35+
StartLine = 3,
36+
EndLine = 4,
37+
Path = "asdf/asdf.cs",
38+
Message = "; is expected",
39+
Title = "CS 12345"
40+
},
41+
IsExpanded = true,
42+
},
43+
new PullRequestAnnotationItemViewModelDesigner
44+
{
45+
Annotation = new CheckRunAnnotationModel
46+
{
47+
AnnotationLevel = CheckAnnotationLevel.Notice,
48+
StartLine = 3,
49+
EndLine = 4,
50+
Path = "asdf/asdf.cs",
51+
Message = "; is expected",
52+
Title = "CS 12345"
53+
},
54+
IsExpanded = true,
55+
},
56+
}
3557
},
36-
IsExpanded = true,
37-
},
38-
new PullRequestAnnotationItemViewModelDesigner{
39-
Annotation = new CheckRunAnnotationModel
4058
{
41-
AnnotationLevel = CheckAnnotationLevel.Warning,
42-
StartLine = 3,
43-
EndLine = 4,
44-
Path = "asdf/asdf.cs",
45-
Message = "; is expected",
46-
Title = "CS 12345"
59+
"blah.cs",
60+
new IPullRequestAnnotationItemViewModel[]
61+
{
62+
new PullRequestAnnotationItemViewModelDesigner
63+
{
64+
Annotation = new CheckRunAnnotationModel
65+
{
66+
AnnotationLevel = CheckAnnotationLevel.Notice,
67+
StartLine = 3,
68+
EndLine = 4,
69+
Path = "blah.cs",
70+
Message = "; is expected",
71+
Title = "CS 12345"
72+
},
73+
IsExpanded = true,
74+
}
75+
}
4776
},
48-
IsExpanded = true
49-
},
50-
new PullRequestAnnotationItemViewModelDesigner{
51-
Annotation = new CheckRunAnnotationModel
52-
{
53-
AnnotationLevel = CheckAnnotationLevel.Failure,
54-
StartLine = 3,
55-
EndLine = 4,
56-
Path = "blah.cs",
57-
Message = "; is expected",
58-
Title = "CS 12345"
59-
}
60-
}
61-
};
77+
};
78+
79+
public string CheckRunName { get; } = "Psuedo Check Run";
6280

6381
public Task InitializeAsync(ILocalRepositoryModel localRepository, IConnection connection, string owner, string repo,
6482
int pullRequestNumber, string checkRunId)

src/GitHub.App/ViewModels/GitHubPane/PullRequestAnnotationsViewModel.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class PullRequestAnnotationsViewModel : PanePageViewModelBase, IPullReque
2323
string title;
2424
string checkSuiteName;
2525
string checkRunName;
26-
IReadOnlyList<IPullRequestAnnotationItemViewModel> annotations;
26+
IReadOnlyDictionary<string, IReadOnlyList<IPullRequestAnnotationItemViewModel>> annotationsDictionary;
2727

2828
/// <summary>
2929
/// Initializes a new instance of the <see cref="PullRequestAnnotationsViewModel"/> class.
@@ -101,11 +101,10 @@ public string CheckRunName
101101
private set { this.RaiseAndSetIfChanged(ref checkRunName, value); }
102102
}
103103

104-
/// <inheritdoc/>
105-
public IReadOnlyList<IPullRequestAnnotationItemViewModel> Annotations
104+
public IReadOnlyDictionary<string, IReadOnlyList<IPullRequestAnnotationItemViewModel>> AnnotationsDictionary
106105
{
107-
get { return annotations; }
108-
private set { this.RaiseAndSetIfChanged(ref annotations, value); }
106+
get { return annotationsDictionary; }
107+
private set { this.RaiseAndSetIfChanged(ref annotationsDictionary, value); }
109108
}
110109

111110
void Load(PullRequestDetailModel pullRequest)
@@ -123,14 +122,19 @@ void Load(PullRequestDetailModel pullRequest)
123122

124123
CheckSuiteName = checkSuiteRun.checkSuite.ApplicationName;
125124
CheckRunName = checkSuiteRun.checkRun.Name;
126-
Annotations = checkSuiteRun.checkRun.Annotations
127-
.Select(annotation => new PullRequestAnnotationItemViewModel(annotation))
128-
.ToArray();
125+
126+
AnnotationsDictionary = checkSuiteRun.checkRun.Annotations
127+
.GroupBy(model => model.Path)
128+
.ToDictionary(
129+
annotation => annotation.Key,
130+
annotation => (IReadOnlyList<IPullRequestAnnotationItemViewModel>) annotation
131+
.Select(model => new PullRequestAnnotationItemViewModel(model)));
129132
}
130133
finally
131134
{
132135
IsBusy = false;
133136
}
134137
}
138+
135139
}
136140
}

src/GitHub.Exports.Reactive/ViewModels/GitHubPane/IPullRequestAnnotationsViewModel.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ public interface IPullRequestAnnotationsViewModel : IPanePageViewModel
5252
ReactiveCommand<Unit, Unit> NavigateToPullRequest { get; }
5353

5454
/// <summary>
55-
/// Gets the list of annotations.
55+
/// Name of the Check Suite.
5656
/// </summary>
57-
IReadOnlyList<IPullRequestAnnotationItemViewModel> Annotations { get; }
57+
string CheckSuiteName { get; }
5858

5959
/// <summary>
60-
/// Name of the Check Suite.
60+
/// Gets a dictionary of annotations by file path.
6161
/// </summary>
62-
string CheckSuiteName { get; }
62+
IReadOnlyDictionary<string, IReadOnlyList<IPullRequestAnnotationItemViewModel>> AnnotationsDictionary { get; }
6363

6464
/// <summary>
6565
/// Initializes the view model.

src/GitHub.VisualStudio.UI/Views/GitHubPane/PullRequestAnnotationsView.xaml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
<ScrollViewer VerticalScrollBarVisibility="Auto">
2828
<StackPanel>
2929
<StackPanel DockPanel.Dock="Top" Margin="8 0" Orientation="Vertical">
30-
<TextBlock FontSize="16" VerticalAlignment="Center">
30+
<TextBlock FontSize="16" VerticalAlignment="Center">
3131
<Run FontWeight="SemiBold" Text="{Binding CheckSuiteName, Mode=OneWay}"/>
32-
</TextBlock>
32+
</TextBlock>
3333
<TextBlock FontSize="16" VerticalAlignment="Center">
3434
<Run FontWeight="SemiBold" Text="{Binding CheckRunName, Mode=OneWay}"/>
3535
<Run>for</Run>
@@ -45,34 +45,43 @@
4545
<StackPanel Orientation="Horizontal" Margin="0 4">
4646
</StackPanel>
4747

48-
<ItemsControl ItemsSource="{Binding Annotations}">
48+
<ItemsControl ItemsSource="{Binding AnnotationsDictionary}">
4949
<ItemsControl.ItemTemplate>
5050
<DataTemplate>
5151
<StackPanel>
52-
<Rectangle Fill="{DynamicResource GitHubHeaderSeparatorBrush}" Height="1" Margin="0 4"/>
52+
<Label Content="{Binding Key}"></Label>
5353

54-
<Expander Margin="0 0 4 0"
55-
Foreground="{DynamicResource GitHubVsToolWindowText}"
56-
IsExpanded="{Binding IsExpanded, Mode=OneTime}">
57-
<Expander.Header>
58-
<StackPanel Orientation="Horizontal">
59-
<ghfvs:OcticonImage Margin="0 0 0 0" MinWidth="20" Icon="search" Foreground="CornflowerBlue" Visibility="{Binding Annotation.AnnotationLevel, Converter={ghfvs:EqualsToVisibilityConverter Notice}}"/>
60-
<ghfvs:OcticonImage Margin="0 0 0 0" MinWidth="20" Icon="alert" Foreground="#f1c647" Visibility="{Binding Annotation.AnnotationLevel, Converter={ghfvs:EqualsToVisibilityConverter Warning}}"/>
61-
<ghfvs:OcticonImage Margin="0 0 0 0" MinWidth="20" Icon="x" Foreground="#cb2431" Visibility="{Binding Annotation.AnnotationLevel, Converter={ghfvs:EqualsToVisibilityConverter Failure}}"/>
62-
<TextBlock FontWeight="SemiBold" Margin="2 0">
63-
<Run Text="{Binding Annotation.Title, Mode=OneWay}"/>
64-
</TextBlock>
65-
</StackPanel>
66-
</Expander.Header>
67-
<StackPanel Margin="21 4 0 4">
68-
<TextBlock Margin="5 4 0 0">
69-
<Run Text="{Binding Annotation.Path, Mode=OneWay}"/>
70-
<Run FontWeight="SemiBold" Text="{Binding LineDescription, Mode=OneWay}"/>
71-
</TextBlock>
72-
<markdig:MarkdownViewer Margin="5 0 0 0" Markdown="{Binding Annotation.Message}"/>
73-
</StackPanel>
74-
</Expander>
54+
<ItemsControl ItemsSource="{Binding Value}">
55+
<ItemsControl.ItemTemplate>
56+
<DataTemplate>
57+
<StackPanel>
58+
<Rectangle Fill="{DynamicResource GitHubHeaderSeparatorBrush}" Height="1" Margin="0 4"/>
59+
60+
<Expander Margin="0 0 4 0" Foreground="{DynamicResource GitHubVsToolWindowText}" IsExpanded="{Binding IsExpanded, Mode=OneTime}">
61+
<Expander.Header>
62+
<StackPanel Orientation="Horizontal">
63+
<ghfvs:OcticonImage Margin="0 0 0 0" MinWidth="20" Icon="search" Foreground="CornflowerBlue" Visibility="{Binding Annotation.AnnotationLevel, Converter={ghfvs:EqualsToVisibilityConverter Notice}}"/>
64+
<ghfvs:OcticonImage Margin="0 0 0 0" MinWidth="20" Icon="alert" Foreground="#f1c647" Visibility="{Binding Annotation.AnnotationLevel, Converter={ghfvs:EqualsToVisibilityConverter Warning}}"/>
65+
<ghfvs:OcticonImage Margin="0 0 0 0" MinWidth="20" Icon="x" Foreground="#cb2431" Visibility="{Binding Annotation.AnnotationLevel, Converter={ghfvs:EqualsToVisibilityConverter Failure}}"/>
66+
<TextBlock FontWeight="SemiBold" Margin="2 0">
67+
<Run Text="{Binding Annotation.Title, Mode=OneWay}"/>
68+
</TextBlock>
69+
</StackPanel>
70+
</Expander.Header>
71+
<StackPanel Margin="21 4 0 4">
72+
<TextBlock Margin="5 4 0 0">
73+
<Run Text="{Binding Annotation.Path, Mode=OneWay}"/>
74+
<Run FontWeight="SemiBold" Text="{Binding LineDescription, Mode=OneWay}"/>
75+
</TextBlock>
76+
<markdig:MarkdownViewer Margin="5 0 0 0" Markdown="{Binding Annotation.Message}"/>
77+
</StackPanel>
78+
</Expander>
79+
</StackPanel>
80+
</DataTemplate>
81+
</ItemsControl.ItemTemplate>
82+
</ItemsControl>
7583
</StackPanel>
84+
7685
</DataTemplate>
7786
</ItemsControl.ItemTemplate>
7887
</ItemsControl>

0 commit comments

Comments
 (0)