Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/GitHub.InlineReviews/GitHub.InlineReviews.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@
<Project>{6AFE2E2D-6DB0-4430-A2EA-F5F5388D2F78}</Project>
<Name>GitHub.Extensions</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.UI.Reactive\GitHub.UI.Reactive.csproj">
<Project>{158b05e8-fdbc-4d71-b871-c96e28d5adf5}</Project>
<Name>GitHub.UI.Reactive</Name>
</ProjectReference>
<ProjectReference Include="..\GitHub.UI\GitHub.UI.csproj">
<Project>{346384dd-2445-4a28-af22-b45f3957bd89}</Project>
<Name>GitHub.UI</Name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ class CommentThreadViewModelDesigner : ICommentThreadViewModel
= new AccountDesigner { Login = "shana", IsUser = true };

public ReactiveCommand<ICommentModel> PostComment { get; }

public Uri GetCommentUrl(int id)
{
throw new NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,34 @@
using GitHub.InlineReviews.ViewModels;
using GitHub.Models;
using GitHub.SampleData;
using GitHub.UI;
using ReactiveUI;

namespace GitHub.InlineReviews.SampleData
{
class CommentViewModelDesigner : ICommentViewModel
class CommentViewModelDesigner : ReactiveObject, ICommentViewModel
{
public CommentViewModelDesigner()
{
User = new AccountDesigner { Login = "shana", IsUser = true };
}

public void Initialize(ViewWithData data)
{
}

public int Id { get; set; }
public string Body { get; set; }
public string ErrorMessage { get; set; }
public CommentEditState EditState { get; set; }
public bool IsReadOnly { get; set; }
public ICommentThreadViewModel Thread { get; }
public DateTimeOffset UpdatedAt => DateTime.Now.Subtract(TimeSpan.FromDays(3));
public IAccount User { get; set; }

public ReactiveCommand<object> BeginEdit { get; }
public ReactiveCommand<object> CancelEdit { get; }
public ReactiveCommand<Unit> CommitEdit { get; }
public ReactiveCommand<object> OpenOnGitHub { get; }
}
}
3 changes: 3 additions & 0 deletions src/GitHub.InlineReviews/ViewModels/CommentThreadViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ public void Dispose()
GC.SuppressFinalize(this);
}

/// <inheritdoc/>
public abstract Uri GetCommentUrl(int id);

protected virtual void Dispose(bool disposing)
{
if (disposing)
Expand Down
11 changes: 11 additions & 0 deletions src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using GitHub.Extensions;
using GitHub.Models;
using GitHub.UI;
using ReactiveUI;

namespace GitHub.InlineReviews.ViewModels
Expand Down Expand Up @@ -73,6 +74,8 @@ public CommentViewModel(
CancelEdit = ReactiveCommand.Create(CommitEdit.IsExecuting.Select(x => !x));
CancelEdit.Subscribe(DoCancelEdit);
AddErrorHandler(CancelEdit);

OpenOnGitHub = ReactiveCommand.Create(this.WhenAnyValue(x => x.Id, x => x != 0));
}

/// <summary>
Expand All @@ -89,6 +92,11 @@ public CommentViewModel(
{
}

public void Initialize(ViewWithData data)
{
// Nothing to do here: initialized in constructor.
}

/// <summary>
/// Creates a placeholder comment which can be used to add a new comment to a thread.
/// </summary>
Expand Down Expand Up @@ -208,5 +216,8 @@ public DateTimeOffset UpdatedAt

/// <inheritdoc/>
public ReactiveCommand<Unit> CommitEdit { get; }

/// <inheritdoc/>
public ReactiveCommand<object> OpenOnGitHub { get; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace GitHub.InlineReviews.ViewModels
/// </summary>
public interface ICommentThreadViewModel
{
/// <summary>
/// Gets the browser URI for a comment in the thread.
/// </summary>
/// <param name="id">The ID of the comment.</param>
/// <returns>The URI.</returns>
Uri GetCommentUrl(int id);

/// <summary>
/// Gets the comments in the thread.
/// </summary>
Expand Down
13 changes: 12 additions & 1 deletion src/GitHub.InlineReviews/ViewModels/ICommentViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Reactive;
using GitHub.Models;
using GitHub.ViewModels;
using ReactiveUI;

namespace GitHub.InlineReviews.ViewModels
Expand All @@ -12,7 +13,7 @@ public enum CommentEditState
Placeholder,
}

public interface ICommentViewModel
public interface ICommentViewModel : IViewModel
{
/// <summary>
/// Gets the ID of the comment.
Expand Down Expand Up @@ -49,6 +50,11 @@ public interface ICommentViewModel
/// </summary>
IAccount User { get; }

/// <summary>
/// Gets the thread that the comment is a part of.
/// </summary>
ICommentThreadViewModel Thread { get; }

/// <summary>
/// Gets a command which will begin editing of the comment.
/// </summary>
Expand All @@ -63,5 +69,10 @@ public interface ICommentViewModel
/// Gets a command which will commit edits to the comment.
/// </summary>
ReactiveCommand<Unit> CommitEdit { get; }

/// <summary>
/// Gets a command to open the comment in a browser.
/// </summary>
ReactiveCommand<object> OpenOnGitHub { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reactive.Linq;
using System.Threading.Tasks;
using GitHub.Api;
Expand Down Expand Up @@ -34,6 +35,7 @@ public InlineCommentThreadViewModel(

this.apiClient = apiClient;
Session = session;

PostComment = ReactiveCommand.CreateAsyncTask(
Observable.Return(true),
DoPostComment);
Expand All @@ -51,6 +53,17 @@ public InlineCommentThreadViewModel(
/// </summary>
public IPullRequestSession Session { get; }

/// <inheritdoc/>
public override Uri GetCommentUrl(int id)
{
return new Uri(string.Format(
CultureInfo.InvariantCulture,
"{0}/pull/{1}#discussion_r{2}",
Session.Repository.CloneUrl.ToRepositoryUrl(),
Session.PullRequest.Number,
id));
}

async Task<ICommentModel> DoPostComment(object parameter)
{
Guard.ArgumentNotNull(parameter, nameof(parameter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public IssueCommentThreadViewModel(
Number = number;
}

/// <inheritdoc/>
public override Uri GetCommentUrl(int id)
{
throw new NotImplementedException();
}

public IRepositoryModel Repository { get; }
public int Number { get; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public bool NeedsPush
private set { this.RaiseAndSetIfChanged(ref needsPush, value); }
}

/// <inheritdoc/>
public override Uri GetCommentUrl(int id)
{
throw new NotSupportedException("Cannot navigate to a non-posted comment.");
}

async Task<ICommentModel> DoPostComment(object parameter)
{
Guard.ArgumentNotNull(parameter, nameof(parameter));
Expand Down
16 changes: 10 additions & 6 deletions src/GitHub.InlineReviews/Views/CommentView.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl x:Class="GitHub.InlineReviews.Views.CommentView"
<views:GenericCommentView x:Class="GitHub.InlineReviews.Views.CommentView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Expand All @@ -8,16 +8,17 @@
xmlns:prop="clr-namespace:GitHub.VisualStudio.UI;assembly=GitHub.VisualStudio.UI"
xmlns:ui="clr-namespace:GitHub.UI;assembly=GitHub.UI"
xmlns:sample="clr-namespace:GitHub.InlineReviews.SampleData"
xmlns:views="clr-namespace:GitHub.InlineReviews.Views"
mc:Ignorable="d" d:DesignWidth="300">
<d:DesignProperties.DataContext>
<sample:CommentViewModelDesigner EditState="Editing">
<sample:CommentViewModelDesigner EditState="None">
<sample:CommentViewModelDesigner.Body>
You can use a `CompositeDisposable` type here, it's designed to handle disposables in an optimal way (you can just call `Dispose()` on it and it will handle disposing everything it holds).
</sample:CommentViewModelDesigner.Body>
</sample:CommentViewModelDesigner>
</d:DesignProperties.DataContext>

<UserControl.Resources>
<FrameworkElement.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<cache:SharedDictionaryManager Source="pack://application:,,,/GitHub.UI;component/SharedDictionary.xaml" />
Expand All @@ -42,7 +43,7 @@
</Style.Resources>
</Style>
</ResourceDictionary>
</UserControl.Resources>
</FrameworkElement.Resources>

<Grid>
<!-- Displays an existing comment-->
Expand Down Expand Up @@ -77,7 +78,10 @@
<Border Background="#FFF6F8FA" Padding="6 5" BorderThickness="1 1 1 0" BorderBrush="#FFD1D5DA" CornerRadius="2 2 0 0">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="2 0" FontWeight="Bold" Text="{Binding User.Login}"/>
<TextBlock Margin="2 0" Opacity="0.75" Text="{Binding UpdatedAt, Converter={ui:DurationToStringConverter}}"/>
<ui:GitHubActionLink Content="{Binding UpdatedAt, Converter={ui:DurationToStringConverter}}"
Command="{Binding OpenOnGitHub}"
Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type TextBlock}, AncestorLevel=1}, Path=Foreground}"
Margin="2 0"/>
</StackPanel>
</Border>

Expand Down Expand Up @@ -186,4 +190,4 @@
</StackPanel>
</Grid>
</Grid>
</UserControl>
</views:GenericCommentView>
19 changes: 18 additions & 1 deletion src/GitHub.InlineReviews/Views/CommentView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,32 @@
using System.Windows.Controls;
using System.Windows.Threading;
using GitHub.InlineReviews.ViewModels;
using GitHub.Services;
using Microsoft.VisualStudio.Shell;
using ReactiveUI;

namespace GitHub.InlineReviews.Views
{
public partial class CommentView : UserControl
public class GenericCommentView : GitHub.UI.ViewBase<ICommentViewModel, GenericCommentView> { }

public partial class CommentView : GenericCommentView
{
public CommentView()
{
InitializeComponent();
this.Loaded += CommentView_Loaded;

this.WhenActivated(d =>
{
d(ViewModel.OpenOnGitHub.Subscribe(_ => DoOpenOnGitHub()));
});
}

void DoOpenOnGitHub()
{
var serviceProvider = (IGitHubServiceProvider)Package.GetGlobalService(typeof(IGitHubServiceProvider));
var browser = serviceProvider.GetService<IVisualStudioBrowser>();
browser.OpenUrl(ViewModel.Thread.GetCommentUrl(ViewModel.Id));
}

private void CommentView_Loaded(object sender, System.Windows.RoutedEventArgs e)
Expand Down