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

Commit 57c9fff

Browse files
authored
Merge branch 'master' into donokuda/pr-list-polish
2 parents 7a0354d + 541e3ba commit 57c9fff

35 files changed

+355
-64
lines changed

src/GitHub.App/Collections/IVirtualizingListSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace GitHub.Collections
1010
/// </summary>
1111
/// <typeparam name="T">The item type.</typeparam>
1212
/// <remarks>
13-
/// This interface is used the the <see cref="VirtualizingList{T}"/> class to load pages of data.
13+
/// This interface is used by the <see cref="VirtualizingList{T}"/> class to load pages of data.
1414
/// </remarks>
1515
public interface IVirtualizingListSource<T> : IDisposable, INotifyPropertyChanged
1616
{

src/GitHub.App/GitHub.App.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,9 @@
194194
<HintPath>..\..\packages\Rx-XAML.2.2.5-custom\lib\net45\System.Reactive.Windows.Threading.dll</HintPath>
195195
<Private>True</Private>
196196
</Reference>
197+
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
198+
<HintPath>..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
199+
</Reference>
197200
<Reference Include="System.Web" />
198201
<Reference Include="System.Xaml" />
199202
<Reference Include="System.Xml.Linq" />

src/GitHub.App/SampleData/PullRequestListViewModelDesigner.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@ public PullRequestListViewModelDesigner()
5959
public IReadOnlyList<IRepositoryModel> Forks { get; }
6060
public string SearchQuery { get; set; }
6161
public string SelectedState { get; set; }
62+
public string StateCaption { get; set; }
6263
public IReadOnlyList<string> States { get; }
64+
public Uri WebUrl => null;
6365
public ReactiveCommand<object> CreatePullRequest { get; }
6466
public ReactiveCommand<Unit> OpenItem { get; }
67+
public ReactiveCommand<object> OpenItemInBrowser { get; }
6568

6669
public Task InitializeAsync(ILocalRepositoryModel repository, IConnection connection) => Task.CompletedTask;
6770
}

src/GitHub.App/Services/RepositoryService.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace GitHub.Services
1414
[PartCreationPolicy(CreationPolicy.Shared)]
1515
public class RepositoryService : IRepositoryService
1616
{
17-
static ICompiledQuery<string> readParentOwnerLogin;
17+
static ICompiledQuery<Tuple<string, string>> readParentOwnerLogin;
1818
readonly IGraphQLClientFactory graphqlFactory;
1919

2020
[ImportingConstructor]
@@ -25,7 +25,7 @@ public RepositoryService(IGraphQLClientFactory graphqlFactory)
2525
this.graphqlFactory = graphqlFactory;
2626
}
2727

28-
public async Task<string> ReadParentOwnerLogin(HostAddress address, string owner, string name)
28+
public async Task<(string owner, string name)?> FindParent(HostAddress address, string owner, string name)
2929
{
3030
Guard.ArgumentNotNull(address, nameof(address));
3131
Guard.ArgumentNotEmptyString(owner, nameof(owner));
@@ -35,7 +35,7 @@ public async Task<string> ReadParentOwnerLogin(HostAddress address, string owner
3535
{
3636
readParentOwnerLogin = new Query()
3737
.Repository(Var(nameof(owner)), Var(nameof(name)))
38-
.Select(r => r.Parent != null ? r.Parent.Owner.Login : null)
38+
.Select(r => r.Parent != null ? Tuple.Create(r.Parent.Owner.Login, r.Parent.Name) : null)
3939
.Compile();
4040
}
4141

@@ -46,7 +46,8 @@ public async Task<string> ReadParentOwnerLogin(HostAddress address, string owner
4646
};
4747

4848
var graphql = await graphqlFactory.CreateConnection(address);
49-
return await graphql.Run(readParentOwnerLogin, vars);
49+
var result = await graphql.Run(readParentOwnerLogin, vars);
50+
return result != null ? (result.Item1, result.Item2) : ((string, string)?)null;
5051
}
5152
}
5253
}

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public abstract class IssueListViewModelBase : PanePageViewModelBase, IIssueList
3030
IReadOnlyList<IRepositoryModel> forks;
3131
string searchQuery;
3232
string selectedState;
33+
ObservableAsPropertyHelper<string> stateCaption;
3334
string stringFilter;
3435
int numberFilter;
3536
IUserFilterViewModel authorFilter;
@@ -42,6 +43,13 @@ public IssueListViewModelBase(IRepositoryService repositoryService)
4243
{
4344
this.repositoryService = repositoryService;
4445
OpenItem = ReactiveCommand.CreateAsyncTask(OpenItemImpl);
46+
stateCaption = this.WhenAnyValue(
47+
x => x.Items.Count,
48+
x => x.SelectedState,
49+
x => x.IsBusy,
50+
x => x.IsLoading,
51+
(count, state, busy, loading) => busy || loading ? state : count + " " + state)
52+
.ToProperty(this, x => x.StateCaption);
4553
}
4654

4755
/// <inheritdoc/>
@@ -106,6 +114,9 @@ public string SelectedState
106114
/// <inheritdoc/>
107115
public abstract IReadOnlyList<string> States { get; }
108116

117+
/// <inheritdoc/>
118+
public string StateCaption => stateCaption.Value;
119+
109120
/// <inheritdoc/>
110121
public ReactiveCommand<Unit> OpenItem { get; }
111122

@@ -116,20 +127,21 @@ public async Task InitializeAsync(ILocalRepositoryModel repository, IConnection
116127
SelectedState = States.FirstOrDefault();
117128
AuthorFilter = new UserFilterViewModel(LoadAuthors);
118129

119-
var parentOwner = await repositoryService.ReadParentOwnerLogin(
130+
var parent = await repositoryService.FindParent(
120131
HostAddress.Create(repository.CloneUrl),
121132
repository.Owner,
122133
repository.Name);
123134

124-
if (parentOwner == null)
135+
if (parent == null)
125136
{
126137
RemoteRepository = repository;
127138
}
128139
else
129140
{
141+
// TODO: Handle forks with different names.
130142
RemoteRepository = new RepositoryModel(
131143
repository.Name,
132-
UriString.ToUriString(repository.CloneUrl.ToRepositoryUrl(parentOwner)));
144+
UriString.ToUriString(repository.CloneUrl.ToRepositoryUrl(parent.Value.owner)));
133145

134146
Forks = new IRepositoryModel[]
135147
{

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.ComponentModel.Composition;
44
using System.Diagnostics;
5+
using System.Reactive.Linq;
56
using System.Threading.Tasks;
67
using GitHub.Collections;
78
using GitHub.Extensions;
@@ -24,6 +25,7 @@ public class PullRequestListViewModel : IssueListViewModelBase, IPullRequestList
2425
readonly IPullRequestSessionManager sessionManager;
2526
readonly IPullRequestService service;
2627
readonly IDisposable subscription;
28+
ObservableAsPropertyHelper<Uri> webUrl;
2729

2830
/// <summary>
2931
/// Initializes a new instance of the <see cref="PullRequestListViewModel"/> class.
@@ -45,15 +47,25 @@ public PullRequestListViewModel(
4547
this.service = service;
4648

4749
subscription = sessionManager.WhenAnyValue(x => x.CurrentSession.PullRequest.Number).Subscribe(UpdateCurrent);
50+
webUrl = this.WhenAnyValue(x => x.RemoteRepository)
51+
.Select(x => x?.CloneUrl?.ToRepositoryUrl().Append("pulls"))
52+
.ToProperty(this, x => x.WebUrl);
4853
CreatePullRequest = ReactiveCommand.Create().OnExecuteCompleted(_ => NavigateTo("pull/new"));
54+
OpenItemInBrowser = ReactiveCommand.Create();
4955
}
5056

5157
/// <inheritdoc/>
5258
public override IReadOnlyList<string> States => states;
5359

60+
/// <inheritdoc/>
61+
public Uri WebUrl => webUrl.Value;
62+
5463
/// <inheritdoc/>
5564
public ReactiveCommand<object> CreatePullRequest { get; }
5665

66+
/// <inheritdoc/>
67+
public ReactiveCommand<object> OpenItemInBrowser { get; }
68+
5769
/// <inheritdoc/>
5870
protected override IVirtualizingListSource<IIssueListItemViewModelBase> CreateItemSource()
5971
{

src/GitHub.App/ViewModels/UserFilterViewModel.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,11 @@ public class UserFilterViewModel : ViewModelBase, IUserFilterViewModel
2525

2626
public UserFilterViewModel(LoadPageDelegate load)
2727
{
28+
Guard.ArgumentNotNull(load, nameof(load));
29+
2830
this.load = load;
2931
this.WhenAnyValue(x => x.Filter).Subscribe(FilterChanged);
32+
this.WhenAnyValue(x => x.Selected).Subscribe(_ => Filter = null);
3033
ClearSelection = ReactiveCommand.Create(
3134
this.WhenAnyValue(x => x.Selected).Select(x => x != null))
3235
.OnExecuteCompleted(_ => Selected = null);
@@ -96,7 +99,7 @@ void FilterChanged(string filter)
9699
}
97100
}
98101

99-
usersView.Refresh();
102+
UsersView.Refresh();
100103
}
101104

102105
bool FilterUsers(object obj)

src/GitHub.App/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,5 @@
3333
<package id="SerilogAnalyzer" version="0.12.0.0" targetFramework="net461" />
3434
<package id="SQLitePCL.raw_basic" version="0.7.3.0-vs2012" targetFramework="net45" />
3535
<package id="Stateless" version="2.5.56.0" targetFramework="net45" />
36+
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
3637
</packages>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ public interface IIssueListViewModelBase : ISearchablePageViewModel
8989
/// </summary>
9090
IReadOnlyList<string> States { get; }
9191

92+
/// <summary>
93+
/// Gets the caption to display as the header on the <see cref="States"/> dropdown.
94+
/// </summary>
95+
string StateCaption { get; }
96+
9297
/// <summary>
9398
/// Gets a command which opens the item passed as a parameter.
9499
/// </summary>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ namespace GitHub.ViewModels.GitHubPane
66
/// <summary>
77
/// Represents a view model which displays a pull request list.
88
/// </summary>
9-
public interface IPullRequestListViewModel : IIssueListViewModelBase
9+
public interface IPullRequestListViewModel : IIssueListViewModelBase, IOpenInBrowser
1010
{
1111
/// <summary>
1212
/// Gets a command which navigates to the "Create Pull Request" view.
1313
/// </summary>
1414
ReactiveCommand<object> CreatePullRequest { get; }
15+
16+
/// <summary>
17+
/// Gets a command that opens pull request item on GitHub.
18+
/// </summary>
19+
ReactiveCommand<object> OpenItemInBrowser { get; }
1520
}
1621
}

0 commit comments

Comments
 (0)