Skip to content

Commit

Permalink
Apply review remarks
Browse files Browse the repository at this point in the history
- Rewrite auditdeltadetailspage, auditdetailspage, auditreportlistpage,
  compliancelevelsgroup into functional components.
- Use camel case instead of snake case
- Use absolute imports without .js suffix
  • Loading branch information
a-h-abdelsalam committed Mar 4, 2024
1 parent 811e5a9 commit 83a22c9
Show file tree
Hide file tree
Showing 33 changed files with 1,010 additions and 1,252 deletions.
2 changes: 1 addition & 1 deletion public/locales/gsa-de.json
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,7 @@
"Include log messages in your filter settings.": "Log-Nachrichten in die Filtereinstellungen einbeziehen.",
"Include report": "Bericht einfügen",
"Included": "Beinhaltet",
"Incomplete": "Inkomplett",
"Incomplete": "Unvollständig",
"Info": "Info",
"Information": "Informationen",
"Inheriting user": "Erbender Benutzer",
Expand Down
8 changes: 4 additions & 4 deletions src/gmp/commands/__tests__/auditreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {createHttp, createEntityResponse} from '../testing';
import {AuditReportCommand} from '../auditreports';
import {createHttp, createEntityResponse} from 'gmp/commands/testing';
import {AuditReportCommand} from 'gmp/commands/auditreports';

describe('ReportCommand tests', () => {
test('should request single report', () => {
describe('AuditReportCommand tests', () => {
test('should request single audit report', () => {
const response = createEntityResponse('report', {_id: 'foo'});
const fakeHttp = createHttp(response);

Expand Down
2 changes: 1 addition & 1 deletion src/gmp/commands/__tests__/auditreports.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
createEntitiesResponse,
createAggregatesResponse,
} from '../testing';
import {AuditReportsCommand} from '../auditreports';
import {AuditReportsCommand} from 'gmp/commands/auditreports';

describe('AuditReportsCommand tests', () => {
test('should return all audit reports', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/gmp/models/auditreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class AuditReport extends Model {
copy.report = AuditReportReport.fromElement(report);
}

copy.report_format = parseModelFromElement(report_format, 'reportformat');
copy.reportFormat = parseModelFromElement(report_format, 'reportformat');
copy.task = parseModelFromElement(task, 'task');

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

copy.scan_start = parseDate(scan_start);
copy.timestamp = parseDate(timestamp);
Expand Down
55 changes: 45 additions & 10 deletions src/gmp/models/report/auditreport.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import {isDefined} from '../../utils/identity';
import {isEmpty} from '../../utils/string';
import {isDefined} from 'gmp/utils/identity';
import {isEmpty} from 'gmp/utils/string';

import {parseDate} from '../../parser';
import {parseDate} from 'gmp/parser';

import {parseFilter} from '../../collection/parser';
import {parseFilter} from 'gmp/collection/parser';

import Model from '../../model';
import Model from 'gmp/model';

import ReportTask from './task';

Expand All @@ -44,14 +44,24 @@ class AuditReportReport extends Model {
static parseElement(element) {
const copy = super.parseElement(element);

const {delta, compliance, scan_start, scan_end, task, scan, timestamp} =
element;
const {
delta,
compliance,
compliance_count,
scan_start,
scan_end,
task,
scan,
timestamp,
} = element;

const filter = parseFilter(element);

copy.filter = filter;

copy.report_type = element._type;
copy.reportType = element._type;

// copy.scanRunStatus = element.scan_run_status;

delete copy.filters;

Expand All @@ -62,6 +72,31 @@ class AuditReportReport extends Model {
};
}

if (isDefined(compliance_count)) {
copy.complianceCounts = {
filtered: parseInt(compliance_count.filtered),
full: parseInt(compliance_count.full),
incomplete: {
filtered: parseInt(compliance_count.incomplete.filtered),
full: parseInt(compliance_count.incomplete.full),
},
no: {
filtered: parseInt(compliance_count.no.filtered),
full: parseInt(compliance_count.no.full),
},
undefined: {
filtered: parseInt(compliance_count.undefined.filtered),
full: parseInt(compliance_count.undefined.full),
},
yes: {
filtered: parseInt(compliance_count.yes.filtered),
full: parseInt(compliance_count.yes.full),
},
};
}

delete copy.compliance_count;

copy.task = ReportTask.fromElement(task);

copy.results = parseResults(element, filter);
Expand All @@ -72,7 +107,7 @@ class AuditReportReport extends Model {

delete copy.host;

copy.operatingsystems = parseOperatingSystems(element, filter);
copy.operatingSystems = parseOperatingSystems(element, filter);

copy.errors = parse_errors(element, filter);

Expand Down Expand Up @@ -112,7 +147,7 @@ class AuditReportReport extends Model {
}

isDeltaReport() {
return this.report_type === 'delta';
return this.reportType === 'delta';
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/gmp/models/report/host.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class Host {
warning: 0,
total: 0,
};
this.compliance_counts = {
this.complianceCounts = {
yes: 0,
no: 0,
incomplete: 0,
Expand All @@ -77,10 +77,12 @@ class Host {
host_compliance,
} = element;

copy.host_compliance = isDefined(host_compliance)
copy.hostCompliance = isDefined(host_compliance)
? host_compliance
: 'undefined';

delete copy.host_compliance;

if (isEmpty(asset._asset_id)) {
delete copy.asset;
} else {
Expand Down Expand Up @@ -111,15 +113,15 @@ class Host {
}

if (isDefined(compliance_count)) {
copy.compliance_counts = {
copy.complianceCounts = {
yes: parse_page_count(compliance_count.yes),
no: parse_page_count(compliance_count.no),
incomplete: parse_page_count(compliance_count.incomplete),
undefined: parse_page_count(compliance_count.undefined),
total: parse_page_count(compliance_count),
};
} else {
copy.compliance_counts = {
copy.complianceCounts = {
yes: 0,
no: 0,
incomplete: 0,
Expand Down
14 changes: 7 additions & 7 deletions src/web/components/bar/compliancebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,24 @@ import React from 'react';

import {isDefined} from 'gmp/utils/identity';

import PropTypes from '../../utils/proptypes.js';
import Theme from 'web/utils/theme.js';
import PropTypes from 'web/utils/proptypes';
import Theme from 'web/utils/theme';

import ProgressBar from './progressbar.js';
import ProgressBar from './progressbar';
import {getTranslatableReportCompliance} from 'gmp/models/auditreport';

const ComplianceBar = ({compliance, toolTip}) => {
const title = getTranslatableReportCompliance(compliance);

let background;
if (compliance === 'no') {
background = Theme.compliance_no;
background = Theme.complianceNo;
} else if (compliance === 'incomplete') {
background = Theme.compliance_incomplete;
background = Theme.complianceIncomplete;
} else if (compliance === 'yes') {
background = Theme.compliance_yes;
background = Theme.complianceYes;
} else {
background = Theme.compliance_undefined;
background = Theme.complianceUndefined;
}

const toolTipText = isDefined(toolTip) ? toolTip : title;
Expand Down
84 changes: 37 additions & 47 deletions src/web/components/label/compliancestate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';

import styled from 'styled-components';

import _ from 'gmp/locale';
import {styledExcludeProps} from 'web/utils/styledConfig';
import Theme from 'web/utils/theme.js';
import Theme from 'web/utils/theme';

const Label = styledExcludeProps(styled.div, [
'backgroundColor',
Expand All @@ -40,53 +38,45 @@ const Label = styledExcludeProps(styled.div, [
border-color: ${props => props.borderColor};
`;

const YesLabel = props => {
return (
<Label
{...props}
backgroundColor={Theme.compliance_yes}
borderColor={Theme.compliance_yes}
>
{_('Yes')}
</Label>
);
};
const YesLabel = props => (
<Label
{...props}
backgroundColor={Theme.complianceYes}
borderColor={Theme.complianceYes}
>
{_('Yes')}
</Label>
);

const NoLabel = props => {
return (
<Label
{...props}
backgroundColor={Theme.compliance_no}
borderColor={Theme.compliance_no}
>
{_('No')}
</Label>
);
};
const NoLabel = props => (
<Label
{...props}
backgroundColor={Theme.complianceNo}
borderColor={Theme.complianceNo}
>
{_('No')}
</Label>
);

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

const UndefinedLabel = props => {
return (
<Label
{...props}
backgroundColor={Theme.compliance_undefined}
borderColor={Theme.compliance_undefined}
>
{_('Undefined')}
</Label>
);
};
const UndefinedLabel = props => (
<Label
{...props}
backgroundColor={Theme.complianceUndefined}
borderColor={Theme.complianceUndefined}
>
{_('Undefined')}
</Label>
);

export const ComplianceStateLabels = {
Yes: YesLabel,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React from 'react';

import {render, fireEvent} from 'web/utils/testing';

import ComplianceLevelsFilterGroup from '../compliancelevelsgroup';
import ComplianceLevelsFilterGroup from 'web/components/powerfilter/compliancelevelsgroup';

import Filter from 'gmp/models/filter';

Expand Down
Loading

0 comments on commit 83a22c9

Please sign in to comment.