Improved rule display: merged warnings and dangers are displayed the same, added sorting
This commit is contained in:
parent
5bc47b91cf
commit
9f74d9abef
|
@ -2,8 +2,9 @@ import React, {useState} from 'react';
|
||||||
import {Modal} from 'react-bootstrap';
|
import {Modal} from 'react-bootstrap';
|
||||||
import * as PropTypes from 'prop-types';
|
import * as PropTypes from 'prop-types';
|
||||||
import Pluralize from 'pluralize';
|
import Pluralize from 'pluralize';
|
||||||
import ScoutSuiteSingleRuleDropdown from './ScoutSuiteSingleRuleDropdown';
|
import ScoutSuiteSingleRuleDropdown, {getRuleStatus} from './ScoutSuiteSingleRuleDropdown';
|
||||||
import '../../../../styles/components/scoutsuite/RuleModal.scss';
|
import '../../../../styles/components/scoutsuite/RuleModal.scss';
|
||||||
|
import STATUSES from '../../common/consts/StatusConsts';
|
||||||
|
|
||||||
|
|
||||||
export default function ScoutSuiteRuleModal(props) {
|
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() {
|
function renderRuleDropdowns() {
|
||||||
let dropdowns = [];
|
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}
|
let dropdown = (<ScoutSuiteSingleRuleDropdown isCollapseOpen={openRuleId === rule.description}
|
||||||
toggleCallback={() => toggleRuleDropdown(rule.description)}
|
toggleCallback={() => toggleRuleDropdown(rule.description)}
|
||||||
rule={rule}
|
rule={rule}
|
||||||
|
|
|
@ -8,7 +8,7 @@ import classNames from 'classnames';
|
||||||
import * as PropTypes from 'prop-types';
|
import * as PropTypes from 'prop-types';
|
||||||
import RULE_LEVELS from '../../common/consts/ScoutSuiteConsts/RuleLevels';
|
import RULE_LEVELS from '../../common/consts/ScoutSuiteConsts/RuleLevels';
|
||||||
import STATUSES from '../../common/consts/StatusConsts';
|
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';
|
import RuleDisplay from './RuleDisplay';
|
||||||
|
|
||||||
export default function ScoutSuiteSingleRuleDropdown(props) {
|
export default function ScoutSuiteSingleRuleDropdown(props) {
|
||||||
|
@ -20,7 +20,7 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
|
||||||
<button className={classNames('btn-collapse', getDropdownClass())}
|
<button className={classNames('btn-collapse', getDropdownClass())}
|
||||||
onClick={props.toggleCallback}>
|
onClick={props.toggleCallback}>
|
||||||
<span>
|
<span>
|
||||||
<FontAwesomeIcon icon={getRuleIcon()} />
|
<FontAwesomeIcon icon={getRuleIcon()}/>
|
||||||
{props.rule.description}
|
{props.rule.description}
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
|
@ -36,12 +36,12 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getRuleIcon() {
|
function getRuleIcon() {
|
||||||
let ruleStatus = getRuleStatus()
|
let ruleStatus = getRuleStatus(props.rule);
|
||||||
switch(ruleStatus) {
|
switch (ruleStatus) {
|
||||||
case STATUSES.STATUS_PASSED:
|
case STATUSES.STATUS_PASSED:
|
||||||
return faCheckCircle;
|
return faCheckCircle;
|
||||||
case STATUSES.STATUS_VERIFY:
|
case STATUSES.STATUS_VERIFY:
|
||||||
return faQuestionCircle;
|
return faExclamationCircle;
|
||||||
case STATUSES.STATUS_FAILED:
|
case STATUSES.STATUS_FAILED:
|
||||||
return faExclamationCircle;
|
return faExclamationCircle;
|
||||||
case STATUSES.STATUS_UNEXECUTED:
|
case STATUSES.STATUS_UNEXECUTED:
|
||||||
|
@ -49,13 +49,13 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDropdownClass(){
|
function getDropdownClass() {
|
||||||
let ruleStatus = getRuleStatus()
|
let ruleStatus = getRuleStatus(props.rule);
|
||||||
switch(ruleStatus) {
|
switch (ruleStatus) {
|
||||||
case STATUSES.STATUS_PASSED:
|
case STATUSES.STATUS_PASSED:
|
||||||
return "collapse-success";
|
return "collapse-success";
|
||||||
case STATUSES.STATUS_VERIFY:
|
case STATUSES.STATUS_VERIFY:
|
||||||
return "collapse-warning";
|
return "collapse-danger";
|
||||||
case STATUSES.STATUS_FAILED:
|
case STATUSES.STATUS_FAILED:
|
||||||
return "collapse-danger";
|
return "collapse-danger";
|
||||||
case STATUSES.STATUS_UNEXECUTED:
|
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() {
|
function renderRule() {
|
||||||
return <RuleDisplay rule={props.rule} scoutsuite_data={props.scoutsuite_data}/>
|
return <RuleDisplay rule={props.rule} scoutsuite_data={props.scoutsuite_data}/>
|
||||||
}
|
}
|
||||||
|
@ -82,6 +70,19 @@ export default function ScoutSuiteSingleRuleDropdown(props) {
|
||||||
return getRuleCollapse();
|
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 = {
|
ScoutSuiteSingleRuleDropdown.propTypes = {
|
||||||
isCollapseOpen: PropTypes.bool,
|
isCollapseOpen: PropTypes.bool,
|
||||||
rule: PropTypes.object,
|
rule: PropTypes.object,
|
||||||
|
|
Loading…
Reference in New Issue