diff --git a/CHANGELOG.md b/CHANGELOG.md index 78e5a1cb6f..7047374e96 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/public/controllers/management/components/management/groups/groups-table.js b/public/controllers/management/components/management/groups/groups-table.js index 5d34286d73..421fcbe1ad 100644 --- a/public/controllers/management/components/management/groups/groups-table.js +++ b/public/controllers/management/components/management/groups/groups-table.js @@ -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(); } } @@ -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() {