Alerting: fix moment when rule list navigation is tracked (#68663)

* Track rule list navigation only on page load

* update tests

* Fix lint

---------

Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
This commit is contained in:
Virginia Cepeda 2023-05-22 14:26:20 -03:00 committed by GitHub
parent d54fa569ec
commit 1763b82b5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -41,6 +41,7 @@ jest.mock('./api/ruler');
jest.mock('../../../core/hooks/useMediaQueryChange'); jest.mock('../../../core/hooks/useMediaQueryChange');
jest.spyOn(ruleActionButtons, 'matchesWidth').mockReturnValue(false); jest.spyOn(ruleActionButtons, 'matchesWidth').mockReturnValue(false);
jest.mock('app/core/core', () => ({ jest.mock('app/core/core', () => ({
...jest.requireActual('app/core/core'),
appEvents: { appEvents: {
subscribe: () => { subscribe: () => {
return { unsubscribe: () => {} }; return { unsubscribe: () => {} };

View File

@ -76,11 +76,14 @@ const RuleList = withErrorBoundary(
// Trigger data refresh only when the RULE_LIST_POLL_INTERVAL_MS elapsed since the previous load FINISHED // Trigger data refresh only when the RULE_LIST_POLL_INTERVAL_MS elapsed since the previous load FINISHED
const [_, fetchRules] = useAsyncFn(async () => { const [_, fetchRules] = useAsyncFn(async () => {
if (!loading) { if (!loading) {
trackRuleListNavigation();
await dispatch(fetchAllPromAndRulerRulesAction(false, { limitAlerts })); await dispatch(fetchAllPromAndRulerRulesAction(false, { limitAlerts }));
} }
}, [loading, limitAlerts, dispatch]); }, [loading, limitAlerts, dispatch]);
useEffect(() => {
trackRuleListNavigation().catch(() => {});
}, []);
// fetch rules, then poll every RULE_LIST_POLL_INTERVAL_MS // fetch rules, then poll every RULE_LIST_POLL_INTERVAL_MS
useEffect(() => { useEffect(() => {
dispatch(fetchAllPromAndRulerRulesAction(false, { limitAlerts })); dispatch(fetchAllPromAndRulerRulesAction(false, { limitAlerts }));