Skip to content

Commit

Permalink
Apply review remarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
a-h-abdelsalam committed Jul 3, 2024
1 parent 22b87c8 commit 2311adb
Show file tree
Hide file tree
Showing 28 changed files with 81 additions and 184 deletions.
2 changes: 1 addition & 1 deletion src/gmp/capabilities/capabilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const convertType = type => {
if (isDefined(ctype)) {
type = ctype;
}
return subtypes[type] ? subtypes[type] : type;
return subtypes[type] || type;
};

class Capabilities {
Expand Down
2 changes: 0 additions & 2 deletions src/gmp/commands/auditreports.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,3 @@ export class AuditReportCommand extends EntityCommand {

registerCommand('auditreport', AuditReportCommand);
registerCommand('auditreports', AuditReportsCommand);

// vim: set ts=2 sw=2 tw=80:
4 changes: 1 addition & 3 deletions src/gmp/models/auditreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class AuditReport extends Model {
copy.task = parseModelFromElement(task, 'task');

copy.reportType = type;
copy.contentType = content_type; // revert ?
copy.contentType = content_type;

copy.scan_start = parseDate(scan_start);
copy.timestamp = parseDate(timestamp);
Expand All @@ -63,5 +63,3 @@ class AuditReport extends Model {
}

export default AuditReport;

// vim: set ts=2 sw=2 tw=80:
4 changes: 0 additions & 4 deletions src/gmp/models/report/auditreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ class AuditReportReport extends Model {

copy.reportType = element._type;

// copy.scanRunStatus = element.scan_run_status;

delete copy.filters;

if (isDefined(compliance)) {
Expand Down Expand Up @@ -140,5 +138,3 @@ class AuditReportReport extends Model {
}

export default AuditReportReport;

// vim: set ts=2 sw=2 tw=80:
4 changes: 1 addition & 3 deletions src/web/components/bar/compliancebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,4 @@ ComplianceBar.propTypes = {
toolTip: PropTypes.string,
};

export default ComplianceBar;

// vim: set ts=2 sw=2 tw=80:
export default ComplianceBar;
68 changes: 16 additions & 52 deletions src/web/components/label/compliancestate.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
*/

import styled from 'styled-components';

import PropTypes from 'web/utils/proptypes';
import useTranslation from 'web/hooks/useTranslation';
import {styledExcludeProps} from 'web/utils/styledConfig';
import Theme from 'web/utils/theme';

const Label = styledExcludeProps(styled.div, [
'backgroundColor',
'borderColor',
])`
const Label = styled.div`
text-align: center;
font-weight: normal;
font-style: normal;
Expand All @@ -22,62 +18,32 @@ const Label = styledExcludeProps(styled.div, [
width: 70px;
height: 1.5em;
font-size: 0.8em;
background-color: ${props => props.backgroundColor};
border-color: ${props => props.borderColor};
background-color: ${props => props.$backgroundColor};
border-color: ${props => props.$borderColor};
`;


const YesLabel = props => {
const ComplianceLabel = ({text, color, ...props}) => {
const [_] = useTranslation();
return (
<Label
{...props}
backgroundColor={Theme.complianceYes}
borderColor={Theme.complianceYes}
$backgroundColor={Theme[color]}
$borderColor={Theme[color]}
>
{_('Yes')}
{_(text)}
</Label>
)
};

const NoLabel = props => {
const [_] = useTranslation();
return (
<Label
{...props}
backgroundColor={Theme.complianceNo}
borderColor={Theme.complianceNo}
>
{_('No')}
</Label>
)
ComplianceLabel.propTypes = {
text: PropTypes.string,
color: PropTypes.string,
};

const IncompleteLabel = props => {
const [_] = useTranslation();
return (
<Label
{...props}
backgroundColor={Theme.complianceIncomplete}
borderColor={Theme.complianceIncomplete}
>
{_('Incomplete')}
</Label>
)
};

const UndefinedLabel = props => {
const [_] = useTranslation();
return (
<Label
{...props}
backgroundColor={Theme.complianceUndefined}
borderColor={Theme.complianceUndefined}
>
{_('Undefined')}
</Label>
)
};
const YesLabel = props => <ComplianceLabel {...props} text="Yes" color="complianceYes" />;
const NoLabel = props => <ComplianceLabel {...props} text='No' color='complianceNo' />;
const IncompleteLabel = props => <ComplianceLabel {...props} text='Incomplete' color='complianceIncomplete' />;
const UndefinedLabel = props => <ComplianceLabel {...props} text='Undefined' color='complianceUndefined' />;

export const ComplianceStateLabels = {
Yes: YesLabel,
Expand All @@ -86,6 +52,4 @@ export const ComplianceStateLabels = {
Undefined: UndefinedLabel,
};

export default ComplianceStateLabels;

// vim: set ts=2 sw=2 tw=80:
export default ComplianceStateLabels;
26 changes: 12 additions & 14 deletions src/web/components/powerfilter/compliancelevelsgroup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,63 +28,63 @@ const ComplianceLevelsFilterGroup = ({
const [_] = useTranslation();

const handleComplianceChange = (value, level) => {
const filter_name = isResult
const filterName = isResult
? 'compliance_levels'
: 'report_compliance_levels';

let compliance = filter.get(filter_name);
let compliance = filter.get(filterName);

if (!compliance) {
compliance = '';
}

if (value && !compliance.includes(level)) {
compliance += level;
onChange(compliance, filter_name);
onChange(compliance, filterName);
} else if (!value && compliance.includes(level)) {
compliance = compliance.replace(level, '');

if (compliance.trim().length === 0) {
onRemove();
} else {
onChange(compliance, filter_name);
onChange(compliance, filterName);
}
}
};

let compliance_levels = filter.get(
let complianceLevels = filter.get(
isResult ? 'compliance_levels' : 'report_compliance_levels',
);

if (!isDefined(compliance_levels)) {
compliance_levels = '';
if (!isDefined(complianceLevels)) {
complianceLevels = '';
}
return (
<FormGroup title={_('Compliance')}>
<IconDivider>
<Checkbox
checked={compliance_levels.includes('y')}
checked={complianceLevels.includes('y')}
name="y"
onChange={handleComplianceChange}
>
<ComplianceStateLabels.Yes />
</Checkbox>
<Checkbox
checked={compliance_levels.includes('n')}
checked={complianceLevels.includes('n')}
name="n"
onChange={handleComplianceChange}
>
<ComplianceStateLabels.No />
</Checkbox>
<Checkbox
checked={compliance_levels.includes('i')}
checked={complianceLevels.includes('i')}
name="i"
onChange={handleComplianceChange}
>
<ComplianceStateLabels.Incomplete />
</Checkbox>
<Checkbox
checked={compliance_levels.includes('u')}
checked={complianceLevels.includes('u')}
name="u"
onChange={handleComplianceChange}
>
Expand All @@ -102,6 +102,4 @@ ComplianceLevelsFilterGroup.propTypes = {
onRemove: PropTypes.func.isRequired,
};

export default ComplianceLevelsFilterGroup;

// vim: set ts=2 sw=2 tw=80:
export default ComplianceLevelsFilterGroup;
1 change: 0 additions & 1 deletion src/web/entities/filterprovider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const FilterProvider = ({
fallbackFilter,
locationQueryFilterString: locationQuery?.filter,
});

return (
<React.Fragment>
{isLoadingFilter ? <Loading /> : children({filter: returnedFilter})}
Expand Down
4 changes: 0 additions & 4 deletions src/web/pages/reports/__mocks__/mockauditdeltareport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {setLocale} from 'gmp/locale/lang';

import AuditReport from 'gmp/models/auditreport';

setLocale('en');

// Task
const task1 = {
_id: '314',
Expand Down
4 changes: 0 additions & 4 deletions src/web/pages/reports/__mocks__/mockauditreport.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {setLocale} from 'gmp/locale/lang';

import AuditReport from 'gmp/models/auditreport';

setLocale('en');

// Task
const task1 = {
_id: '314',
Expand Down
3 changes: 0 additions & 3 deletions src/web/pages/reports/__tests__/auditdeltadetailspage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {describe, test, expect, testing} from '@gsa/testing';
import React from 'react';

import Capabilities from 'gmp/capabilities/capabilities';
import {setLocale} from 'gmp/locale/lang';

import Filter from 'gmp/models/filter';

Expand All @@ -19,8 +18,6 @@ import {getMockAuditDeltaReport} from 'web/pages/reports/__mocks__/mockauditdelt

import DeltaDetailsContent from 'web/pages/reports/deltadetailscontent';

setLocale('en');

const filter = Filter.fromString(
'apply_overrides=0 compliance_levels=ynui rows=10 min_qod=70 first=1 sort=compliant',
);
Expand Down
3 changes: 0 additions & 3 deletions src/web/pages/reports/__tests__/auditdetailscontent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {describe, test, expect, testing} from '@gsa/testing';
import React from 'react';

import Capabilities from 'gmp/capabilities/capabilities';
import {setLocale} from 'gmp/locale/lang';

import Filter from 'gmp/models/filter';

Expand All @@ -19,8 +18,6 @@ import {getMockAuditReport} from 'web/pages/reports/__mocks__/mockauditreport';

import DetailsContent from 'web/pages/reports/auditdetailscontent';

setLocale('en');

const filter = Filter.fromString(
'apply_overrides=0 compliance_levels=ynui rows=10 min_qod=70 first=1 sort=compliant',
);
Expand Down
3 changes: 0 additions & 3 deletions src/web/pages/reports/__tests__/auditfilterdialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import {describe, test, expect, testing} from '@gsa/testing';
import React from 'react';

import Capabilities from 'gmp/capabilities/capabilities';
import {setLocale} from 'gmp/locale/lang';

import Filter from 'gmp/models/filter';

import {rendererWith} from 'web/utils/testing';

import AuditReportFilter from 'web/pages/reports/auditfilterdialog';

setLocale('en');

const caps = new Capabilities(['everything']);

const manualUrl = 'test/';
Expand Down
4 changes: 0 additions & 4 deletions src/web/pages/reports/__tests__/auditreportslistpage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {describe, test, expect, testing} from '@gsa/testing';
import React from 'react';
import {act} from 'react-dom/test-utils';

import {setLocale} from 'gmp/locale/lang';

import CollectionCounts from 'gmp/collection/collectioncounts';

import Filter from 'gmp/models/filter';
Expand All @@ -22,8 +20,6 @@ import {rendererWith, waitFor, fireEvent} from 'web/utils/testing';
import {getMockAuditReport} from 'web/pages/reports/__mocks__/mockauditreport';
import AuditReportsPage from '../auditreportslistpage';

setLocale('en');

window.URL.createObjectURL = testing.fn();

const {entity} = getMockAuditReport();
Expand Down
3 changes: 0 additions & 3 deletions src/web/pages/reports/__tests__/detailsfilterdialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ import {describe, test, expect, testing} from '@gsa/testing';
import React from 'react';

import Capabilities from 'gmp/capabilities/capabilities';
import {setLocale} from 'gmp/locale/lang';

import Filter from 'gmp/models/filter';

import {rendererWith} from 'web/utils/testing';

import FilterDialog from 'web/pages/reports/detailsfilterdialog';

setLocale('en');

const caps = new Capabilities(['everything']);

const manualUrl = 'test/';
Expand Down
4 changes: 1 addition & 3 deletions src/web/pages/reports/auditdashboard/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ const AuditReportsDashboard = props => (
/>
);

export default AuditReportsDashboard;

// vim: set ts=2 sw=2 tw=80:
export default AuditReportsDashboard;
4 changes: 1 addition & 3 deletions src/web/pages/reports/auditdashboard/loaders.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ export const ReportCompianceLoader = ({children, filter}) => (
</Loader>
);

ReportCompianceLoader.propTypes = loaderPropTypes;

// vim: set ts=2 sw=2 tw=80:
ReportCompianceLoader.propTypes = loaderPropTypes;
4 changes: 1 addition & 3 deletions src/web/pages/reports/auditdashboard/statusdisplay.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,4 @@ registerDisplay(
{
title: _l('Table: Audit Reports by Compliance'),
},
);

// vim: set ts=2 sw=2 tw=80:
);
4 changes: 1 addition & 3 deletions src/web/pages/reports/auditdeltadetailspage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,4 @@ DeltaAuditReportDetailsWrapper.propTypes = {
export default compose(
withDialogNotification,
withDownload,
)(DeltaAuditReportDetailsWrapper);

// vim: set ts=2 sw=2 tw=80:
)(DeltaAuditReportDetailsWrapper);
Loading

0 comments on commit 2311adb

Please sign in to comment.