From ec5650cc82552dc87fb179a5fadfd596e54b03e4 Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Tue, 25 Jul 2023 18:00:10 +0200 Subject: [PATCH] LogRow: ensure scrollIntoView is called only once with shortlinks (#72291) --- public/app/features/logs/components/LogRow.test.tsx | 10 +++++++++- public/app/features/logs/components/LogRow.tsx | 8 ++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/public/app/features/logs/components/LogRow.test.tsx b/public/app/features/logs/components/LogRow.test.tsx index 60be5c483a0..fc48b6ef55a 100644 --- a/public/app/features/logs/components/LogRow.test.tsx +++ b/public/app/features/logs/components/LogRow.test.tsx @@ -66,6 +66,7 @@ describe('LogRow', () => { logRowUid: 'log-row-id', datasourceType: 'unknown', }); + expect(scrollIntoView).toHaveBeenCalledTimes(1); }); it('highlights row with same permalink-id', () => { @@ -104,11 +105,18 @@ describe('LogRow', () => { expect(scrollIntoView).toHaveBeenCalled(); }); - it('not calls `scrollIntoView` if permalink does not match', () => { + it('does not call `scrollIntoView` if permalink does not match', () => { const scrollIntoView = jest.fn(); setup({ permalinkedRowId: 'wrong-log-row-id', scrollIntoView }); expect(scrollIntoView).not.toHaveBeenCalled(); }); + + it('calls `scrollIntoView` once', async () => { + const scrollIntoView = jest.fn(); + setup({ permalinkedRowId: 'log-row-id', scrollIntoView }); + await userEvent.hover(screen.getByText('test123')); + expect(scrollIntoView).toHaveBeenCalledTimes(1); + }); }); it('should render the menu cell on mouse over', async () => { diff --git a/public/app/features/logs/components/LogRow.tsx b/public/app/features/logs/components/LogRow.tsx index 90c28510c64..3a38064dc50 100644 --- a/public/app/features/logs/components/LogRow.tsx +++ b/public/app/features/logs/components/LogRow.tsx @@ -143,11 +143,11 @@ class UnThemedLogRow extends PureComponent { return; } - // at this point this row is the permalinked row, so we need to scroll to it and highlight it if possible. - if (this.logLineRef.current && scrollIntoView) { - scrollIntoView(this.logLineRef.current); - } if (!this.state.highlightBackround) { + // at this point this row is the permalinked row, so we need to scroll to it and highlight it if possible. + if (this.logLineRef.current && scrollIntoView) { + scrollIntoView(this.logLineRef.current); + } reportInteraction('grafana_explore_logs_permalink_opened', { datasourceType: row.datasourceType ?? 'unknown', logRowUid: row.uid,