-
Notifications
You must be signed in to change notification settings - Fork 31
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
feat: display Priority Score in Snyk Code suggestions [IDE-30] #422
Conversation
Priority Score is rendered dynamically within the issue details. Co-authored-by: Jason Luong <[email protected]>
011f8a0
to
527a185
Compare
`showSuggestionMeta` handles the dynamic generation of issue type, CWE links, issue position, and priority score.
Updated `severity` property in the `Suggestion` from a generic `string` to a specific union type: `'Low' | 'Medium' | 'High'`. This ensures that severity can only be one of these three explicit values.
The `toggleSeverityIcons` function updates the visibility of severity icons based on the `currentSeverity`. If `currentSeverity` is undefined, all icons are hidden.
9c7b118
to
debe8bc
Compare
…gestion` This change aims to make clear that these variables are references to DOM elements, not values or other types of objects.
This change aims to avoid overwriting existing classes list by directly manipulating `className`.
|
||
function appendIdentifierSpan(identifiers: Element, id: string, link?: string) { | ||
const delimiter = document.createElement('span'); | ||
delimiter.innerText = ' | '; | ||
delimiter.className = 'delimiter'; | ||
identifiers.appendChild(delimiter); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When testing https://github.com/dexidp/dex I realised that we had an extra delimiter in Snyk Configuration Issue panel
Before | After |
---|---|
// Append the priority score if available. | ||
if (suggestion.priorityScore !== undefined) { | ||
const priorityScoreElement = document.createElement('span'); | ||
priorityScoreElement.className = 'suggestion-meta'; | ||
priorityScoreElement.textContent = `Priority Score: ${suggestion.priorityScore}`; | ||
metaElem.appendChild(priorityScoreElement); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have decided to enable this rule with the idea that little by little we will add the missing types. I'm happy to revert it if the team finds it so.
const severityMap = { | ||
Low: 1, | ||
Medium: 2, | ||
High: 3, | ||
}; | ||
return suggestion | ||
? { | ||
value: stringMap[suggestion.severity], | ||
text: suggestion.severity, | ||
} | ||
: undefined; | ||
|
||
const severityAllowedValues = Object.keys(severityMap); | ||
if (!severityAllowedValues.includes(severity)) { | ||
return undefined; | ||
} | ||
|
||
return { | ||
value: severityMap[severity], | ||
text: severity, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this function since the check suggestion ? {} : undefined
didn't guarantee that suggestion contained a severity
property or that severity
contained valid values to match severityMap[suggestion.severity]
.
function toggleSeverityIcons(severity: HTMLElement, currentSeverity: CurrentSeverity | undefined) { | ||
const severityIcons = severity.querySelectorAll('img'); | ||
const validIconsIds: { [key: number]: string } = { 1: 'sev1', 2: 'sev2', 3: 'sev3' }; | ||
|
||
if (!currentSeverity) { | ||
severityIcons.forEach(icon => (icon.className = 'icon hidden')); | ||
return; | ||
} | ||
|
||
severity.setAttribute('title', currentSeverity.text); | ||
|
||
severityIcons.forEach(icon => { | ||
const currentIconId = validIconsIds[currentSeverity.value]; | ||
icon.className = icon.id === currentIconId ? 'icon' : 'icon hidden'; | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've opted for strict comparison icon.id === currentIconId
instead of testing it with contains
: n.id.includes(currentSeverity.value)
to ensure matching
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done @cat2608, for amazing refactoring and implementation!
- Adjusted colors for 'added' and 'removed' elements to improve visibility in high contrast mode. - Ensured consistent background color for 'code' elements within 'added' and 'removed' sections. This commit addresses visual issues in the high contrast theme of VSCode.
Description
Priority Score is rendered dynamically within the issue details.
The Priority Score will become available once the Language Server propagates it, as detailed in this PR: snyk/snyk-ls#425
Checklist
Screenshots / GIFs
priority-score.mp4