Commit d820d645 authored by Daniel Tian's avatar Daniel Tian

Move BASE_FILTERS from filters/constants to security_dashboard/helpers

Changelog: other
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/83240
EE: true
parent a2a64e65
...@@ -4,7 +4,6 @@ import { ...@@ -4,7 +4,6 @@ import {
REPORT_TYPES_NO_CLUSTER_IMAGE, REPORT_TYPES_NO_CLUSTER_IMAGE,
SEVERITY_LEVELS, SEVERITY_LEVELS,
} from 'ee/security_dashboard/store/constants'; } from 'ee/security_dashboard/store/constants';
import { BASE_FILTERS } from 'ee/security_dashboard/store/modules/filters/constants';
import convertReportType from 'ee/vue_shared/security_reports/store/utils/convert_report_type'; import convertReportType from 'ee/vue_shared/security_reports/store/utils/convert_report_type';
import { VULNERABILITY_STATES } from 'ee/vulnerabilities/constants'; import { VULNERABILITY_STATES } from 'ee/vulnerabilities/constants';
import { convertObjectPropsToSnakeCase } from '~/lib/utils/common_utils'; import { convertObjectPropsToSnakeCase } from '~/lib/utils/common_utils';
...@@ -14,6 +13,8 @@ import { DEFAULT_SCANNER } from './constants'; ...@@ -14,6 +13,8 @@ import { DEFAULT_SCANNER } from './constants';
const parseOptions = (obj) => const parseOptions = (obj) =>
Object.entries(obj).map(([id, name]) => ({ id: id.toUpperCase(), name })); Object.entries(obj).map(([id, name]) => ({ id: id.toUpperCase(), name }));
const toolName = s__('SecurityReports|Tool');
const allToolsName = s__('ciReport|All tools');
const stateOptions = parseOptions(VULNERABILITY_STATES); const stateOptions = parseOptions(VULNERABILITY_STATES);
const defaultStateOptions = stateOptions.filter((x) => ['DETECTED', 'CONFIRMED'].includes(x.id)); const defaultStateOptions = stateOptions.filter((x) => ['DETECTED', 'CONFIRMED'].includes(x.id));
...@@ -21,7 +22,7 @@ export const stateFilter = { ...@@ -21,7 +22,7 @@ export const stateFilter = {
name: s__('SecurityReports|Status'), name: s__('SecurityReports|Status'),
id: 'state', id: 'state',
options: stateOptions, options: stateOptions,
allOption: BASE_FILTERS.state, allOption: { id: 'all', name: s__('VulnerabilityStatusTypes|All statuses') },
defaultOptions: defaultStateOptions, defaultOptions: defaultStateOptions,
}; };
...@@ -29,7 +30,7 @@ export const severityFilter = { ...@@ -29,7 +30,7 @@ export const severityFilter = {
name: s__('SecurityReports|Severity'), name: s__('SecurityReports|Severity'),
id: 'severity', id: 'severity',
options: parseOptions(SEVERITY_LEVELS), options: parseOptions(SEVERITY_LEVELS),
allOption: BASE_FILTERS.severity, allOption: { name: s__('ciReport|All severities') },
defaultOptions: [], defaultOptions: [],
}; };
...@@ -48,38 +49,38 @@ export const createScannerOption = (vendor, reportType) => { ...@@ -48,38 +49,38 @@ export const createScannerOption = (vendor, reportType) => {
// used by the scanner filter that shows a flat list of scan types (DAST, SAST, etc) with no vendor // used by the scanner filter that shows a flat list of scan types (DAST, SAST, etc) with no vendor
// grouping. // grouping.
export const simpleScannerFilter = { export const simpleScannerFilter = {
name: s__('SecurityReports|Tool'), name: toolName,
id: 'reportType', id: 'reportType',
options: parseOptions(REPORT_TYPES), options: parseOptions(REPORT_TYPES),
allOption: BASE_FILTERS.report_type, allOption: { name: allToolsName },
defaultOptions: [], defaultOptions: [],
}; };
export const simpleScannerFilterNoClusterImage = { export const simpleScannerFilterNoClusterImage = {
name: s__('SecurityReports|Tool'), name: toolName,
id: 'reportType', id: 'reportType',
options: parseOptions(REPORT_TYPES_NO_CLUSTER_IMAGE), options: parseOptions(REPORT_TYPES_NO_CLUSTER_IMAGE),
allOption: BASE_FILTERS.report_type, allOption: { name: allToolsName },
defaultOptions: [], defaultOptions: [],
}; };
// This is used on the project-level report. It's used by the scanner filter that shows a list of // This is used on the project-level report. It's used by the scanner filter that shows a list of
// scan types (DAST, SAST, etc) that's grouped by vendor. // scan types (DAST, SAST, etc) that's grouped by vendor.
export const vendorScannerFilter = { export const vendorScannerFilter = {
name: s__('SecurityReports|Tool'), name: toolName,
id: 'scanner', id: 'scanner',
options: Object.keys(REPORT_TYPES).map((x) => createScannerOption(DEFAULT_SCANNER, x)), options: Object.keys(REPORT_TYPES).map((x) => createScannerOption(DEFAULT_SCANNER, x)),
allOption: BASE_FILTERS.report_type, allOption: { name: allToolsName },
defaultOptions: [], defaultOptions: [],
}; };
export const vendorScannerFilterNoClusterImage = { export const vendorScannerFilterNoClusterImage = {
name: s__('SecurityReports|Tool'), name: toolName,
id: 'scanner', id: 'scanner',
options: Object.keys(REPORT_TYPES_NO_CLUSTER_IMAGE).map((x) => options: Object.keys(REPORT_TYPES_NO_CLUSTER_IMAGE).map((x) =>
createScannerOption(DEFAULT_SCANNER, x), createScannerOption(DEFAULT_SCANNER, x),
), ),
allOption: BASE_FILTERS.report_type, allOption: { name: allToolsName },
defaultOptions: [], defaultOptions: [],
}; };
...@@ -93,7 +94,7 @@ export const activityFilter = { ...@@ -93,7 +94,7 @@ export const activityFilter = {
name: s__('Reports|Activity'), name: s__('Reports|Activity'),
id: 'activity', id: 'activity',
options: Object.values(activityOptions), options: Object.values(activityOptions),
allOption: BASE_FILTERS.activity, allOption: { name: s__('SecurityReports|All activity') },
defaultOptions: [], defaultOptions: [],
}; };
...@@ -101,7 +102,7 @@ export const projectFilter = { ...@@ -101,7 +102,7 @@ export const projectFilter = {
name: s__('SecurityReports|Project'), name: s__('SecurityReports|Project'),
id: 'projectId', id: 'projectId',
options: [], options: [],
allOption: BASE_FILTERS.project_id, allOption: { name: s__('ciReport|All projects') },
defaultOptions: [], defaultOptions: [],
}; };
......
import { s__ } from '~/locale';
export const ALL = 'all';
export const STATE = {
DETECTED: 'DETECTED',
CONFIRMED: 'CONFIRMED',
};
export const DISMISSAL_STATES = { export const DISMISSAL_STATES = {
DISMISSED: 'dismissed', DISMISSED: 'dismissed',
ALL: 'all', ALL: 'all',
}; };
export const BASE_FILTERS = {
state: {
name: s__('VulnerabilityStatusTypes|All statuses'),
id: ALL,
},
severity: {
name: s__('ciReport|All severities'),
id: ALL,
},
report_type: {
name: s__('ciReport|All tools'),
id: ALL,
},
activity: {
name: s__('SecurityReports|All activity'),
id: ALL,
},
project_id: {
name: s__('ciReport|All projects'),
id: ALL,
},
};
...@@ -118,7 +118,7 @@ describe('Scanner Filter component', () => { ...@@ -118,7 +118,7 @@ describe('Scanner Filter component', () => {
expectSelectedItems(selectedOptions); expectSelectedItems(selectedOptions);
await clickAndCheck(filter.options); // First click selects all. await clickAndCheck(filter.options); // First click selects all.
await clickAndCheck([filter.allOption]); // Second check unselects all. await clickAndCheck([{ id: 'all' }]); // Second check unselects all.
await clickAndCheck(filter.options); // Third click selects all again. await clickAndCheck(filter.options); // Third click selects all again.
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment