8000 Unify the repository list and URL tabs in the clone dialog by jcansdale · Pull Request #2197 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

Unify the repository list and URL tabs in the clone dialog #2197

Merged
merged 16 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10000
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Reactive;
using System.Threading.Tasks;
using GitHub.Models;
using GitHub.Primitives;
using GitHub.ViewModels;
using GitHub.ViewModels.Dialog.Clone;
using ReactiveUI;
Expand All @@ -17,13 +18,13 @@ public RepositoryCloneViewModelDesigner()
}

public string Path { get; set; }
public UriString Url { get; set; }
public string PathWarning { get; set; }
public int SelectedTabIndex { get; set; }
public string Title => null;
public IObservable<object> Done => null;
public IRepositorySelectViewModel GitHubTab { get; }
public IRepositorySelectViewModel EnterpriseTab { get; }
public IRepositoryUrlViewModel UrlTab { get; }
public ReactiveCommand<Unit, Unit> Browse { get; }
public ReactiveCommand<Unit, CloneDialogResult> Clone { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/GitHub.App/Services/DialogService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public async Task<CloneDialogResult> ShowCloneDialog(IConnection connection, str
var viewModel = factory.CreateViewModel<IRepositoryCloneViewModel>();
if (url != null)
{
viewModel.UrlTab.Url = url;
viewModel.Url = url;
}

if (connection != null)
Expand Down
48 changes: 22 additions & 26 deletions src/GitHub.App/ViewModels/Dialog/Clone/RepositoryCloneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using GitHub.Extensions;
using GitHub.Logging;
using GitHub.Models;
using GitHub.Primitives;
using GitHub.Services;
using ReactiveUI;
using Rothko;
Expand All @@ -20,15 +21,14 @@ namespace GitHub.ViewModels.Dialog.Clone
[PartCreationPolicy(CreationPolicy.NonShared)]
public class RepositoryCloneViewModel : ViewModelBase, IRepositoryCloneViewModel
{
static readonly ILogger log = LogManager.ForContext<RepositoryCloneViewModel>();
readonly IOperatingSystem os;
readonly IConnectionManager connectionManager;
readonly IRepositoryCloneService service;
readonly IGitService gitService;
readonly IUsageService usageService;
readonly IUsageTracker usageTracker;
readonly IReadOnlyList<IRepositoryCloneTabViewModel> tabs;
string path;
UriString url;
RepositoryModel previousRepository;
ObservableAsPropertyHelper<string> pathWarning;
int selectedTabIndex;
Expand All @@ -39,23 +39,19 @@ public RepositoryCloneViewModel(
IConnectionManager connectionManager,
IRepositoryCloneService service,
IGitService gitService,
IUsageService usageService,
IUsageTracker usageTracker,
IRepositorySelectViewModel gitHubTab,
IRepositorySelectViewModel enterpriseTab,
IRepositoryUrlViewModel urlTab)
IRepositorySelectViewModel enterpriseTab)
{
this.os = os;
this.connectionManager = connectionManager;
this.service = service;
this.gitService = gitService;
this.usageService = usageService;
this.usageTracker = usageTracker;

GitHubTab = gitHubTab;
EnterpriseTab = enterpriseTab;
UrlTab = urlTab;
tabs = new IRepositoryCloneTabViewModel[] { GitHubTab, EnterpriseTab, UrlTab };
tabs = new IRepositoryCloneTabViewModel[] { GitHubTab, EnterpriseTab };

var repository = this.WhenAnyValue(x => x.SelectedTabIndex)
.SelectMany(x => tabs[x].WhenAnyValue(tab => tab.Repository));
Expand Down Expand Up @@ -88,14 +84,19 @@ public RepositoryCloneViewModel(

public IRepositorySelectViewModel GitHubTab { get; }
public IRepositorySelectViewModel EnterpriseTab { get; }
public IRepositoryUrlViewModel UrlTab { get; }

public string Path
{
get => path;
set => this.RaiseAndSetIfChanged(ref path, value);
}

public UriString Url
{
get => url;
set => this.RaiseAndSetIfChanged(ref url, value);
}

public string PathWarning => pathWarning.Value;

public int SelectedTabIndex
Expand Down Expand Up @@ -135,26 +136,21 @@ public async Task InitializeAsync(IConnection connection)
SelectedTabIndex = 1;
}

this.WhenAnyValue(x => x.SelectedTabIndex).Subscribe(x => tabs[x].Activate().Forget());

// When a clipboard URL has been set, show the URL tab by default
if (!string.IsNullOrEmpty(UrlTab.Url))
if (Url?.Host is string host && HostAddress.Create(host) is HostAddress hostAddress)
{
SelectedTabIndex = 2;
if (hostAddress == gitHubConnection?.HostAddress)
{
GitHubTab.Filter = Url;
SelectedTabIndex = 0;
}
else if (hostAddress == enterpriseConnection?.HostAddress)
{
EnterpriseTab.Filter = Url;
SelectedTabIndex = 1;
}
}

switch (SelectedTabIndex)
{
case 0:
usageTracker.IncrementCounter(model => model.NumberOfCloneViewGitHubTab).Forget();
break;
case 1:
usageTracker.IncrementCounter(model => model.NumberOfCloneViewEnterpriseTab).Forget();
break;
case 2:
usageTracker.IncrementCounter(model => model.NumberOfCloneViewUrlTab).Forget();
break;
}
this.WhenAnyValue(x => x.SelectedTabIndex).Subscribe(x => tabs[x].Activate().Forget());
}

void BrowseForDirectory()
Expand Down
B41A
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reactive.Linq;
using System.Threading.Tasks;
using System.Windows.Data;
using GitHub.Exports;
using GitHub.Extensions;
using GitHub.Logging;
using GitHub.Models;
Expand All @@ -23,6 +24,7 @@ public class RepositorySelectViewModel : ViewModelBase, IRepositorySelectViewMod
{
static readonly ILogger log = LogManager.ForContext<RepositorySelectViewModel>();
readonly IRepositoryCloneService service;
readonly IGitHubContextService gitHubContextService;
IConnection connection;
Exception error;
string filter;
Expand All @@ -35,15 +37,26 @@ public class RepositorySelectViewModel : ViewModelBase, IRepositorySelectViewMod
IRepositoryItemViewModel selectedItem;

[ImportingConstructor]
public RepositorySelectViewModel(IRepositoryCloneService service)
public RepositorySelectViewModel(IRepositoryCloneService service, IGitHubContextService gitHubContextService)
{
Guard.ArgumentNotNull(service, nameof(service));
Guard.ArgumentNotNull(service, nameof(gitHubContextService));

this.service = service;
this.gitHubContextService = gitHubContextService;

repository = this.WhenAnyValue(x => x.SelectedItem)
.Select(CreateRepository)
var selectedRepository = this.WhenAnyValue(x => x.SelectedItem)
.Select(CreateRepository);

var filterRepository = this.WhenAnyValue(x => x.Filter)
.Select(f => gitHubContextService.FindContextFromUrl(f))
.Where(c => c?.LinkType == LinkType.Repository)
.Select(c => new RepositoryModel(c.RepositoryName, c.Url));

repository = selectedRepository
.Merge(filterRepository)
.ToProperty(this, x => x.Repository);

this.WhenAnyValue(x => x.Filter).Subscribe(_ => ItemsView?.Refresh());
}

Expand Down Expand Up @@ -166,7 +179,9 @@ bool FilterItem(object obj)
{
if (obj is IRepositoryItemViewModel item && !string.IsNullOrWhiteSpace(Filter))
{
return item.Caption.Contains(Filter, StringComparison.CurrentCultureIgnoreCase);
return
item.Caption.Contains(Filter, StringComparison.CurrentCultureIgnoreCase) ||
item.Url.ToString().Contains(Filter, StringComparison.OrdinalIgnoreCase);
}

return true;
Expand Down
65 changes: 0 additions & 65 deletions src/GitHub.App/ViewModels/Dialog/Clone/RepositoryUrlViewModel.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reactive;
using GitHub.Models;
using GitHub.Primitives;
using ReactiveUI;

namespace GitHub.ViewModels.Dialog.Clone
Expand All @@ -21,9 +22,9 @@ public interface IRepositoryCloneViewModel : IDialogContentViewModel, IConnectio
IRepositorySelectViewModel EnterpriseTab { get; }

/// <summary>
/// Gets the view model for the URL tab.
/// Initial URL for the dialog.
/// </summary>
IRepositoryUrlViewModel UrlTab { get; }
UriString Url { get; set; }

/// <summary>
/// Gets the path to clone the repository to.
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions src/GitHub.Exports/Models/UsageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,6 @@ public class MeasuresModel
public int ExecuteToggleInlineCommentMarginCommand { get; set; }
public int NumberOfPullRequestFileMarginToggleInlineCommentMargin { get; set; }
public int NumberOfPullRequestFileMarginViewChanges { get; set; }
public int NumberOfCloneViewGitHubTab { get; set; }
public int NumberOfCloneViewEnterpriseTab { get; set; }
public int NumberOfCloneViewUrlTab { get; set; }
public int NumberOfGitHubClones { get; set; }
public int NumberOfEnterpriseClones { get; set; }
public int NumberOfGitHubOpens { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<d:DesignData.DataContext>
<ghfvs:RepositoryCloneViewModelDesigner/>
</d:DesignData.DataContext>

<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
Expand Down Expand Up @@ -70,21 +70,6 @@
Visibility="{Binding EnterpriseTab.IsEnabled, Converter={ghfvs:BooleanToVisibilityConverter}}">
<local:SelectPageView DataContext="{Binding EnterpriseTab}"/>
</TabItem>
<TabItem Header="URL" Style="{DynamicResource LightModalViewTabItem}">
<DockPanel DataContext="{Binding UrlTab}"
LastChildFill="False"
Margin="8">
<TextBlock DockPanel.Dock="Top">
Repository URL or GitHub username and repository
<LineBreak/>
(<Run Background="#66d3d3d3" FontFamily="Consolas">hubot/cool-repo</Run>)
</TextBlock>
<ghfvs:PromptTextBox DockPanel.Dock="Top"
Margin="0 4"
PromptText="URL or username/repository"
Text="{Binding Url, UpdateSourceTrigger=PropertyChanged}"/>
</DockPanel>
</TabItem>
</TabControl>
</DockPanel>
</UserControl>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<DockPanel>
<ghfvs:PromptTextBox DockPanel.Dock="Top"
Margin="0,4"
PromptText="Filter"
PromptText="Search or enter a URL"
Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged, Delay=300}"/>

<Grid>
Expand Down
Loading
0