Skip to content

Commit

Permalink
Fix repeated request in groups-table (#5465)
Browse files Browse the repository at this point in the history
* Fix repeated request in groups-table

* Add changelog

* Add suggestion

(cherry picked from commit e4884fa)
  • Loading branch information
yenienserrano authored and github-actions[bot] committed May 29, 2023
1 parent 4029137 commit 4a149a9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Fixed the GitHub and Office 365 modules appear in the main menu when they were not configured [#5376](https://github.com/wazuh/wazuh-kibana-app/pull/5376)
- Fixed TypeError in FIM Inventory using new error handler [#5364](https://github.com/wazuh/wazuh-kibana-app/pull/5364)
- Fixed error when using invalid group configuration [#5423](https://github.com/wazuh/wazuh-kibana-app/pull/5423)
- Fixed repeated requests in the group table when adding a group or refreshing the table [#5465](https://github.com/wazuh/wazuh-kibana-app/pull/5465)

## Wazuh v4.4.3 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 00

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,19 @@ class WzGroupsTable extends Component {
}

async componentDidUpdate(prevProps, prevState) {
if (this.props.state.isProcessing && this._isMounted) {
await this.getItems();
}
const { filters } = this.state;
if (JSON.stringify(filters) !== JSON.stringify(prevState.filters)) {
if ((JSON.stringify(filters) !== JSON.stringify(prevState.filters)) ||
/**
Is verifying that isProcessing is true and that it has changed its value,
since in the shouldComponentUpdate it is making it re-execute several times
each time a state changes, regardless of whether it is a change in isProcessing.
*/
(
prevProps.state.isProcessing !== this.props.state.isProcessing &&
this.props.state.isProcessing &&
this._isMounted
)
) {
await this.getItems();
}
}
Expand All @@ -95,35 +103,37 @@ class WzGroupsTable extends Component {
* Loads the initial information
*/
async getItems() {
this.setState({ items: [], totalItems: 0 }, async () => {
try {
this.props.updateLoadingStatus(true);
const rawItems = await this.groupsHandler.listGroups({ params: this.buildFilter() });
const { affected_items, total_affected_items } = ((rawItems || {}).data || {}).data;
try {
this.props.updateLoadingStatus(true);
const rawItems = await this.groupsHandler.listGroups({ params: this.buildFilter() });
const {
affected_items: affectedItem,
total_affected_items: totalAffectedItem
} = rawItems?.data?.data;
this.setState({
items: affectedItem,
totalItems: totalAffectedItem,
});
this.props.updateLoadingStatus(false);
this.props.state.isProcessing && this.props.updateIsProcessing(false);

} catch (error) {
this.props.updateLoadingStatus(false);
this.props.state.isProcessing && this.props.updateIsProcessing(false);
const options = {
context: `${WzGroupsTable.name}.getItems`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.CRITICAL,
store: true,
error: {
error: error,
message: error.message || error,
title: `Error getting groups`,
},
};
getErrorOrchestrator().handleError(options);
}

this.setState({
items: affected_items,
totalItems: total_affected_items,
});
this.props.updateLoadingStatus(false);
this.props.state.isProcessing && this.props.updateIsProcessing(false);
} catch (error) {
this.props.updateLoadingStatus(false);
this.props.state.isProcessing && this.props.updateIsProcessing(false);
const options = {
context: `${WzGroupsTable.name}.getItems`,
level: UI_LOGGER_LEVELS.ERROR,
severity: UI_ERROR_SEVERITIES.CRITICAL,
store: true,
error: {
error: error,
message: error.message || error,
title: `Error getting groups`,
},
};
getErrorOrchestrator().handleError(options);
}
});
}

buildFilter() {
Expand Down

0 comments on commit 4a149a9

Please sign in to comment.