Skip to content

Refactor package vulnerability scanner stores #232

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

Merged
merged 3 commits into from
Jul 10, 2025

Conversation

dotNomad
Copy link
Collaborator

@dotNomad dotNomad commented Jul 9, 2025

In an effort to improve the Package Vulnerability Scanner with additional features a bit of a store refactor was required to raise information about Content, their packages, and the vulnerabilities related to those packages. Previously this information was split across components and used as needed. Now there is a scanner store that collects that information into a Content type to be used by several components.

The new Content type consolidates the packages and vulnerabilityCount info so it can be used in a cleaner way. This also opens up the door for some more features to be done in a cleaner way.

These changes have been published to our internal Dogfood server here.

@@ -1,51 +1,49 @@
{
"version": 1,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Most of these are Prettier formatting changes. The only real changes are file checksums

Copy link
Contributor

@marcosnav marcosnav left a comment

Choose a reason for hiding this comment

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

Looks pretty good, minor comments and questions.

function handleClick() {
contentStore.currentContentId = props.content.guid;
scannerStore.currentContent = props.content;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not fully familiar with Pinia yet, so take this comment with a handful of salt. Couple questions here, also for my own education:

  1. Assigning an object to the state, could it lead to unwanted side-effects? sinceprops.content is a reactive object, any change to it would propagate, this can be good when that's the intention though.
  2. Updating the state directly, I think it is pretty handy and simple, instead of having to create methods to mutate the state. Still, is this the encouraged way to do it in Pinia? IIRC the .$patch method is preferred, although I don't know if there is a substantial difference.

Copy link
Collaborator Author

@dotNomad dotNomad Jul 10, 2025

Choose a reason for hiding this comment

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

Happy to answer :)

Pinia has examples in the documentation to directly manipulate state. The $patch method is to apply multiple changes at once to prevent duplicate re-renders. If you are manipulating one there isn't a need to do that.

It can lead to unwanted side-effects but in this case I want to react when scannerStore.currentContent changes. One reason I have props.content specifically is so I can guarantee that this component is getting Content for typing reasons (as opposed to grabbing the content from scannerStore.currentContent and having undefined logic everywhere.

References: https://pinia.vuejs.org/core-concepts/state.html#Mutating-the-state

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry I submitted a bit early, edited my comment to have everything I wanted to say.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for the explanation! 😄

v-if="isFetched"
:type="hasVulnerabilities ? 'error' : 'success'"
v-else
:type="content.vulnerabilityCount > 0 ? 'error' : 'success'"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this attr check might be better as a computed instance?

@@ -56,7 +58,7 @@ fetchPackagesInBatches();
/>
</div>

<div v-else-if="contentStore.contentList.length === 0">
<div v-else-if="scannerStore.content.length === 0">
Copy link
Contributor

Choose a reason for hiding this comment

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

same nit here: I think the other checks you have, where the logic is handled as computed and the template is a bit cleaner, are pretty good.

Also, since this is already data from the store, WDYT about a getter? e.g: scannerStore.hasContent

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed with you on all the comments you left. I'll consolidate the computed properties to scannerStore where it makes sense.

@dotNomad dotNomad merged commit b94b786 into main Jul 10, 2025
18 checks passed
@dotNomad dotNomad deleted the dotnomad/refactor-scanner-stores branch July 10, 2025 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants