From 998b4ac50aa1afa6d19db938f34e2e35754a2b81 Mon Sep 17 00:00:00 2001 From: Paul D'Ambra Date: Sat, 14 Dec 2024 12:14:38 +0100 Subject: [PATCH] fix: no polling when hidden (#26912) --- .../e2e/insights-navigation-open-sql-insight-first.cy.ts | 3 +++ .../sidepanel/panels/activity/sidePanelActivityLogic.tsx | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cypress/e2e/insights-navigation-open-sql-insight-first.cy.ts b/cypress/e2e/insights-navigation-open-sql-insight-first.cy.ts index 85f472a09c97b..a902e861bacd6 100644 --- a/cypress/e2e/insights-navigation-open-sql-insight-first.cy.ts +++ b/cypress/e2e/insights-navigation-open-sql-insight-first.cy.ts @@ -56,6 +56,9 @@ describe('Insights', () => { it('can open a new stickiness insight', () => { insight.clickTab('STICKINESS') + // this test flaps, so check for a parent element, that is present even when failing + // in the hope that it slows the test down a little and stops it flapping + cy.get('.InsightVizDisplay--type-stickiness').should('exist') cy.get('.TrendsInsight canvas').should('exist') }) diff --git a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelActivityLogic.tsx b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelActivityLogic.tsx index 81b31df645706..244e42c52d936 100644 --- a/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelActivityLogic.tsx +++ b/frontend/src/layout/navigation-3000/sidepanel/panels/activity/sidePanelActivityLogic.tsx @@ -174,7 +174,7 @@ export const sidePanelActivityLogic = kea([ ], })), - listeners(({ values, actions }) => ({ + listeners(({ values, actions, cache }) => ({ setActiveTab: ({ tab }) => { if (tab === SidePanelActivityTab.All && !values.allActivityResponseLoading) { actions.loadAllActivity() @@ -191,6 +191,13 @@ export const sidePanelActivityLogic = kea([ actions.setActiveTab(options as SidePanelActivityTab) } }, + togglePolling: ({ pageIsVisible }) => { + if (pageIsVisible) { + actions.loadImportantChanges() + } else { + clearTimeout(cache.pollTimeout) + } + }, })), selectors({ allActivity: [