Skip to content

Commit

Permalink
Fix merge deleted files
Browse files Browse the repository at this point in the history
  • Loading branch information
juankaromo committed Apr 27, 2020
1 parent 9ee13eb commit e22bf32
Show file tree
Hide file tree
Showing 2 changed files with 276 additions and 95 deletions.
138 changes: 43 additions & 95 deletions public/components/agents/sca/states.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,8 @@
import React, { Component, Fragment } from 'react';
import { Pie } from "../../d3/pie";
import {
EuiFlexItem,
EuiFlexGroup,
EuiPanel,
EuiPage,
EuiBasicTable,
EuiInMemoryTable,
EuiSpacer,
EuiText,
EuiProgress,
EuiTitle,
EuiButton,
EuiButtonIcon,
EuiStat,
EuiHealth,
EuiDescriptionList,
EuiButtonEmpty,
EuiToolTip,
EuiCallOut
EuiFlexItem, EuiFlexGroup, EuiPanel, EuiPage, EuiBasicTable, EuiInMemoryTable, EuiSpacer, EuiText, EuiProgress,
EuiTitle, EuiButton, EuiButtonIcon, EuiStat, EuiHealth, EuiDescriptionList, EuiButtonEmpty, EuiToolTip, EuiCallOut
} from '@elastic/eui';
import { WzRequest } from '../../../react-services/wz-request';
import TimeService from '../../../react-services/time-service'
Expand All @@ -42,13 +26,13 @@ export class States extends Component {
{
field: 'description',
name: 'Description',
truncateText: true
truncateText: true,
},
{
field: 'end_scan',
name: 'Last scan',
dataType: 'date',
render: value => this.offsetTimestamp('', value)
render: value => this.offsetTimestamp('', value),
},
{
field: 'pass',
Expand Down Expand Up @@ -85,38 +69,21 @@ export class States extends Component {
field: 'title',
name: 'Title',
sortable: true,
truncateText: true
truncateText: true,
},
{
name: 'Target',
truncateText: true,
render: item => (
<div>
{item.file ? (
<span>
<b>File:</b> {item.file}
</span>
) : item.directory ? (
<span>
<b>Directory:</b> {item.directory}
</span>
) : item.process ? (
<span>
<b>Process: </b> {item.process}
</span>
) : item.command ? (
<span>
<b>Command: </b> {item.command}
</span>
) : item.registry ? (
<span>
<b>Registry: </b> {item.registry}
</span>
) : (
'-'
)}
{item.file ? <span><b>File:</b> {item.file}</span>
: item.directory ? <span><b>Directory:</b> {item.directory}</span>
: item.process ? <span><b>Process: </b> {item.process}</span>
: item.command ? <span><b>Command: </b> {item.command}</span>
: item.registry ? <span><b>Registry: </b> {item.registry}</span>
: '-'}
</div>
)
),
},
{
field: 'result',
Expand All @@ -133,17 +100,11 @@ export class States extends Component {
render: item => (
<EuiButtonIcon
onClick={() => this.toggleDetails(item)}
aria-label={
this.state.itemIdToExpandedRowMap[item.id] ? 'Collapse' : 'Expand'
}
iconType={
this.state.itemIdToExpandedRowMap[item.id]
? 'arrowUp'
: 'arrowDown'
}
aria-label={this.state.itemIdToExpandedRowMap[item.id] ? 'Collapse' : 'Expand'}
iconType={this.state.itemIdToExpandedRowMap[item.id] ? 'arrowUp' : 'arrowDown'}
/>
)
}
),
},
];
}

Expand All @@ -165,7 +126,7 @@ export class States extends Component {
}

addHealthResultRender(result) {
const color = result => {
const color = (result) => {
if (result.toLowerCase() === 'passed') {
return 'success';
} else if (result.toLowerCase() === 'failed') {
Expand All @@ -186,26 +147,19 @@ export class States extends Component {
try {
this._isMount && this.setState({ loading: true });
this.lookingPolicy = false;
const policies = await this.wzReq.apiReq(
'GET',
`/sca/${this.state.agent.id}`,
{}
);
const policies = await this.wzReq.apiReq('GET', `/sca/${this.state.agent.id}`, {});
this.policies = (((policies || {}).data || {}).data || {}).items || [];
const models = [];
for (let i = 0; i < this.policies.length; i++) {
models.push({
name: this.policies[i].name,
status: [
{ id: 'pass', label: 'Pass', value: this.policies[i].pass },
{ id: 'fail', label: 'Fail', value: this.policies[i].fail },
{
id: 'invalid',
label: 'Not applicable',
value: this.policies[i].invalid
}
]
});
name: this.policies[i].name, status:
[
{ id: 'pass', label: "Pass", value: this.policies[i].pass },
{ id: 'fail', label: "Fail", value: this.policies[i].fail },
{ id: 'invalid', label: "Not applicable", value: this.policies[i].invalid },
]
}
)
}
this._isMount && this.setState({ data: models, loading: false });
} catch (error) {
Expand All @@ -216,11 +170,7 @@ export class States extends Component {
async loadScaPolicy(policy) {
this._isMount && this.setState({ loadingPolicy: true, itemIdToExpandedRowMap: {}, pageIndex: 0 });
if (policy) {
const checks = await this.wzReq.apiReq(
'GET',
`/sca/${this.state.agent.id}/checks/${policy.policy_id}`,
{}
);
const checks = await this.wzReq.apiReq('GET', `/sca/${this.state.agent.id}/checks/${policy.policy_id}`, {});
this.checks = (((checks || {}).data || {}).data || {}).items || [];
}
this._isMount && this.setState({ lookingPolicy: policy, loadingPolicy: false });
Expand All @@ -232,14 +182,14 @@ export class States extends Component {
if (item.compliance.length) {
item.complianceText = '';
item.compliance.forEach(x => {
item.complianceText += `${x.key}: ${x.value}\n`;
});
item.complianceText += `${x.key}: ${x.value}\n`
})
}
if (item.rules.length) {
item.rulesText = '';
item.rules.forEach(x => {
item.rulesText += `${x.rule}\n`;
});
item.rulesText += `${x.rule}\n`
})
}

if (itemIdToExpandedRowMap[item.id]) {
Expand All @@ -251,36 +201,34 @@ export class States extends Component {
const listItems = [
{
title: 'Check not applicable due to:',
description: item.reason
description: item.reason,
},
{
title: 'Rationale',
description: item.rationale,
},
{
title: 'Remediation',
description: item.remediation
description: item.remediation,
},
{
title: 'Description',
description: item.description
description: item.description,
},
{
title: (item.directory || '').includes(',') ? 'Paths' : 'Path',
description: item.directory
description: item.directory,
},
{
title: checks,
description: item.rulesText,
},
{
title: 'Compliance',
description: item.complianceText
description: item.complianceText,
}
];
const itemsToShow = listItems.filter(x => {
return x.description;
});
const itemsToShow = listItems.filter(x => { return x.description });
itemIdToExpandedRowMap[item.id] = (
<EuiDescriptionList listItems={itemsToShow} />
);
Expand Down Expand Up @@ -313,21 +261,21 @@ export class States extends Component {
return {
'data-test-subj': `sca-row-${idx}`,
className: 'customRowClass',
onClick: () => this.loadScaPolicy(item)
onClick: () => this.loadScaPolicy(item),
};
};
const getChecksRowProps = (item, idx) => {
return {
'data-test-subj': `sca-check-row-${idx}`,
className: 'customRowClass',
onClick: () => this.toggleDetails(item)
onClick: () => this.toggleDetails(item),
};
};
const pagination = {
pageIndex: this.state.pageIndex,
pageSize: 10,
totalItemCount: (this.checks || []).length,
pageSizeOptions: [10, 25, 50, 100]
pageSizeOptions: [10, 25, 50, 100],
};

const search = {
Expand All @@ -339,8 +287,8 @@ export class States extends Component {
const sorting = {
sort: {
field: 'id',
direction: 'asc'
}
direction: 'asc',
},
};

return (
Expand Down Expand Up @@ -484,4 +432,4 @@ export class States extends Component {
</Fragment>
);
}
}
}
Loading

0 comments on commit e22bf32

Please sign in to comment.