Skip to content

Commit

Permalink
Fix pagination in SCA checks table when expanding some row (#3018)
Browse files Browse the repository at this point in the history
* fix(frontend): Fix pagination in SCA checks table when expand some row
  • Loading branch information
Desvelao authored Mar 1, 2021
1 parent 375d2f1 commit 20499ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ All notable changes to the Wazuh app project will be documented in this file.
### Fixed

- Fix SCA policy detail showing name and check results about another policy [#3007](https://github.com/wazuh/wazuh-kibana-app/pull/3007)
- Fix pagination in SCA checks table when expand some row [#3018](https://github.com/wazuh/wazuh-kibana-app/pull/3018)

## Wazuh v4.1.1 - Kibana 7.10.0 , 7.10.2 - Revision 4102

Expand Down
38 changes: 19 additions & 19 deletions public/components/agents/sca/inventory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ import exportCsv from '../../../react-services/wz-csv';
import { getToasts } from '../../../kibana-services';
import { WzSearchBar } from '../../../components/wz-search-bar';
import { RuleText, ComplianceText } from './components';
import _ from 'lodash';

export class Inventory extends Component {
_isMount = false;
constructor(props) {
super(props);
const { agent } = this.props;
this.state = { agent, items: [], itemIdToExpandedRowMap: {}, showMoreInfo: false, loading: false, filters: [] }
this.state = { agent, items: [], itemIdToExpandedRowMap: {}, showMoreInfo: false, loading: false, filters: [], pageTableChecks: {pageIndex: 0} }
this.policies = [];
this.suggestions = {};
this.columnsPolicies = [
Expand Down Expand Up @@ -169,8 +170,11 @@ export class Inventory extends Component {
}

async componentDidUpdate(prevProps, prevState) {
if (JSON.stringify(this.props.agent) !== JSON.stringify(prevProps.agent)) {
if (!_.isEqual(this.props.agent, prevProps.agent)) {
this.setState({ lookingPolicy: false }, async () => await this.initialize());
};
if(!_.isEqual(this.state.filters, prevState.filters)){
this.setState({itemIdToExpandedRowMap: {}, pageTableChecks: {pageIndex: 0, pageSize: this.state.pageTableChecks.pageSize}});
}
}

Expand Down Expand Up @@ -259,7 +263,7 @@ export class Inventory extends Component {
}

async loadScaPolicy(policy) {
this._isMount && this.setState({ loadingPolicy: true, itemIdToExpandedRowMap: {}, pageIndex: 0 });
this._isMount && this.setState({ loadingPolicy: true, itemIdToExpandedRowMap: {}, pageTableChecks: {pageIndex: 0} });
if (policy) {
try {
const policyResponse = await WzRequest.apiReq(
Expand Down Expand Up @@ -311,25 +315,16 @@ export class Inventory extends Component {
toggleDetails = item => {
const itemIdToExpandedRowMap = { ...this.state.itemIdToExpandedRowMap };

item.complianceText = '';
if (item.compliance && item.compliance.length) {
item.compliance.forEach(x => {
item.complianceText += `${x.key}: ${x.value}\n`;
});
}
if (item.rules.length) {
item.rulesText = '';
item.rules.forEach(x => {
item.rulesText += `${x.rule}\n`;
});
}

if (itemIdToExpandedRowMap[item.id]) {
delete itemIdToExpandedRowMap[item.id];
} else {
let checks = '';
checks += (item.rules || []).length > 1 ? 'Checks' : 'Check';
checks += item.condition ? ` (Condition: ${item.condition})` : '';
const complianceText = item.compliance && item.compliance.length
? item.compliance.map(el => `${el.key}: ${el.value}`).join('\n')
: '';
const rulesText = item.rules.length ? item.rules.map(el => el.rule).join('\n') : '';
const listItems = [
{
title: 'Check not applicable due to:',
Expand All @@ -353,11 +348,11 @@ export class Inventory extends Component {
},
{
title: checks,
description: <RuleText rulesText={item.rulesText} />,
description: <RuleText rulesText={rulesText} />,
},
{
title: 'Compliance',
description: <ComplianceText complianceText={item.complianceText} />
description: <ComplianceText complianceText={complianceText} />
}
];
const itemsToShow = listItems.filter(x => {
Expand Down Expand Up @@ -394,6 +389,10 @@ export class Inventory extends Component {
return <button onClick={() => this.setState({ filters: [{ field, value }] })}>{text}</button>
}

onChangeTableChecks({ page: {index: pageIndex, size: pageSize} }){
this.setState({ pageTableChecks: {pageIndex, pageSize} });
}

render() {
const getPoliciesRowProps = (item, idx) => {
return {
Expand Down Expand Up @@ -565,8 +564,9 @@ export class Inventory extends Component {
itemIdToExpandedRowMap={this.state.itemIdToExpandedRowMap}
isExpandable={true}
sorting={sorting}
pagination={true}
pagination={this.state.pageTableChecks}
loading={this.state.loadingPolicy}
onTableChange={(change) => this.onChangeTableChecks(change)}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down

0 comments on commit 20499ac

Please sign in to comment.