Skip to content

Commit 8767cb7

Browse files
authored
[9.1] [ResponseOps][Alerts] Fix alerts table pagination resetting when lastReloadRequestTime is used (#242275) (#242563)
# Backport This will backport the following commits from `main` to `9.1`: - [[ResponseOps][Alerts] Fix alerts table pagination resetting when lastReloadRequestTime is used (#242275)](#242275) <!--- Backport version: 10.1.0 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Umberto Pepato","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-11-11T11:44:29Z","message":"[ResponseOps][Alerts] Fix alerts table pagination resetting when lastReloadRequestTime is used (#242275)\n\n## 📄 Summary\n\nRemoves the `refresh` callback from the `lastReloadRequestTime` effect\ndependencies to avoid triggering a refresh when the refresh callback\nitself changes (like it happened\n[here](https://github.com/elastic/kibana/issues/241593)).\n\n<details>\n<summary>\n\n## 🧪 Verification steps\n\n</summary>\n\n1. Create a rule that fires many alerts (i.e. Security query rule)\n2. Wait for the alerts to be generated\n3. Navigate to the rule page from Stack Management > Rules\n4. Check that the pagination in the alerts table at the bottom of the\npage works correctly\n\n</details>\n\n## ⏪ Backport rationale\n\nBackporting to all open versions since this is a bug fix\n\n## Release Notes\n\nFixes a bug that caused the alerts tables pagination to be stuck in the\nRule pages\n\n## 🔗 References\n\nFixes #241593\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] ~~Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~~\n- [ ]\n~~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials~~\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] ~~If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~~\n- [ ] ~~This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.~~\n- [ ] ~~[Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed~~\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"722c33eb42562a86412be79e745ea4702f36a6d7","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Team:ResponseOps","backport:version","v9.3.0","v8.19.7","v9.1.7","v9.2.1"],"title":"[ResponseOps][Alerts] Fix alerts table pagination resetting when lastReloadRequestTime is used","number":242275,"url":"https://github.com/elastic/kibana/pull/242275","mergeCommit":{"message":"[ResponseOps][Alerts] Fix alerts table pagination resetting when lastReloadRequestTime is used (#242275)\n\n## 📄 Summary\n\nRemoves the `refresh` callback from the `lastReloadRequestTime` effect\ndependencies to avoid triggering a refresh when the refresh callback\nitself changes (like it happened\n[here](https://github.com/elastic/kibana/issues/241593)).\n\n<details>\n<summary>\n\n## 🧪 Verification steps\n\n</summary>\n\n1. Create a rule that fires many alerts (i.e. Security query rule)\n2. Wait for the alerts to be generated\n3. Navigate to the rule page from Stack Management > Rules\n4. Check that the pagination in the alerts table at the bottom of the\npage works correctly\n\n</details>\n\n## ⏪ Backport rationale\n\nBackporting to all open versions since this is a bug fix\n\n## Release Notes\n\nFixes a bug that caused the alerts tables pagination to be stuck in the\nRule pages\n\n## 🔗 References\n\nFixes #241593\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] ~~Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~~\n- [ ]\n~~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials~~\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] ~~If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~~\n- [ ] ~~This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.~~\n- [ ] ~~[Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed~~\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"722c33eb42562a86412be79e745ea4702f36a6d7"}},"sourceBranch":"main","suggestedTargetBranches":["8.19","9.1"],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/242275","number":242275,"mergeCommit":{"message":"[ResponseOps][Alerts] Fix alerts table pagination resetting when lastReloadRequestTime is used (#242275)\n\n## 📄 Summary\n\nRemoves the `refresh` callback from the `lastReloadRequestTime` effect\ndependencies to avoid triggering a refresh when the refresh callback\nitself changes (like it happened\n[here](https://github.com/elastic/kibana/issues/241593)).\n\n<details>\n<summary>\n\n## 🧪 Verification steps\n\n</summary>\n\n1. Create a rule that fires many alerts (i.e. Security query rule)\n2. Wait for the alerts to be generated\n3. Navigate to the rule page from Stack Management > Rules\n4. Check that the pagination in the alerts table at the bottom of the\npage works correctly\n\n</details>\n\n## ⏪ Backport rationale\n\nBackporting to all open versions since this is a bug fix\n\n## Release Notes\n\nFixes a bug that caused the alerts tables pagination to be stuck in the\nRule pages\n\n## 🔗 References\n\nFixes #241593\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n\n- [ ] ~~Any text added follows [EUI's writing\nguidelines](https://elastic.github.io/eui/#/guidelines/writing), uses\nsentence case text and includes [i18n\nsupport](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)~~\n- [ ]\n~~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\nwas added for features that require explanation or tutorials~~\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [ ] ~~If a plugin configuration key changed, check if it needs to be\nallowlisted in the cloud and added to the [docker\nlist](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~~\n- [ ] ~~This was checked for breaking HTTP API changes, and any breaking\nchanges have been approved by the breaking-change committee. The\n`release_note:breaking` label should be applied in these situations.~~\n- [ ] ~~[Flaky Test\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was\nused on any tests changed~~\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n- [x] Review the [backport\nguidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing)\nand apply applicable `backport:*` labels.\n\n---------\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"722c33eb42562a86412be79e745ea4702f36a6d7"}},{"branch":"8.19","label":"v8.19.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.1","label":"v9.1.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"9.2","label":"v9.2.1","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/242527","number":242527,"state":"MERGED","mergeCommit":{"sha":"11cbc3a21cad0cf26355a31a92e02343a0ca76e0","message":"[9.2] [ResponseOps][Alerts] Fix alerts table pagination resetting when lastReloadRequestTime is used (#242275) (#242527)\n\n# Backport\n\nThis will backport the following commits from `main` to `9.2`:\n- [[ResponseOps][Alerts] Fix alerts table pagination resetting when\nlastReloadRequestTime is used\n(#242275)](https://github.com/elastic/kibana/pull/242275)\n\n\n\n### Questions ?\nPlease refer to the [Backport tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by: Umberto Pepato <[email protected]>\nCo-authored-by: Elastic Machine <[email protected]>"}}]}] BACKPORT-->
1 parent 9b14657 commit 8767cb7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/platform/packages/shared/response-ops/alerts-table/components/alerts_table.test.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,15 @@ describe('AlertsTable', () => {
337337
let onToggleColumn: AlertsDataGridProps['onToggleColumn'];
338338
let onResetColumns: AlertsDataGridProps['onResetColumns'];
339339
let refresh: RenderContext<AdditionalContext>['refresh'];
340+
let refreshSpy: jest.SpyInstance<void, []>;
340341

341342
mockAlertsDataGrid.mockImplementation((props) => {
342343
const { AlertsDataGrid: ActualAlertsDataGrid } = jest.requireActual('./alerts_data_grid');
343344
onChangePageIndex = props.onChangePageIndex;
344345
onToggleColumn = props.onToggleColumn;
345346
onResetColumns = props.onResetColumns;
346347
refresh = props.renderContext.refresh;
348+
refreshSpy = jest.spyOn(props.renderContext, 'refresh');
347349
return <ActualAlertsDataGrid {...props} />;
348350
});
349351

@@ -1210,5 +1212,17 @@ describe('AlertsTable', () => {
12101212
});
12111213
expect(mockSearchAlerts).toHaveBeenLastCalledWith(expect.objectContaining({ pageIndex: 0 }));
12121214
});
1215+
1216+
it("doesn't call `refresh` when paginating and using `lastReloadRequestTime`", async () => {
1217+
render(<AlertsTable {...tableProps} lastReloadRequestTime={Date.now()} />);
1218+
1219+
await waitFor(() => expect(onChangePageIndex).not.toBeUndefined());
1220+
1221+
act(() => {
1222+
onChangePageIndex(1);
1223+
});
1224+
1225+
expect(refreshSpy).not.toHaveBeenCalled();
1226+
});
12131227
});
12141228
});

src/platform/packages/shared/response-ops/alerts-table/components/alerts_table.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,9 @@ const AlertsTableContent = typedForwardRef(
434434
if (lastReloadRequestTime) {
435435
refresh();
436436
}
437-
}, [lastReloadRequestTime, refresh]);
437+
// Purposefully not including `refresh` to avoid refreshing when it changes
438+
// eslint-disable-next-line react-hooks/exhaustive-deps
439+
}, [lastReloadRequestTime]);
438440

439441
useImperativeHandle(ref, () => ({
440442
refresh,

0 commit comments

Comments
 (0)