Skip to content

Commit 0e8ff28

Browse files
[Security solution][Alerts] Fix alerts page controls (elastic#236756)
## Summary Fixes elastic#231286 ## πŸ›‘ Problem overview As explained in the linked ticket above, there is a bug on the alert's page controls (the filters on top of the page). Basically, after the user re-orders and edits the available controls (e.g. removes a field) and then tries to reset the controls, some of the controls gets duplicated. It doesn't happens always, but only with a specific combination of edits. The one described in the ticket is: - move the "status" control to the end - delete the "user" control - save, then reset the controls The result of this is a duplicated "host" control where the "user" control should be. ## πŸ’‘ Solution The issue appear to lie on the reset callback. In this callback there's a loop that goes through the `initialControls`, which are the ones displayed by default before any user modification. In this loop, a new "controls state" get generated, but somehow the code also calls `controlGroup?.updateInput(newInput);` on every loop. This doesn't make sense, as we are building the state and we want to set it only once we have it all. Moving `controlGroup?.updateInput(newInput);` outside of the loop seems to have solve the issue. ## πŸ’­ To keep in mind I myself don't fully understand why this fix is working. I tried to deep dive into the `controlGroup` APIs but it was too deep a rabbit hole for me to follow Also, this PR seems to be fixing also another related bug: elastic#226987 --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent 7ff3b05 commit 0e8ff28

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

β€Žsrc/platform/packages/shared/kbn-alerts-ui-shared/src/alert_filter_controls/context_menu.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export const FilterGroupContextMenu = () => {
7070
},
7171
String(counter)
7272
);
73-
controlGroup?.updateInput(newInput);
7473
}
74+
controlGroup?.updateInput(newInput);
7575

7676
switchToViewMode();
7777
setShowFiltersChangedBanner(false);

β€Žsrc/platform/packages/shared/kbn-alerts-ui-shared/src/alert_filter_controls/filter_group.test.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ describe(' Filter Group Component ', () => {
471471
fireEvent.click(screen.getByTestId(TEST_IDS.CONTEXT_MENU.RESET));
472472

473473
// blanks the input
474-
await waitFor(() => expect(controlGroupMock.updateInput.mock.calls.length).toBe(5));
474+
await waitFor(() => expect(controlGroupMock.updateInput.mock.calls.length).toBe(1));
475475
});
476476

477477
it('should restore controls saved in local storage', async () => {

0 commit comments

Comments
Β (0)