LogRow: ensure scrollIntoView is called only once with shortlinks (#72291)

This commit is contained in:
Matias Chomicki 2023-07-25 18:00:10 +02:00 committed by GitHub
parent b71117393b
commit ec5650cc82
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 5 deletions

View File

@ -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 () => {

View File

@ -143,11 +143,11 @@ class UnThemedLogRow extends PureComponent<Props, State> {
return;
}
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);
}
if (!this.state.highlightBackround) {
reportInteraction('grafana_explore_logs_permalink_opened', {
datasourceType: row.datasourceType ?? 'unknown',
logRowUid: row.uid,