Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination in SCA checks table when expanding some row #3018

Merged
merged 3 commits into from
Mar 1, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to the Wazuh app project will be documented in this file.

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

### Fixed

- 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

### Added
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)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

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 @@ -307,25 +311,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 @@ -349,11 +344,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 @@ -390,6 +385,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 @@ -561,8 +560,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