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

Commit 5113951

Browse files
committed
Open clone dialog on tab for URL
Add IRepositoryCloneViewModel.Url property. Select the tab corresponding to the host. Don't select a tab when host doesn't match.
1 parent fe2a04f commit 5113951

File tree

5 files changed

+65
-2
lines changed

5 files changed

+65
-2
lines changed

src/GitHub.App/SampleData/Dialog/Clone/RepositoryCloneViewModelDesigner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Reactive;
33
using System.Threading.Tasks;
44
using GitHub.Models;
5+
using GitHub.Primitives;
56
using GitHub.ViewModels;
67
using GitHub.ViewModels.Dialog.Clone;
78
using ReactiveUI;
@@ -17,6 +18,7 @@ public RepositoryCloneViewModelDesigner()
1718
}
1819

1920
public string Path { get; set; }
21+
public UriString Url { get; set; }
2022
public string PathWarning { get; set; }
2123
public int SelectedTabIndex { get; set; }
2224
public string Title => null;

src/GitHub.App/Services/DialogService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public async Task<CloneDialogResult> ShowCloneDialog(IConnection connection, str
5151
var viewModel = factory.CreateViewModel<IRepositoryCloneViewModel>();
5252
if (url != null)
5353
{
54-
viewModel.GitHubTab.Filter = url;
55-
viewModel.EnterpriseTab.Filter = url;
54+
viewModel.Url = url;
5655
}
5756

5857
if (connection != null)

src/GitHub.App/ViewModels/Dialog/Clone/RepositoryCloneViewModel.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using GitHub.Extensions;
1010
using GitHub.Logging;
1111
using GitHub.Models;
12+
using GitHub.Primitives;
1213
using GitHub.Services;
1314
using ReactiveUI;
1415
using Rothko;
@@ -29,6 +30,7 @@ public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
2930
readonly IUsageTracker usageTracker;
3031
readonly IReadOnlyList<IRepositoryCloneTabViewModel> tabs;
3132
string path;
33+
UriString url;
3234
RepositoryModel previousRepository;
3335
ObservableAsPropertyHelper<string> pathWarning;
3436
int selectedTabIndex;
@@ -93,6 +95,12 @@ public string Path
9395
set => this.RaiseAndSetIfChanged(ref path, value);
9496
}
9597

98+
public UriString Url
99+
{
100+
get => url;
101+
set => this.RaiseAndSetIfChanged(ref url, value);
102+
}
103+
96104
public string PathWarning => pathWarning.Value;
97105

98106
public int SelectedTabIndex
@@ -132,6 +140,20 @@ public async Task InitializeAsync(IConnection connection)
132140
SelectedTabIndex = 1;
133141
}
134142

143+
if (Url?.Host is string host && HostAddress.Create(host) is HostAddress hostAddress)
144+
{
145+
if (hostAddress == gitHubConnection?.HostAddress)
146+
{
147+
GitHubTab.Filter = Url;
148+
SelectedTabIndex = 0;
149+
}
150+
else if (hostAddress == enterpriseConnection?.HostAddress)
151+
{
152+
EnterpriseTab.Filter = Url;
153+
SelectedTabIndex = 1;
154+
}
155+
}
156+
135157
this.WhenAnyValue(x => x.SelectedTabIndex).Subscribe(x => tabs[x].Activate().Forget());
136158

137159
switch (SelectedTabIndex)

src/GitHub.Exports.Reactive/ViewModels/Dialog/Clone/IRepositoryCloneViewModel.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Reactive;
33
using GitHub.Models;
4+
using GitHub.Primitives;
45
using ReactiveUI;
56

67
namespace GitHub.ViewModels.Dialog.Clone
@@ -20,6 +21,11 @@ public interface IRepositoryCloneViewModel : IDialogContentViewModel, IConnectio
2021
/// </summary>
2122
IRepositorySelectViewModel EnterpriseTab { get; }
2223

24+
/// <summary>
25+
/// Initial URL for the dialog.
26+
/// </summary>
27+
UriString Url { get; set; }
28+
2329
/// <summary>
2430
/// Gets the path to clone the repository to.
2531
/// </summary>

test/GitHub.App.UnitTests/ViewModels/Dialog/Clone/RepositoryCloneViewModelTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,40 @@ public class RepositoryCloneViewModelTests
2323
const string fileExists = "d:\\exists\\file";
2424
const string defaultPath = "d:\\default\\path";
2525

26+
public class TheUrlProperty
27+
{
28+
[TestCase("https://github.com;https://enterprise.com", null, 0)]
29+
[TestCase("https://github.com;https://enterprise.com", "https://github.com/foo/bar", 0)]
30+
[TestCase("https://github.com;https://enterprise.com", "https://enterprise.com/foo/bar", 1)]
31+
[TestCase("https://github.com;https://enterprise.com", "https://unknown.com/foo/bar", 0)]
32+
public async Task Select_Tab_For_Url(string addresses, string url, int expectTabIndex)
33+
{
34+
var cm = CreateConnectionManager(addresses.Split(';'));
35+
var target = CreateTarget(connectionManager: cm);
36+
target.Url = url;
37+
38+
await target.InitializeAsync(null);
39+
40+
Assert.That(target.SelectedTabIndex, Is.EqualTo(expectTabIndex));
41+
}
42+
43+
[TestCase("https://github.com;https://enterprise.com", null, "", "")]
44+
[TestCase("https://github.com;https://enterprise.com", "https://github.com/foo/bar", "https://github.com/foo/bar", "")]
45+
[TestCase("https://github.com;https://enterprise.com", "https://enterprise.com/foo/bar", "", "https://enterprise.com/foo/bar")]
46+
[TestCase("https://github.com;https://enterprise.com", "https://unknown.com/foo/bar", "", "")]
47+
public async Task Set_Filter_For_Url(string addresses, string url, string expectGitHubFilter, string expectEnterpriseFilter)
48+
{
49+
var cm = CreateConnectionManager(addresses.Split(';'));
50+
var target = CreateTarget(connectionManager: cm);
51+
target.Url = url;
52+
53+
await target.InitializeAsync(null);
54+
55+
Assert.That(target.GitHubTab.Filter, Is.EqualTo(expectGitHubFilter));
56+
Assert.That(target.EnterpriseTab.Filter, Is.EqualTo(expectEnterpriseFilter));
57+
}
58+
}
59+
2660
[Test]
2761
public async Task GitHubPage_Is_Initialized()
2862
{

0 commit comments

Comments
 (0)