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 Apr 4, 2024
1 parent 40dbe2c commit b474908
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 54 deletions.
11 changes: 6 additions & 5 deletions src/web/components/powerfilter/compliancelevelsgroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ import IconDivider from 'web/components/layout/icondivider';

import ComplianceStateLabels from 'web/components/label/compliancestate';

const ComplianceLevelsFilterGroup = props => {
const ComplianceLevelsFilterGroup = ({
filter,
onChange,
onRemove,
isResult = false,
}) => {
const handleComplianceChange = (value, level) => {
const {filter, onChange, onRemove, isResult = false} = props;

const filter_name = isResult
? 'compliance_levels'
: 'report_compliance_levels';
Expand All @@ -59,8 +62,6 @@ const ComplianceLevelsFilterGroup = props => {
}
};

const {filter, isResult} = props;

let compliance_levels = filter.get(
isResult ? 'compliance_levels' : 'report_compliance_levels',
);
Expand Down
2 changes: 1 addition & 1 deletion src/web/pages/reports/__tests__/auditreportslistpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ describe('AuditReportsPage tests', () => {
const selects = getAllByTestId('select-selected-value');

// Toolbar Icons
expect(icons[0]).toHaveAttribute('title', 'Help: Reports');
expect(icons[0]).toHaveAttribute('title', 'Help: Audit Reports');

// Powerfilter
expect(inputs[0]).toHaveAttribute('name', 'userFilterString');
Expand Down
17 changes: 6 additions & 11 deletions src/web/pages/reports/auditdeltadetailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,16 @@ const getTarget = (entity = {}) => {
return task.target;
};

const getFilter = (entity = {}) => {
const {report = {}} = entity;
return report.filter;
};

const DeltaAuditReportDetails = props => {
const [activeTab, setActiveTab] = useState(0);
const [showFilterDialog, setShowFilterDialog] = useState(false);
const [showDownloadReportDialog, setShowDownloadReportDialog] =
useState(false);
const [reportFormatId, setReportFormatId] = useState(undefined);
const [reportFormatId, setReportFormatId] = useState();
const [isUpdating, setIsUpdating] = useState(false);
// storeAsDefault is set in SaveDialogContent
// eslint-disable-next-line no-unused-vars
const [storeAsDefault, setStoreAsDefault] = useState(undefined);
const [storeAsDefault, setStoreAsDefault] = useState();

const [sorting, setSorting] = useState({
results: {
Expand Down Expand Up @@ -181,10 +176,10 @@ const DeltaAuditReportDetails = props => {
// instead of just showing x is undefined JS stacktrace
const noReportFormatError = _(
'The report cannot be displayed because' +
' no Greenbone Vulnerability Manager report format is available.' +
' no report format is available.' +
' This could be due to a missing gvmd data feed. Please update' +
' the gvmd data feed, check the "feed import owner" setting, or' +
' contact your system administrator.',
' the gvmd data feed, check the "feed import owner" setting, the' +
' feed status page, or contact your system administrator.',
);
throw new Error(noReportFormatError);
}
Expand Down Expand Up @@ -521,7 +516,7 @@ const DeltaAuditReportDetailsWrapper = ({defaultFilter, ...props}) => {
const {id: reportId, deltaid: deltaReportId} = match.params;
const deltaSel = useSelector(deltaAuditReportSelector, shallowEqual);
const entity = deltaSel.getEntity(reportId, deltaReportId);
const reportFilter = getFilter(entity);
const reportFilter = entity?.report?.filter;

return (
<Reload
Expand Down
32 changes: 13 additions & 19 deletions src/web/pages/reports/auditdetailspage.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,6 @@ const getTarget = (entity = {}) => {
return task.target;
};

const getFilter = (entity = {}) => {
const {report = {}} = entity;
return report.filter;
};

const ReportDetails = props => {
const [activeTab, setActiveTab] = useState(0);
const [showFilterDialog, setShowFilterDialog] = useState(false);
Expand Down Expand Up @@ -142,19 +137,18 @@ const ReportDetails = props => {
},
});

const [entity, setEntity] = useState(undefined);
const [resultsCounts, setResultsCounts] = useState(undefined);
const [hostsCounts, setHostsCounts] = useState(undefined);
const [operatingSystemsCounts, setOperatingSystemsCounts] =
useState(undefined);
const [tlsCertificatesCounts, setTlsCertificatesCounts] = useState(undefined);
const [reportFormatId, setReportFormatId] = useState(undefined);
const [errorsCounts, setErrorsCounts] = useState(undefined);
const [reportFilter, setReportFilter] = useState(undefined);
const [entity, setEntity] = useState();
const [resultsCounts, setResultsCounts] = useState();
const [hostsCounts, setHostsCounts] = useState();
const [operatingSystemsCounts, setOperatingSystemsCounts] = useState();
const [tlsCertificatesCounts, setTlsCertificatesCounts] = useState();
const [reportFormatId, setReportFormatId] = useState();
const [errorsCounts, setErrorsCounts] = useState();
const [reportFilter, setReportFilter] = useState();
const [isUpdating, setIsUpdating] = useState(false);
// storeAsDefault is set in SaveDialogContent
// eslint-disable-next-line no-unused-vars
const [storeAsDefault, setStoreAsDefault] = useState(undefined);
const [storeAsDefault, setStoreAsDefault] = useState();

const gmp = useGmp();
const dispatch = useDispatch();
Expand Down Expand Up @@ -240,10 +234,10 @@ const ReportDetails = props => {
// instead of just showing x is undefined JS stacktrace
const noReportFormatError = _(
'The report cannot be displayed because' +
' no Greenbone Vulnerability Manager report format is available.' +
' no report format is available.' +
' This could be due to a missing gvmd data feed. Please update' +
' the gvmd data feed, check the "feed import owner" setting, or' +
' contact your system administrator.',
' the gvmd data feed, check the "feed import owner" setting, the' +
' feed status page, or contact your system administrator.',
);
throw new Error(noReportFormatError);
}
Expand Down Expand Up @@ -657,7 +651,7 @@ const ReportDetailsWrapper = props => {

const pageFilter = pSelector.getFilter(getReportPageName(reportId));
const entity = reportSel.getEntity(reportId, pageFilter);
const reportFilter = getFilter(entity);
const reportFilter = entity?.report?.filter;

return (
<FilterProvider
Expand Down
39 changes: 21 additions & 18 deletions src/web/pages/reports/auditreportslistpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import {

import compose from 'web/utils/compose';
import PropTypes from 'web/utils/proptypes';
import withGmp from 'web/utils/withGmp';

import AuditFilterDialog from './auditfilterdialog';
import AuditReportsTable from './auditreportstable';
Expand All @@ -64,32 +63,35 @@ const ToolBarIcons = () => (
<IconDivider>
<ManualIcon
page="reports"
anchor="using-and-managing-reports"
title={_('Help: Reports')}
anchor="using-and-managing-audit-reports"
title={_('Help: Audit Reports')}
/>
</IconDivider>
);

const AuditReportsPage = props => {
const [selectedDeltaReport, setSelectedDeltaReport] = useState(undefined);
const [beforeSelectFilter, setBeforeSelectFilter] = useState(undefined);
const AuditReportsPage = ({
filter,
onFilterChanged,
onInteraction,
onDelete,
...props
}) => {
const [selectedDeltaReport, setSelectedDeltaReport] = useState();
const [beforeSelectFilter, setBeforeSelectFilter] = useState();
const history = useHistory();

useEffect(() => {
if (
isDefined(selectedDeltaReport) &&
(!isDefined(props.filter) ||
props.filter.get('task_id') !== selectedDeltaReport.task.id)
(!isDefined(filter) ||
filter.get('task_id') !== selectedDeltaReport.task.id)
) {
// filter has changed. reset delta report selection
setSelectedDeltaReport(undefined);
setSelectedDeltaReport();
}
}, [props.filter, selectedDeltaReport]);
}, [filter, selectedDeltaReport]);

const handleReportDeleteClick = report => {
const {onDelete} = props;
return onDelete(report);
};
const handleReportDeleteClick = onDelete;

const handleReportDeltaSelect = report => {
if (isDefined(selectedDeltaReport)) {
Expand All @@ -99,7 +101,9 @@ const AuditReportsPage = props => {
'/auditreport/delta/' + selectedDeltaReport.id + '/' + report.id,
);
} else {
const {filter = new Filter()} = props;
if (!isDefined(filter)) {
filter = new Filter();
}

onFilterChanged(
filter
Expand All @@ -112,7 +116,6 @@ const AuditReportsPage = props => {
}
};

const {filter, onFilterChanged, onInteraction} = props;
return (
<React.Fragment>
<PageTitle title={_('Audit Reports')} />
Expand All @@ -138,6 +141,8 @@ const AuditReportsPage = props => {
toolBarIcons={ToolBarIcons}
title={_('Audit Reports')}
sectionIcon={<ReportIcon size="large" />}
filter={filter}
onFilterChanged={onFilterChanged}
onInteraction={onInteraction}
onReportDeltaSelect={handleReportDeltaSelect}
onReportDeleteClick={handleReportDeleteClick}
Expand All @@ -148,7 +153,6 @@ const AuditReportsPage = props => {

AuditReportsPage.propTypes = {
filter: PropTypes.filter,
gmp: PropTypes.gmp.isRequired,
history: PropTypes.object.isRequired,
onChanged: PropTypes.func.isRequired,
onDelete: PropTypes.func.isRequired,
Expand All @@ -167,7 +171,6 @@ const FALLBACK_AUDIT_REPORT_LIST_FILTER = Filter.fromString(
);

export default compose(
withGmp,
withEntitiesContainer('auditreport', {
fallbackFilter: FALLBACK_AUDIT_REPORT_LIST_FILTER,
entitiesSelector,
Expand Down

0 comments on commit b474908

Please sign in to comment.