Extracted execution status function to reduce code duplication

This commit is contained in:
Shay Nehmad 2019-08-19 15:57:48 +03:00
parent c4805b70e2
commit 2fa2c04940
5 changed files with 15 additions and 17 deletions

View File

@ -18,6 +18,7 @@ import ReportLoader from "../report-components/common/ReportLoader";
import MustRunMonkeyWarning from "../report-components/common/MustRunMonkeyWarning";
import {SecurityIssuesGlance} from "../report-components/common/SecurityIssuesGlance";
import PrintReportButton from "../report-components/common/PrintReportButton";
import {extractExecutionStatusFromServerResponse} from "../report-components/common/ExecutionStatus";
let guardicoreLogoImage = require('../../images/guardicore-logo.png');
@ -97,11 +98,7 @@ class ReportPageComponent extends AuthComponent {
return this.authFetch('/api')
.then(res => res.json())
.then(res => {
// This check is used to prevent unnecessary re-rendering
this.setState({
allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']),
runStarted: res['completed_steps']['run_monkey']
});
this.setState(extractExecutionStatusFromServerResponse(res));
return res;
});
};
@ -134,10 +131,8 @@ class ReportPageComponent extends AuthComponent {
let content;
if (this.stillLoadingDataFromServer()) {
console.log("still loading?: " + this.stillLoadingDataFromServer());
content = <ReportLoader loading={true}/>;
} else {
console.log("not still loading: " + this.stillLoadingDataFromServer());
content =
<div>
{this.generateReportOverviewSection()}

View File

@ -1,5 +1,5 @@
import React, {Fragment} from 'react';
import {Button, Col, Row, Grid} from 'react-bootstrap';
import {Col, Grid, Row} from 'react-bootstrap';
import AuthComponent from '../AuthComponent';
import ReportHeader, {ReportTypes} from "../report-components/common/ReportHeader";
import PillarsOverview from "../report-components/zerotrust/PillarOverview";
@ -11,6 +11,7 @@ import MustRunMonkeyWarning from "../report-components/common/MustRunMonkeyWarni
import {SecurityIssuesGlance} from "../report-components/common/SecurityIssuesGlance";
import {StatusesToPillarsSummary} from "../report-components/zerotrust/StatusesToPillarsSummary";
import PrintReportButton from "../report-components/common/PrintReportButton";
import {extractExecutionStatusFromServerResponse} from "../report-components/common/ExecutionStatus";
class ZeroTrustReportPageComponent extends AuthComponent {
@ -31,10 +32,7 @@ class ZeroTrustReportPageComponent extends AuthComponent {
return this.authFetch('/api')
.then(res => res.json())
.then(res => {
this.setState({
allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']),
runStarted: res['completed_steps']['run_monkey']
});
this.setState(extractExecutionStatusFromServerResponse(res));
return res;
});
};

View File

@ -0,0 +1,6 @@
export function extractExecutionStatusFromServerResponse(res) {
return {
allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']),
runStarted: res['completed_steps']['run_monkey']
};
}

View File

@ -17,6 +17,7 @@ import T1082 from "../../attack/techniques/T1082";
import T1145 from "../../attack/techniques/T1145";
import T1107 from "../../attack/techniques/T1107";
import T1065 from "../../attack/techniques/T1065";
import {extractExecutionStatusFromServerResponse} from "../common/ExecutionStatus";
const tech_components = {
'T1210': T1210,
@ -54,11 +55,7 @@ class AttackReportPageComponent extends AuthComponent {
return this.authFetch('/api')
.then(res => res.json())
.then(res => {
// This check is used to prevent unnecessary re-rendering
this.setState({
allMonkeysAreDead: (!res['completed_steps']['run_monkey']) || (res['completed_steps']['infection_done']),
runStarted: res['completed_steps']['run_monkey']
});
this.setState(extractExecutionStatusFromServerResponse(res));
return res;
});
};

View File

@ -19,6 +19,8 @@ const columns = [
class PillarOverview extends Component {
pillarsToStatuses;
grades;
render() {
const data = this.props.grades.map((grade) => {
const newGrade = grade;