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

Use pretty name for notification type field and corrected missing severity #2230

Merged
merged 5 commits into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ export const AdvancedFilters = ({
setSelectedCloudAccounts([]);
}, [notificationType, cloudProvider]);

const severities = [...SeverityEnumList];

return (
<div className="col-span-2 mt-6">
<div className="flex text-text-input-value ">
Expand Down Expand Up @@ -254,7 +256,7 @@ export const AdvancedFilters = ({
return value && value.length ? `${value.length} selected` : '';
}}
>
{SeverityEnumList.map((severity) => {
{severities.map((severity) => {
return (
<ListboxOption key={severity} value={severity}>
{getSeverityPrettyName(severity)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { AdvancedFilters } from './AdvancedFilter';
import { FieldSelection } from './FieldSelection';
import { TextInputType } from './TextInputType';
import {
getDisplayNotification,
getNotificationPrettyName,
IntegrationType,
isCloudComplianceNotification,
isCloudTrailNotification,
Expand Down Expand Up @@ -57,15 +57,15 @@ export const NotificationTypeField = ({
placeholder="Select notification type"
label="Notification Type"
getDisplayValue={() => {
return getDisplayNotification(notificationType);
return getNotificationPrettyName(notificationType);
}}
required
>
{['Vulnerability', 'Secret', 'Malware', 'Compliance', 'CloudCompliance'].map(
(notification) => {
return (
<ListboxOption key={notification} value={notification}>
{getDisplayNotification(notification)}
{getNotificationPrettyName(notification)}
</ListboxOption>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export const isJiraIntegration = (integrationType: string) => {
};

export const isCloudComplianceNotification = (notificationType: string) => {
return notificationType && notificationType === 'CloudCompliance';
return (
Copy link
Member

Choose a reason for hiding this comment

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

can you double check? this condition should be like notificationType && (notificationType === 'CloudCompliance' || notificationType.toLowerCase() === 'cloud_compliance')

notificationType &&
(notificationType.toLowerCase() === 'cloudcompliance' ||
notificationType.toLowerCase() === 'cloud_compliance')
);
};

export const isComplianceNotification = (notificationType: string) => {
Expand Down Expand Up @@ -156,7 +160,7 @@ export const API_SCAN_TYPE_MAP: Record<string, ScanTypeEnum> = {

export const scanTypes = ['Secret', 'Vulnerability', 'Malware'];

export const getDisplayNotification = (notificationType: string) => {
export const getNotificationPrettyName = (notificationType: string) => {
if (isCloudTrailNotification(notificationType)) {
return 'CloudTrail Alert';
} else if (isUserActivityNotification(notificationType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const CommonForm = ({
return getReportNodeType(resource);
}, [resource]);

const severities = resource ? [...SeverityEnumList] : [];

return (
<>
<Listbox
Expand Down Expand Up @@ -77,7 +79,7 @@ export const CommonForm = ({
setSeverity([]);
}}
>
{[...SeverityEnumList].splice(0, SeverityEnumList.length - 1).map((resource) => {
{severities.map((resource) => {
return (
<ListboxOption value={resource} key={resource}>
{upperFirst(resource)}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { has, isEmpty } from 'lodash-es';
import { has, isEmpty, startCase } from 'lodash-es';
import { useMemo } from 'react';
import { useParams } from 'react-router-dom';
import {
Expand All @@ -18,7 +18,7 @@ import {
severityMap,
} from '@/features/integrations/pages/IntegrationAdd';

import { IntegrationType } from './integration-form/utils';
import { getNotificationPrettyName, IntegrationType } from './integration-form/utils';

const ActionDropdown = ({
row,
Expand Down Expand Up @@ -603,7 +603,7 @@ export const useIntegrationTableColumn = (
maxSize: 75,
}),
columnHelper.accessor('notification_type', {
cell: (cell) => cell.getValue(),
cell: (cell) => startCase(getNotificationPrettyName(cell.getValue() ?? '')),
header: () => 'Notification type',
minSize: 65,
size: 70,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
UtilsReportFiltersSeverityOrCheckTypeEnum,
} from '@/api/generated';
import { SlidingModalHeaderWrapper } from '@/features/common/SlidingModalHeaderWrapper';
import { getNotificationPrettyName } from '@/features/integrations/components/integration-form/utils';
import { AdvancedFilter } from '@/features/integrations/components/report-form/AdvanceFilter';
import { CloudComplianceForm } from '@/features/integrations/components/report-form/CloudComplianceForm';
import { CommonForm } from '@/features/integrations/components/report-form/CommonForm';
Expand All @@ -33,7 +34,7 @@ import { apiWrapper } from '@/utils/api';
import { getArrayTypeValuesFromFormData } from '@/utils/formData';
import { usePageNavigation } from '@/utils/usePageNavigation';

export const RESOURCES = [
export const RESOURCES: UtilsReportFiltersScanTypeEnum[] = [
UtilsReportFiltersScanTypeEnum.Vulnerability,
UtilsReportFiltersScanTypeEnum.Secret,
UtilsReportFiltersScanTypeEnum.Malware,
Expand Down Expand Up @@ -148,9 +149,8 @@ const action = async ({ request }: ActionFunctionArgs): Promise<ActionData> => {
include_dead_nodes: body.deadNodes === 'on',
node_type: _nodeType,
scan_type: _resource,
severity_or_check_type: (severitiesOrCheckTypes as string[]).map((sev) =>
sev.toLowerCase(),
) as UtilsReportFiltersSeverityOrCheckTypeEnum,
severity_or_check_type:
Copy link
Member

Choose a reason for hiding this comment

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

please double check this change

severitiesOrCheckTypes as UtilsReportFiltersSeverityOrCheckTypeEnum,
},

report_type: _reportType,
Expand Down Expand Up @@ -186,13 +186,6 @@ const Header = () => {
);
};

const getResourceDisplayValue = (resource: string) => {
if (resource === UtilsReportFiltersScanTypeEnum.CloudCompliance) {
return 'Cloud Compliance';
}
return resource;
};

const ReportForm = () => {
const [resource, setResource] = useState('');
const [provider, setProvider] = useState('');
Expand Down Expand Up @@ -229,15 +222,15 @@ const ReportForm = () => {
setProvider('');
}}
getDisplayValue={(item) => {
return item ? upperFirst(getResourceDisplayValue(item)) : '';
return item ? upperFirst(getNotificationPrettyName(item)) : '';
}}
placeholder="Select resource"
required
>
{RESOURCES.map((resource) => {
return (
<ListboxOption value={resource} key={resource}>
{upperFirst(getResourceDisplayValue(resource))}
{upperFirst(getNotificationPrettyName(resource))}
</ListboxOption>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,7 @@ const action = async ({ request, params }: ActionFunctionArgs): Promise<ActionDa
const filters = _filters.fields_filters.contains_filter.filter_in;
const newFilter = {
...filters,
[severityMap[_notificationType ?? ''] || 'severity']: severityFilter.map(
(severity) => severity.toLowerCase(),
),
[severityMap[_notificationType ?? ''] || 'severity']: severityFilter,
};
_filters.fields_filters.contains_filter.filter_in = newFilter;
}
Expand Down
Loading