Skip to content

Conversation

@mcnallyella
Copy link
Contributor

@mcnallyella mcnallyella commented Jul 1, 2022

Bug

Fixes: NuGet/Home#11362

Regression? Last working version:

Description

There is currently no support for package source mapping in the VS options UI. These changes allow the user to see all package source mappings in a new Package Source Mapping options dialog, and to Add, Remove, or Clear mappings. Here is a screenshot of this dialog showing the mappings for NuGet.sln:
image

When a user clicks Add, a new window appears, and the user can type in a package namespace and select from all the previously configured sources for that project to map to. Here is a screenshot showing this window:
image

There were some concerns about the modal dialog and the amount of whitespace in the ListView showing package source mappings, but the UX Board checked it and said it was okay.

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added - There are 4 tests for changes to the API. Most of this feature is UI, however, so I have not written tests. This feature currently passes all checks for Accessibility Insights but one. The one accessibility issue is that the ListView showing the package source mappings in the Package Source Mappings options dialog shows the wrong value for the IsOffScreen property for mappings not in view. This issue appears in other VS options dialogs that have a ListView and is mentioned in this issue: Inconsistent UIA IsOffscreen and ClickablePoint properties for WPF ListViewItems that are scrolled out of view dotnet/wpf#4631 , so I decided not to fix it.

AccessibilityInsights

- **OR** - [ ] Test exception - **OR** - [ ] N/A

@mcnallyella mcnallyella marked this pull request as ready for review July 12, 2022 17:42
@mcnallyella mcnallyella requested a review from a team as a code owner July 12, 2022 17:42
@mcnallyella mcnallyella force-pushed the dev-mcnallyella-packageSourceMappingOptions branch from 829a07d to 849bb52 Compare July 12, 2022 19:09
Copy link
Contributor

@donnie-msft donnie-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Things are really coming along nicely! 🥳
Few considerations, nitpicks, and suggestions...

}

//converts from list of packagesourcemappingsourceItems to a dictonary that can be read by UI
private ItemsChangeObservableCollection<PackageItem> ReadMappingsFromConfigToUI(IReadOnlyList<PackageSourceMappingSourceItem> originalMappings)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this method be reduced? As another reviewer mentioned, I think more ideal would be using a more generic type than ObservableCollection, then interacting with the single SourceMappingsCollection directly.

/// Source name to package patterns list.
/// </summary>
internal IReadOnlyDictionary<string, IReadOnlyList<string>> Patterns { get; }
public IReadOnlyDictionary<string, IReadOnlyList<string>> Patterns { get; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is not in draft mode, but this change (and others in src/NuGet.Core) are from this PR: #4709

Please focus one completing dependent PRs before marking new PRs that need the same change as "ready for review", to minimize workload on the rest of the team.

using Microsoft.VisualStudio.Shell;


namespace NuGet.Options
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This namespace doesn't feel right to me. Usually project default namespaces are the project name + folder within the project, so shouldn't the namespace be NuGet.PackageManagement.UI.Options?

Same question for the other new files in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided not to change the namespace since the two existing options pages are in the NuGet.Options namespace.

@mcnallyella mcnallyella force-pushed the dev-mcnallyella-packageSourceMappingOptions branch from 2722c90 to a907efa Compare July 14, 2022 21:44
Copy link
Contributor

@dominoFire dominoFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job. Some comments.

@@ -0,0 +1,89 @@
<Window x:Class="NuGet.Options.AddMappingDialog"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like, using our VsDialogWindow class?

Suggested change
<Window x:Class="NuGet.Options.AddMappingDialog"
<nuget:VsDialogWindow x:Class="NuGet.Options.AddMappingDialog"

@mcnallyella mcnallyella force-pushed the dev-mcnallyella-packageSourceMappingOptions branch 2 times, most recently from 1ad6fea to a9ee7dc Compare July 25, 2022 19:08
IReadOnlyList<PackageSourceMappingSourceItem> packageSourceMappingsSourceItems = ReadMappingsFromUIToConfig(SourceMappingsCollection);
try
{
if (SourceMappingsChanged(_originalPackageSourceMappings, packageSourceMappingsSourceItems))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to call this method to find out if Source Mapping changed?
Doesn't packageSourceMappingProvider.SavePackageSourceMappings method only save if there is change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No SavePackageSourceMappings will go through all of the mappings and call AddOrUpdate even if nothing is changed (it won't modify the config file, though). It seems like it makes more sense to check if Save even needs to be called in the first place

@erdembayar
Copy link
Contributor

Is edit button considered at this point? Currently remove button simply remove the patterns with all the sources.

@donnie-msft donnie-msft dismissed their stale review August 1, 2022 21:38

Many commits since review

@mcnallyella mcnallyella force-pushed the dev-mcnallyella-packageSourceMappingOptions branch 2 times, most recently from 05d592e to e91e3db Compare August 1, 2022 23:35
Copy link
Contributor

@erdembayar erdembayar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another feedbacks, I believe your PR is very close. 🚀

{
public class MappingUIDisplay
{
public string ID { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it just package Id or packagePattern? Maybe I rename to PackageId or PackagePattern, it's quite hard to remember it was packageId to begin.

mappingsDictonary[source.Name] = new List<PackagePatternItem>();
}
PackagePatternItem tempID = new PackagePatternItem(mappingUIDisplay.ID);
bool newID = true;
Copy link
Contributor

@erdembayar erdembayar Aug 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe line 224-236 can be replaced with below, which is more readable.

                  PackagePatternItem tempID = new PackagePatternItem(mappingUIDisplay.ID);

                   if (!mappingsDictonary[source.Name].Any(id => id.Pattern == tempID.Pattern))
                   {
                       mappingsDictonary[source.Name].Add(tempID);
                   }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do. thanks

@kartheekp-ms
Copy link
Contributor

Team Triage: Work with @dominoFire regarding the localization of strings.

Copy link
Contributor

@dominoFire dominoFire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please address button overflow. Keep up the good work!

<Reference Include="System.Drawing" />
<Reference Include="System.Runtime.Caching" />
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.ServiceProcess" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this namespace? I don't see any namespace reference to System.ServiceProcess


namespace NuGet.Options
{
internal class ButtonCommand : ICommand
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be wrong but, I believe you can remove this class and achieve the same result using CommandBinding directly in XAML control.

Buttons in both dialogs (option dialog and add source mapping dialog) can map to method actions using XAML CommandBinding construc.

An example can be found in PackageManagerControl for search command:

<CommandBinding
Command="{x:Static nuget:Commands.RestartSearchCommand}"
Executed="ExecuteRestartSearchCommand"/>

Ping me if you have more questions.

@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Aug 23, 2022
@ghost
Copy link

ghost commented Aug 23, 2022

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

1 similar comment
@ghost
Copy link

ghost commented Aug 30, 2022

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Aug 30, 2022
@donnie-msft
Copy link
Contributor

Like, using our VsDialogWindow class?

#4711 (comment)

@dominoFire - I decided to delete that class :) #4778

@donnie-msft donnie-msft force-pushed the dev-mcnallyella-packageSourceMappingOptions branch from 6ab4bae to 21f7a87 Compare August 31, 2022 04:03
@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Sep 7, 2022
@ghost
Copy link

ghost commented Sep 7, 2022

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@donnie-msft donnie-msft force-pushed the dev-mcnallyella-packageSourceMappingOptions branch from 21f7a87 to 95f3603 Compare September 8, 2022 04:47
@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Sep 8, 2022
@ghost ghost added the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Sep 15, 2022
@ghost
Copy link

ghost commented Sep 15, 2022

This PR has been automatically marked as stale because it has no activity for 7 days. It will be closed if no further activity occurs within another 7 days of this comment. If it is closed, you may reopen it anytime when you're ready again, as long as you don't delete the branch.

@ghost ghost closed this Sep 22, 2022
@ghost ghost removed the Status:No recent activity PRs that have not had any recent activity and will be closed if the label is not removed label Sep 29, 2022
@donnie-msft
Copy link
Contributor

Decided to Sort the mappings by Package ID in the options page, since otherwise it's just a random order of how the IDs are read from the config. ff324ec
image

Note that when adding new mappings, they appear initially at the bottom until "OK" is pressed. I think this is standard/expected behavior.

@donnie-msft donnie-msft removed their assignment Oct 5, 2022
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package Source Mapping UI - List Package Source Mappings in the NuGet Options UI

8 participants