-
Notifications
You must be signed in to change notification settings - Fork 694
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated PM UI to render the README inside of a tab in the README Deta…
…ils pane. (#6094) * Add ReadmeFileUrl field to IPackageSearchMetadata (#6014) Adds the ReadmeFileUrl field to IPackageSearchMetadata and implements the ability to get the URL for local packages. Future PRs will include implementations for getting the URL for remote READMEs and downloading them. --------- Co-authored-by: Andy Zivkovic <zivkan@users.noreply.github.com> * Added new user controls, updated details * Adjust readme viewmodel name * update views * Ensured ReadmefileUrl is set when merging sources * Fix delegation, update ux to render properly * Limit local readme rendering to excluse browse tab * ensure no readme found message for local packages. Added tests * update property count * lock url * fix rebase weirdness. * PR comments * Simplify * Move model to viewmodel * Renamed controls so they're less confusing * Switched to templates for tabs * fix typo * Update src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/PackageFeeds/MultiSourcePackageMetadataProvider.cs Co-authored-by: Donnie Goodson <49205731+donnie-msft@users.noreply.github.com> * PR comment * rename * rename tests * change spacing to make pr easier to see * more spacing * Update src/NuGet.Clients/NuGet.PackageManagement.UI/ViewModels/PackageDetailsTabViewModel.cs Co-authored-by: Donnie Goodson <49205731+donnie-msft@users.noreply.github.com> * Revert "Update src/NuGet.Clients/NuGet.PackageManagement.UI/ViewModels/PackageDetailsTabViewModel.cs" This reverts commit add1b00. * IsVisible rename * add is visible * extra line * rename tsts * Reduce tab dependencies * pr comments * Adjust how selected tab is set * rename loaded/unloaded * avoid setting visibility, make tabs more generic * create conversion for vm to enum * pr comments * Update src/NuGet.Clients/NuGet.PackageManagement.UI/ViewModels/PackageDetailsTabViewModel.cs Co-authored-by: Jean-Pierre Briedé <jebriede@microsoft.com> --------- Co-authored-by: Andy Zivkovic <zivkan@users.noreply.github.com> Co-authored-by: Donnie Goodson <49205731+donnie-msft@users.noreply.github.com> Co-authored-by: Jean-Pierre Briedé <jebriede@microsoft.com>
- Loading branch information
1 parent
575b1e8
commit 2c9fde3
Showing
28 changed files
with
1,242 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1 @@ | ||
#nullable enable | ||
~const NuGet.Protocol.JsonProperties.ReadmeFileUrl = "readmeFileUrl" -> string | ||
~NuGet.Protocol.Core.Types.IPackageSearchMetadata.ReadmeFileUrl.get -> string | ||
~NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.ReadmeFileUrl.get -> string | ||
~NuGet.Protocol.Core.Types.PackageSearchMetadataBuilder.ClonedPackageSearchMetadata.ReadmeFileUrl.set -> void | ||
~NuGet.Protocol.LocalPackageSearchMetadata.ReadmeFileUrl.get -> string | ||
~NuGet.Protocol.PackageSearchMetadata.ReadmeFileUrl.get -> string | ||
~NuGet.Protocol.PackageSearchMetadataV2Feed.ReadmeFileUrl.get -> string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/NuGet.Clients/NuGet.PackageManagement.UI/Models/PackageMetadataTab.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace NuGet.PackageManagement.UI | ||
{ | ||
public enum PackageMetadataTab | ||
{ | ||
Readme, | ||
PackageDetails, | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/NuGet.Clients/NuGet.PackageManagement.UI/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
src/NuGet.Clients/NuGet.PackageManagement.UI/ViewModels/PackageDetailsTabViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
using System; | ||
using System.Collections.ObjectModel; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.VisualStudio.Shell; | ||
using NuGet.VisualStudio; | ||
using NuGet.VisualStudio.Internal.Contracts; | ||
|
||
namespace NuGet.PackageManagement.UI.ViewModels | ||
{ | ||
public class PackageDetailsTabViewModel : ViewModelBase, IDisposable | ||
{ | ||
private bool _disposed = false; | ||
private bool _readmeTabEnabled; | ||
|
||
public ReadmePreviewViewModel ReadmePreviewViewModel { get; private set; } | ||
|
||
public DetailControlModel DetailControlModel { get; private set; } | ||
|
||
public ObservableCollection<TitledPageViewModelBase> Tabs { get; private set; } | ||
|
||
private TitledPageViewModelBase _selectedTab; | ||
public TitledPageViewModelBase SelectedTab | ||
{ | ||
get => _selectedTab; | ||
set | ||
{ | ||
SetAndRaisePropertyChanged(ref _selectedTab, value); | ||
} | ||
} | ||
|
||
public PackageDetailsTabViewModel() | ||
{ | ||
_readmeTabEnabled = true; | ||
Tabs = new ObservableCollection<TitledPageViewModelBase>(); | ||
} | ||
|
||
public async Task InitializeAsync(DetailControlModel detailControlModel, INuGetPackageFileService nugetPackageFileService, ItemFilter currentFilter, PackageMetadataTab initialSelectedTab) | ||
{ | ||
var nuGetFeatureFlagService = await ServiceLocator.GetComponentModelServiceAsync<INuGetFeatureFlagService>(); | ||
_readmeTabEnabled = await nuGetFeatureFlagService.IsFeatureEnabledAsync(NuGetFeatureFlagConstants.RenderReadmeInPMUI); | ||
|
||
ReadmePreviewViewModel = new ReadmePreviewViewModel(nugetPackageFileService, currentFilter, _readmeTabEnabled); | ||
DetailControlModel = detailControlModel; | ||
|
||
Tabs.Add(ReadmePreviewViewModel); | ||
Tabs.Add(DetailControlModel); | ||
|
||
SelectedTab = Tabs.FirstOrDefault(t => t.IsVisible && ConvertFromTabType(t) == initialSelectedTab) ?? Tabs.FirstOrDefault(t => t.IsVisible); | ||
|
||
DetailControlModel.PropertyChanged += DetailControlModel_PropertyChanged; | ||
|
||
foreach (var tab in Tabs) | ||
{ | ||
tab.PropertyChanged += IsVisible_PropertyChanged; | ||
} | ||
} | ||
|
||
public static PackageMetadataTab ConvertFromTabType(TitledPageViewModelBase vm) | ||
{ | ||
if (vm is DetailControlModel) | ||
{ | ||
return PackageMetadataTab.PackageDetails; | ||
} | ||
return PackageMetadataTab.Readme; | ||
} | ||
|
||
public async Task SetCurrentFilterAsync(ItemFilter filter) | ||
{ | ||
if (_readmeTabEnabled) | ||
{ | ||
await ReadmePreviewViewModel.SetCurrentFilterAsync(filter); | ||
} | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
if (_disposed) | ||
{ | ||
return; | ||
} | ||
_disposed = true; | ||
DetailControlModel.PropertyChanged -= DetailControlModel_PropertyChanged; | ||
|
||
foreach (var tab in Tabs) | ||
{ | ||
tab.PropertyChanged -= IsVisible_PropertyChanged; | ||
} | ||
} | ||
|
||
private void IsVisible_PropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName == nameof(TitledPageViewModelBase.IsVisible)) | ||
{ | ||
if (SelectedTab == null || (SelectedTab == sender && !SelectedTab.IsVisible)) | ||
{ | ||
SelectedTab = Tabs.FirstOrDefault(t => t.IsVisible); | ||
} | ||
} | ||
} | ||
|
||
private void DetailControlModel_PropertyChanged(object sender, PropertyChangedEventArgs e) | ||
{ | ||
ThreadHelper.JoinableTaskFactory.Run(async () => | ||
{ | ||
if (_readmeTabEnabled) | ||
{ | ||
await ReadmePreviewViewModel.SetPackageMetadataAsync(DetailControlModel.PackageMetadata, CancellationToken.None); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.