-
Notifications
You must be signed in to change notification settings - Fork 668
DYN-9357: Installed packages list on Package Manager shows the latest version of the package #16853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ivaylo-matov
wants to merge
7
commits into
DynamoDS:master
Choose a base branch
from
ivaylo-matov:DYN-9357-Install-button-260123
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+559
−61
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
fc8879f
draft
ivaylo-matov c6c6f75
Update PackageManagerSearchElementViewModel.cs
ivaylo-matov ac068d9
moved uninstall command to vm
ivaylo-matov ec4372a
removed redundant SearchElementViewModelOnPropertyChanged
ivaylo-matov ba76aca
rationalization
ivaylo-matov fb63466
searchElementViewModelOnPropertyChanged brought back
ivaylo-matov d410ac2
copilot comments addressed
ivaylo-matov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| using System.Windows.Data; | ||
| using System.Windows.Input; | ||
| using Dynamo.ViewModels; | ||
| using Dynamo.Wpf.Properties; | ||
| using Dynamo.Wpf.ViewModels; | ||
| using Greg.Responses; | ||
| using Prism.Commands; | ||
|
|
@@ -20,6 +21,10 @@ public class PackageManagerSearchElementViewModel : BrowserItemViewModel, IEquat | |
| public ICommand VisitSiteCommand { get; set; } | ||
| public ICommand VisitRepositoryCommand { get; set; } | ||
| public ICommand DownloadLatestToCustomPathCommand { get; set; } | ||
| public ICommand InstallActionCommand | ||
| { | ||
| get { return IsInstalledVersionSelected ? uninstallCommand : DownloadLatestCommand; } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// VM IsDeprecated property | ||
|
|
@@ -69,6 +74,24 @@ public class PackageManagerSearchElementViewModel : BrowserItemViewModel, IEquat | |
| /// The currently selected version of a package | ||
| /// </summary> | ||
| private VersionInformation selectedVersion; | ||
| private string installedVersion; | ||
| private bool hasUpdateAvailable; | ||
| private readonly DelegateCommand uninstallCommand; | ||
| private Func<bool> canUninstall; | ||
| private bool HasInstalledVersion => !string.IsNullOrEmpty(installedVersion); | ||
|
|
||
| /// <summary> | ||
| /// True when the selected version is installed. | ||
| /// </summary> | ||
| public bool IsInstalledVersionSelected => SelectedVersion?.IsInstalled == true; | ||
| /// <summary> | ||
| /// True when the selected installed version cannot be uninstalled. | ||
| /// </summary> | ||
| public bool IsInstalledFallback => IsInstalledVersionSelected && canUninstall == null; | ||
| /// <summary> | ||
| /// True when the selected installed version can be uninstalled. | ||
| /// </summary> | ||
| public bool IsUninstallState => IsInstalledVersionSelected && canUninstall != null; | ||
|
|
||
| public bool? IsSelectedVersionCompatible | ||
| { | ||
|
|
@@ -96,8 +119,71 @@ public VersionInformation SelectedVersion | |
| selectedVersion = value; | ||
|
|
||
| // Update the compatibility info so the icon of the currently selected version is updated | ||
| IsSelectedVersionCompatible = selectedVersion.IsCompatible; | ||
| IsSelectedVersionCompatible = selectedVersion?.IsCompatible; | ||
| SearchElementModel.SelectedVersion = selectedVersion; | ||
| RaisePropertyChanged(nameof(SelectedVersion)); | ||
| RaisePropertyChanged(nameof(InstallActionText)); | ||
| RaisePropertyChanged(nameof(InstallActionCommand)); | ||
| RaisePropertyChanged(nameof(IsInstalledVersionSelected)); | ||
| RaisePropertyChanged(nameof(IsInstalledFallback)); | ||
| RaisePropertyChanged(nameof(IsUninstallState)); | ||
| RefreshUninstallCommandCanExecute(); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// The text to display for the install action button, which changes based on the package's installation state. | ||
| /// </summary> | ||
| public string InstallActionText | ||
| { | ||
| get | ||
| { | ||
| if (HasInstalledVersion) | ||
| { | ||
| if (IsInstalledVersionSelected) | ||
| { | ||
| return IsInstalledFallback | ||
| ? Resources.PackageDownloadStateInstalled | ||
| : Resources.PackageManagerUninstall; | ||
| } | ||
|
|
||
| return Resources.PackageManagerUpdate; | ||
| } | ||
|
|
||
| return Resources.PackageManagerInstall; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// True if newer version is available for an installed package | ||
| /// </summary> | ||
| public bool HasUpdateAvailable | ||
| { | ||
| get { return hasUpdateAvailable; } | ||
| set | ||
| { | ||
| if (hasUpdateAvailable != value) | ||
| { | ||
| hasUpdateAvailable = value; | ||
| RaisePropertyChanged(nameof(HasUpdateAvailable)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| internal ICommand UninstallCommand => uninstallCommand; | ||
| internal Func<bool> CanUninstall | ||
| { | ||
| get { return canUninstall; } | ||
| set | ||
| { | ||
| if (canUninstall != value) | ||
| { | ||
| canUninstall = value; | ||
| RaisePropertyChanged(nameof(InstallActionText)); | ||
| RaisePropertyChanged(nameof(IsInstalledFallback)); | ||
| RaisePropertyChanged(nameof(IsUninstallState)); | ||
| RefreshUninstallCommandCanExecute(); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -116,6 +202,7 @@ public PackageManagerSearchElementViewModel(PackageManagerSearchElement element, | |
| this.SearchElementModel = element; | ||
| CanInstall = install; | ||
| IsEnabledForInstall = isEnabledForInstall; | ||
| uninstallCommand = new DelegateCommand(OnRequestUninstall, () => CanUninstall?.Invoke() == true); | ||
|
|
||
| // Attempts to show the latest compatible version. If no compatible, will return the latest instead. | ||
| this.SelectedVersion = this.SearchElementModel.LatestCompatibleVersion; | ||
|
|
@@ -128,7 +215,7 @@ public PackageManagerSearchElementViewModel(PackageManagerSearchElement element, | |
|
|
||
| this.DownloadLatestCommand = new DelegateCommand( | ||
| () => OnRequestDownload(false), | ||
| () => !SearchElementModel.IsDeprecated && CanInstall); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are we removing |
||
| () => !SearchElementModel.IsDeprecated); | ||
| this.DownloadLatestToCustomPathCommand = new DelegateCommand(() => OnRequestDownload(true)); | ||
|
|
||
| this.UpvoteCommand = new DelegateCommand(SearchElementModel.Upvote, () => canLogin); | ||
|
|
@@ -143,11 +230,11 @@ private void OnSearchElementModelPropertyChanged(object sender, PropertyChangedE | |
| { | ||
| if (e.PropertyName == nameof(SearchElementModel.LatestCompatibleVersion)) | ||
| { | ||
| this.SelectedVersion = this.SearchElementModel.LatestCompatibleVersion; | ||
| SetDefaultSelectedVersion(); | ||
| } | ||
| if (e.PropertyName == nameof(SearchElementModel.VersionDetails)) | ||
| { | ||
| this.VersionInformationList = this.SearchElementModel.VersionDetails; | ||
| SetDefaultSelectedVersion(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -191,8 +278,11 @@ public bool CanInstall | |
|
|
||
| internal set | ||
| { | ||
| canInstall = value; | ||
| RaisePropertyChanged(nameof(CanInstall)); | ||
| if (canInstall != value) | ||
| { | ||
| canInstall = value; | ||
| RaisePropertyChanged(nameof(CanInstall)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -262,6 +352,7 @@ public List<VersionInformation> VersionInformationList | |
| { | ||
| versionInformationList = value; | ||
| RaisePropertyChanged(nameof(VersionInformationList)); | ||
| UpdateInstalledVersionFlags(); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -278,13 +369,75 @@ public ICollectionView ReversedVersionInformationList | |
| } | ||
| } | ||
|
|
||
| internal void UpdateInstalledVersion(string version, bool setDefaultSelection) | ||
| { | ||
| installedVersion = version; | ||
| UpdateInstalledVersionFlags(); | ||
|
|
||
| if (setDefaultSelection) | ||
| { | ||
| SetDefaultSelectedVersion(); | ||
| } | ||
| RaisePropertyChanged(nameof(InstallActionText)); | ||
| RaisePropertyChanged(nameof(InstallActionCommand)); | ||
| RaisePropertyChanged(nameof(IsInstalledVersionSelected)); | ||
| RaisePropertyChanged(nameof(IsInstalledFallback)); | ||
| RaisePropertyChanged(nameof(IsUninstallState)); | ||
| RefreshUninstallCommandCanExecute(); | ||
| } | ||
|
|
||
| private void SetDefaultSelectedVersion() | ||
| { | ||
| var defaultVersion = GetDefaultSelectedVersion(); | ||
| if (defaultVersion != null && SelectedVersion != defaultVersion) | ||
| { | ||
| SelectedVersion = defaultVersion; | ||
| } | ||
| } | ||
|
|
||
| private VersionInformation GetDefaultSelectedVersion() | ||
| { | ||
| if (!string.IsNullOrEmpty(installedVersion)) | ||
| { | ||
| var installedInfo = VersionInformationList?.FirstOrDefault(v => v.Version == installedVersion); | ||
| if (installedInfo != null) | ||
| { | ||
| return installedInfo; | ||
| } | ||
| } | ||
|
|
||
| return SearchElementModel?.LatestCompatibleVersion; | ||
| } | ||
|
|
||
| private void UpdateInstalledVersionFlags() | ||
| { | ||
| if (VersionInformationList == null) return; | ||
|
|
||
| foreach (var versionInfo in VersionInformationList) | ||
| { | ||
| versionInfo.IsInstalled = !string.IsNullOrEmpty(installedVersion) && | ||
| string.Equals(versionInfo.Version, installedVersion, StringComparison.OrdinalIgnoreCase); | ||
| } | ||
|
|
||
| RaisePropertyChanged(nameof(ReversedVersionInformationList)); | ||
| } | ||
|
|
||
| private void RefreshUninstallCommandCanExecute() | ||
| { | ||
| if (uninstallCommand is DelegateCommand delegateCommand) | ||
| { | ||
| delegateCommand.RaiseCanExecuteChanged(); | ||
| } | ||
| } | ||
|
|
||
| private List<String> CustomPackageFolders; | ||
| private bool? isSelectedVersionCompatible; | ||
|
|
||
| public delegate void PackageSearchElementDownloadHandler( | ||
| PackageManagerSearchElement element, PackageVersion version, string downloadPath = null); | ||
| public event PackageSearchElementDownloadHandler RequestDownload; | ||
|
|
||
| internal event Action<PackageManagerSearchElementViewModel> RequestUninstall; | ||
|
|
||
| public void OnRequestDownload(PackageVersion version, bool downloadToCustomPath) | ||
| { | ||
| string downloadPath = String.Empty; | ||
|
|
@@ -301,9 +454,19 @@ public void OnRequestDownload(PackageVersion version, bool downloadToCustomPath) | |
| RequestDownload(this.SearchElementModel, version, downloadPath); | ||
| } | ||
|
|
||
| private void OnRequestUninstall() | ||
| { | ||
| if (RequestUninstall != null) | ||
| { | ||
| RequestUninstall(this); | ||
| } | ||
| } | ||
|
|
||
| private void OnRequestDownload(bool downloadToCustomPath) | ||
| { | ||
| var version = this.SearchElementModel.Header.versions.First(x => x.version.Equals(SelectedVersion.Version)); | ||
| var version = this.SearchElementModel?.Header?.versions | ||
| ?.FirstOrDefault(x => x.version.Equals(SelectedVersion.Version)); | ||
| if (version == null) return; | ||
|
|
||
| string downloadPath = String.Empty; | ||
|
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.