Skip to content

[Data model] Package factory - #6326

Merged
martinrrm merged 7 commits into
dev-feature-PackageDomainModelfrom
dev-martinrrm-package-factory
Mar 21, 2025
Merged

martinrrm merged 7 commits into
dev-feature-PackageDomainModelfrom
dev-martinrrm-package-factory

Conversation

@martinrrm

@martinrrm martinrrm commented Mar 19, 2025 •

Copy link
Copy Markdown
Contributor

Bug

Fixes:

Description

Adds a factory class to create the corresponding PackageModel depending on the metadata provided.
This PR also adds the PackageModel to the PckageItemViewModel

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

@dotnet-policy-service

dotnet-policy-service Bot commented Mar 19, 2025 •

Copy link
Copy Markdown
Contributor

This PR contains changes to XAML files. Verify that you've completed the following tasks:

@martinrrm
martinrrm force-pushed the dev-martinrrm-package-factory branch from e8f88ee to ef2009a Compare March 20, 2025 17:22
public string? Authors { get; }

public IReadOnlyList<string>? OwnersList { get; }
public string? Owners { get; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we going back to a string of owners after deciding to have a list of owners?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

PackageSearchMetadataContextInfo has OwnersList and Owners as properties, but PackageViewModel only uses Owners and I cannot find where we actually use OwnersList, not sure why we have both but given that Owners is the only one used in the ViewModel I think we should use that one instead of OwnersList which is not used

@donnie-msft donnie-msft Mar 21, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we going back to a string of owners after deciding to have a list of owners?

@jebriede When was this decision made?

not sure why we have both

@martinrrm did you look at the history of the code you referenced when creating this model? There should be a PR when I made changes for the Owner work and it was intentional to have both. There should be PR Description and review feedback about it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@donnie-msft I'm glad to get your perspective about this! We want our model to represent structured data and have the comma-delimited list for display purposes.

@martinrrm let's find that PR and make sure we're not missing anything to have one representation in the new model.

@jebriede jebriede Mar 21, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@donnie-msft There's 10 closed PRs that mention owners! 🙂 Would you mind pointing us at the PR and the comment that helps understand why the PackageSearchMetadataContextInfo has both a comma-delimited list and a list of owners? That would be very helpful!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@donnie-msft do you mean this pr? #5751

It sounds like we needed both when converting from JSON because the v2 api returns owners as a string, which caused an exception. These changes aren't impacting how we parse the data from the API.

The model in the PM UI shouldn't care about implementation details from different APIs, I think we should pick one and stick with it. My preference is the ReadonlyList of Owners, it leaves formatting the owners for the presentation layer up to the ViewModel.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I highly recommend using git blame rather than searching keywords in git when understanding existing code.

@jgonz120 yes, you found where Protocol provides both Owners & OwnersList! Both are part of the NuGet API and can be used as needed by the PM UI. The ViewModel today uses Owners and OwnerList, here's one example:

My preference is the ReadonlyList of Owners, it leaves formatting the owners for the presentation layer up to the ViewModel.

Yes, and the OwnersList is what's used today when rendering the owner hyperlinks. In places like the ToolTip, the string is used.

Rebuilding this owner string from the owners list in the UI is something you could do but just note that the string is already given to you directly by the NuGet API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh I see from the docs, https://learn.microsoft.com/en-us/nuget/api/search-query-service-resource#search-result, the owner can be returned from the API as a string representing a single owner. I wonder if we actually need to preemptively convert the list of owners to a string.

@martinrrm
martinrrm force-pushed the dev-martinrrm-package-factory branch from f4931d1 to 2961e97 Compare March 20, 2025 21:28
@martinrrm
martinrrm marked this pull request as ready for review March 20, 2025 21:29
@martinrrm
martinrrm requested a review from a team as a code owner March 20, 2025 21:29
@martinrrm
martinrrm requested review from jebriede and jgonz120 March 20, 2025 21:29
}

var listItem = new PackageItemViewModel(_searchService, _packageVulnerabilityService)
PackageModel packageModel = _packageModelFactory.Create(metadataContextInfo, _itemFilter);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this still create an installed package if we're on the browse tab and the package has been installed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can you help me understand this scenario with our package models?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Idk how to describe it that way, but if you search in the PM UI it will show a green check if the package is installed. UI will say uninstall instead of update.
image

@martinrrm
martinrrm requested review from jebriede and jgonz120 March 21, 2025 00:09
@martinrrm
martinrrm force-pushed the dev-martinrrm-package-factory branch from 4742eab to a892893 Compare March 21, 2025 02:39
@martinrrm
martinrrm merged commit be0932a into dev-feature-PackageDomainModel Mar 21, 2025
@martinrrm
martinrrm deleted the dev-martinrrm-package-factory branch March 21, 2025 18:08
jebriede pushed a commit that referenced this pull request Mar 24, 2025
jebriede pushed a commit that referenced this pull request Apr 16, 2025
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.

4 participants