Skip to content
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

✨ OSIDB-3434: Reusable CvssCalculator for affect fields #443

Merged
merged 5 commits into from
Nov 12, 2024

Conversation

C-Valen
Copy link
Member

@C-Valen C-Valen commented Sep 26, 2024

OSIDB-3434: Reusable CvssCalculator for affect fields

Checklist:

  • Commits consolidated
  • Changelog updated
  • Test cases added/updated
  • Jira ticket updated

Summary:

Refactors CvssCalculator component to make it reusable in different layouts and uses it on the CVSS fields of the affect table.

Changes:

  • Fix minor wrong types issue
  • Refactors CvssCalculator component
  • Creates a OverlayedCvssCalculator component
  • Applies new component to the affect section
  • Minor affect section adjustments to support the calculator
  • Update test cases and snapshots

Demo:

OSIM-CvssCalculator-OnAffects-Demo.mp4

*UPDATE:
Refactor made to reduce the width of the CVSS columns in the affect table. In order to achieve that, now it is only displayed the CVSS Score by default, and the vector in a tooltip when hovering the cell. In edit mode the CVSS Vector input has been moved into the calculator's popup div, that way the column can be kept in reduced size while supporting all the functionalities of the CVSS Calculator.

*UPDATEv2:
It has been added a padding bottom on the flaw affects section to fix some UI bugs caused on the overplayed calculator, cause part of it was outside of the section.

Normal CVSS Score display:
image

CVSS Vector tooltip:
image

Edit mode with calculator closed:
image

Edit mode with calculator opened:
image

Closes OSIDB-3434
Closes OSIDB-3511

@C-Valen C-Valen added the enhancement New feature or request label Sep 26, 2024
@C-Valen C-Valen self-assigned this Sep 26, 2024
@C-Valen C-Valen marked this pull request as draft September 26, 2024 14:10
@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch from 95143c5 to 46e47e4 Compare October 1, 2024 11:26
@C-Valen C-Valen marked this pull request as ready for review October 1, 2024 11:33
@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch from 19fa6d0 to af0ae1d Compare October 1, 2024 11:38
@C-Valen C-Valen marked this pull request as draft October 7, 2024 11:33
@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch from d03e8e3 to 80ff4b2 Compare October 10, 2024 11:29
@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch 2 times, most recently from 2a39697 to 2e39eb9 Compare November 4, 2024 15:34
@C-Valen C-Valen marked this pull request as ready for review November 4, 2024 15:37
@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch 3 times, most recently from 0f1e0ab to 17ee7bd Compare November 6, 2024 09:55
@C-Valen
Copy link
Member Author

C-Valen commented Nov 6, 2024

Update:

  • Commits squashed for reduced noise and better organization
  • Changelog corrected

@@ -27,6 +27,7 @@ const emit = defineEmits<{
'affect:revert': [value: ZodAffectType];
'affect:toggle-selection': [value: ZodAffectType];
'affect:track': [value: ZodAffectType];
'affect:updateCvss': [affect: ZodAffectType, newVector: string, newScore: null | number, cvssScoreIndex: number];
Copy link
Member

Choose a reason for hiding this comment

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

Since we have this event declared multiple times as is passed to multiple children, what do you guys think about exporting the type? That way is only declared once and can be used for the handler as well?
@superbuggy

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sensible!

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed on meeting this will be handled in an independent task/PR (OSIDB-3668)

affect.cvss_scores[cvssScoreIndex].score = newScore;
} else if (newVector !== '') {
affect.cvss_scores.push({
issuer: 'RH',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
issuer: 'RH',
issuer: IssuerEnum.Rh,

} else if (newVector !== '') {
affect.cvss_scores.push({
issuer: 'RH',
cvss_version: 'V3',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cvss_version: 'V3',
cvss_version: CVSS_V3,

Comment on lines 103 to 132
const cvssId = affect.cvss_scores[cvssScoreIndex]?.uuid;
if (newVector === '' && cvssScoreIndex !== -1 && affect.uuid && cvssId) {
affect.cvss_scores[cvssScoreIndex].vector = '';
affect.cvss_scores[cvssScoreIndex].score = null;
affectCvssToDelete.value[affect.uuid] = cvssId;
} else {
if (affect.uuid && affectCvssToDelete.value[affect.uuid]) {
delete affectCvssToDelete.value[affect.uuid];
}
if (cvssScoreIndex !== -1) {
affect.cvss_scores[cvssScoreIndex].vector = newVector;
affect.cvss_scores[cvssScoreIndex].score = newScore;
} else if (newVector !== '') {
affect.cvss_scores.push({
issuer: 'RH',
cvss_version: 'V3',
comment: '',
score: newScore,
vector: newVector,
embargoed: affect.embargoed,
alerts: [],
});
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I find this function a bit hard to follow, could you change it a bit? Maybe use an early return instead of the else and maybe add a short comment on what each branch of the conditionals are intended to do

},
});
function affectCvss(affect: ZodAffectType) {
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === 'RH' && cvss_version === 'V3');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === 'RH' && cvss_version === 'V3');
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === IssuerEnum.Rh && cvss_version === CSSV_V3);

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a new component only to show it on a overlay? Can't just mount the same CvssCalculator on a div and move the div to the correct position?

The only change I see is that we are triggering an event on change, we could just trigger that event on a parent with a watch and use the same CvssCalculator

},
});
function affectCvss(affect: ZodAffectType) {
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === 'RH' && cvss_version === 'V3');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === 'RH' && cvss_version === 'V3');
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === IssuerEnum.Rh && cvss_version === CVSS_V3);

@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch 3 times, most recently from c935959 to 8170bda Compare November 7, 2024 11:58
@C-Valen C-Valen requested a review from MrMarble November 7, 2024 12:03
@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch from 8170bda to af41930 Compare November 7, 2024 12:07
@@ -23,7 +23,9 @@ const props = defineProps<{
const showAllCvss = ref(false);

const otherCvss = computed(() => props.allCvss.filter(cvssItem =>
(!(cvssItem.cvss_version === 'V3' && (cvssItem.issuer === IssuerEnum.Rh || cvssItem.issuer === IssuerEnum.Nist)))));
(
!(cvssItem.cvss_version === 'CVSS_V3' && (cvssItem.issuer === IssuerEnum.Rh || cvssItem.issuer === IssuerEnum.Nist))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
!(cvssItem.cvss_version === 'CVSS_V3' && (cvssItem.issuer === IssuerEnum.Rh || cvssItem.issuer === IssuerEnum.Nist))
!(cvssItem.cvss_version === CVSS_V3 && (cvssItem.issuer === IssuerEnum.Rh || cvssItem.issuer === IssuerEnum.Nist))

},
});
function affectCvss(affect: ZodAffectType) {
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === IssuerEnum.Rh && cvss_version === 'CVSS_V3');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === IssuerEnum.Rh && cvss_version === 'CVSS_V3');
return affect.cvss_scores.find(({ cvss_version, issuer }) => issuer === IssuerEnum.Rh && cvss_version === CVSS_V3);

} else if (newVector !== '') {
affect.cvss_scores.push({
issuer: IssuerEnum.Rh,
cvss_version: 'CVSS_V3',
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
cvss_version: 'CVSS_V3',
cvss_version: CVSS_V3,

@C-Valen C-Valen force-pushed the feature/OSIDB-3434-cvss-calculator-on-affects branch from af41930 to 0b0d9ae Compare November 11, 2024 09:11
MrMarble
MrMarble previously approved these changes Nov 11, 2024
Copy link
Member

@MrMarble MrMarble left a comment

Choose a reason for hiding this comment

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

LGTM

'background-color': hslForBackground,
};
};

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this just used in the buttons?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, also in the vector

@@ -0,0 +1,170 @@
<script setup lang="ts">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we change the name to CvssFactorButtons.vue?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure


function reset() {
cvssScore.value = null;
emit('updateAffectCvss', '', null);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this be emit('affect:cvss:update', '', null)?

Copy link
Member Author

Choose a reason for hiding this comment

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

As commented off thread, it needs to be discussed what convention we get into and apply it to all emits

✨ Use new CvssCalculator components
✅ Update snapshots

✅ Add overlayed calculator test suite
@C-Valen C-Valen merged commit c4593e3 into main Nov 12, 2024
5 checks passed
@C-Valen C-Valen deleted the feature/OSIDB-3434-cvss-calculator-on-affects branch November 12, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants