Simplify getFormattedScanners logic for vulnerability report tool filter
What does this MR do and why?
This MR addresses a follow-up:
The following discussion from !106199 (merged) should be addressed:
-
@dftian started a discussion: This is not specific to this MR, but I took a look at where
option.disabled
was created and and I think we can greatly simplify the code for it. It takes advantage of the fact thatREPORT_TYPES_WITH_MANUALLY_ADDED
already has the report types alphabetically ordered withGENERIC
at the bottom, and we don't need the scanner IDs, we just need to know if there are any fordisabled
:Subject: [PATCH] clipboard --- Index: ee/app/assets/javascripts/security_dashboard/helpers.js IDEA additional info: Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP <+>UTF-8 =================================================================== diff --git a/ee/app/assets/javascripts/security_dashboard/helpers.js b/ee/app/assets/javascripts/security_dashboard/helpers.js --- a/ee/app/assets/javascripts/security_dashboard/helpers.js (revision b5740adfad19f2ecebdbbd1a86288cbbe6732e2a) +++ b/ee/app/assets/javascripts/security_dashboard/helpers.js (date 1670368811297) @@ -177,26 +177,8 @@ }; /** - * Provided a groupBy vulnerability scanners, this returns an array that is - * sorted alphabetically with the "GENERIC" custom scanner name as the last item - * - * @param {Object} groupedByReportType - * @returns {Array} sorted groupedByReportType - */ -const sortGroupedReportType = (groupedByReportType) => { - const manuallyAddedScannerId = 'GENERIC'; - - return Object.entries(groupedByReportType).sort(([a], [b]) => { - if (a === manuallyAddedScannerId) return 1; - if (b === manuallyAddedScannerId) return -1; - - return a.localeCompare(b); - }); -}; - -/** - * Provided a vulnerability scanners from the GraphQL API, this returns an array that is - * formatted so it can be displayed in the dropdown UI. + * Provided vulnerability scanners from the GraphQL API, this returns an array that is formatted + * so it can be displayed in the dropdown UI. * The final formatted scanners will include all possible scanners, including the available ones * from the GraphQL API and the unavailable ones. * @@ -204,27 +186,16 @@ * @returns {Array} formatted vulnerabilityScanners */ export const getFormattedScanners = (vulnerabilityScanners) => { - const allPossibleReportTypes = Object.keys(REPORT_TYPES_WITH_MANUALLY_ADDED).reduce( - (a, v) => ({ ...a, [v.toUpperCase()]: null }), - {}, - ); - const availableReportTypes = groupBy(vulnerabilityScanners, 'reportType'); + const groupedByReportType = groupBy(vulnerabilityScanners, 'reportType'); - const combinedDeduplicatedReportTypes = { - ...allPossibleReportTypes, - ...availableReportTypes, - }; + return Object.entries(REPORT_TYPES_WITH_MANUALLY_ADDED).map(([type, name]) => { + const reportType = type.toUpperCase(); - const sortedAllReportTypes = sortGroupedReportType(combinedDeduplicatedReportTypes); - - return sortedAllReportTypes.map(([reportType, scanners]) => { - const scannersArr = scanners || []; return { id: reportType, reportType, - name: SCANNER_NAMES_MAP[reportType] || SCANNER_NAMES_MAP.GENERIC, - scannerIds: scannersArr.map(({ id }) => id), - disabled: scannersArr.length === 0, + name, + disabled: (groupedByReportType[reportType] || []).length <= 0, }; }); };
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #385029 (closed)