Improved rule display: merged warnings and dangers are displayed the same, added sorting

This commit is contained in:
VakarisZ 2020-09-24 17:09:45 +03:00
parent 5bc47b91cf
commit 9f74d9abef
2 changed files with 52 additions and 23 deletions

View File

@ -2,8 +2,9 @@ import React, {useState} from 'react';
import {Modal} from 'react-bootstrap';
import * as PropTypes from 'prop-types';
import Pluralize from 'pluralize';
import ScoutSuiteSingleRuleDropdown from './ScoutSuiteSingleRuleDropdown';
import ScoutSuiteSingleRuleDropdown, {getRuleStatus} from './ScoutSuiteSingleRuleDropdown';
import '../../../../styles/components/scoutsuite/RuleModal.scss';
import STATUSES from '../../common/consts/StatusConsts';
export default function ScoutSuiteRuleModal(props) {
@ -17,9 +18,36 @@ export default function ScoutSuiteRuleModal(props) {
}
}
function compareRules(firstRule, secondRule) {
let firstStatus = getRuleStatus(firstRule);
let secondStatus = getRuleStatus(secondRule);
return compareRuleStatuses(firstStatus, secondStatus);
}
function compareRuleStatuses(ruleStatusOne, ruleStatusTwo) {
if (ruleStatusOne === ruleStatusTwo) {
return 0;
} else if (ruleStatusOne === STATUSES.STATUS_FAILED) {
return -1;
} else if (ruleStatusTwo === STATUSES.STATUS_FAILED) {
return 1;
} else if (ruleStatusOne === STATUSES.STATUS_VERIFY) {
return -1;
} else if (ruleStatusTwo === STATUSES.STATUS_VERIFY) {
return 1;
} else if (ruleStatusOne === STATUSES.STATUS_PASSED) {
return -1;
} else if (ruleStatusTwo === STATUSES.STATUS_PASSED) {
return 1;
}
}
function renderRuleDropdowns() {
let dropdowns = [];
props.scoutsuite_rules.forEach(rule => {
let rules = props.scoutsuite_rules;
rules.sort(compareRules);
rules.forEach(rule => {
let dropdown = (<ScoutSuiteSingleRuleDropdown isCollapseOpen={openRuleId === rule.description}
toggleCallback={() => toggleRuleDropdown(rule.description)}
rule={rule}

View File

@ -8,7 +8,7 @@ import classNames from 'classnames';
import * as PropTypes from 'prop-types';
import RULE_LEVELS from '../../common/consts/ScoutSuiteConsts/RuleLevels';
import STATUSES from '../../common/consts/StatusConsts';
import {faCheckCircle, faCircle, faExclamationCircle, faQuestionCircle} from '@fortawesome/free-solid-svg-icons';
import {faCheckCircle, faCircle, faExclamationCircle} from '@fortawesome/free-solid-svg-icons';
import RuleDisplay from './RuleDisplay';
export default function ScoutSuiteSingleRuleDropdown(props) {
@ -20,7 +20,7 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
<button className={classNames('btn-collapse', getDropdownClass())}
onClick={props.toggleCallback}>
<span>
<FontAwesomeIcon icon={getRuleIcon()} />
<FontAwesomeIcon icon={getRuleIcon()}/>
{props.rule.description}
</span>
<span>
@ -36,12 +36,12 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
}
function getRuleIcon() {
let ruleStatus = getRuleStatus()
switch(ruleStatus) {
let ruleStatus = getRuleStatus(props.rule);
switch (ruleStatus) {
case STATUSES.STATUS_PASSED:
return faCheckCircle;
case STATUSES.STATUS_VERIFY:
return faQuestionCircle;
return faExclamationCircle;
case STATUSES.STATUS_FAILED:
return faExclamationCircle;
case STATUSES.STATUS_UNEXECUTED:
@ -49,13 +49,13 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
}
}
function getDropdownClass(){
let ruleStatus = getRuleStatus()
switch(ruleStatus) {
function getDropdownClass() {
let ruleStatus = getRuleStatus(props.rule);
switch (ruleStatus) {
case STATUSES.STATUS_PASSED:
return "collapse-success";
case STATUSES.STATUS_VERIFY:
return "collapse-warning";
return "collapse-danger";
case STATUSES.STATUS_FAILED:
return "collapse-danger";
case STATUSES.STATUS_UNEXECUTED:
@ -63,18 +63,6 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
}
}
function getRuleStatus(){
if(props.rule.checked_items === 0) {
return STATUSES.STATUS_UNEXECUTED
} else if (props.rule.items.length === 0) {
return STATUSES.STATUS_PASSED
} else if (props.rule.level === RULE_LEVELS.LEVEL_WARNING) {
return STATUSES.STATUS_VERIFY
} else {
return STATUSES.STATUS_FAILED
}
}
function renderRule() {
return <RuleDisplay rule={props.rule} scoutsuite_data={props.scoutsuite_data}/>
}
@ -82,6 +70,19 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
return getRuleCollapse();
}
export function getRuleStatus(rule) {
if (rule.checked_items.length === 0) {
return STATUSES.STATUS_UNEXECUTED
} else if (rule.items.length === 0) {
return STATUSES.STATUS_PASSED
} else if (rule.level === RULE_LEVELS.LEVEL_WARNING) {
return STATUSES.STATUS_VERIFY
} else {
return STATUSES.STATUS_FAILED
}
}
ScoutSuiteSingleRuleDropdown.propTypes = {
isCollapseOpen: PropTypes.bool,
rule: PropTypes.object,