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 repeated request in groups-table #5465

Merged
merged 4 commits into from
May 29, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,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 - OpenSearch Dashboards 2.6.0 - Revision 01

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