Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Logs: Add permalink to log lines (#69464)
* create explore panel state for logs * add props to LogRows and unify * pass properties from explore to logs * add css * implement button and scrolling * export and use `getUrlStateFromPaneState` * make `scrollIntoView` optional * change state handling for permalinks * change link icon * removed unused state * add tests for `LogRowMessage` * remove unused prop * fix name * reorg component * add `LogRow` tests * add test for `Logs` * Update public/app/features/logs/components/LogRow.test.tsx Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> * Update public/app/features/explore/Logs/Logs.test.tsx Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> * improve types in test * fix props export in Logs.tsx * fix props export in LogRowMessage.tsx * fix props export in LogRow.tsx * fixed import * fix theme import * remove hidden style * add better test names * change to `log line` rather logline Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> * fix tooltips * remove unused css --------- Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
- Loading branch information
1 parent
4bbf35d
commit ae63c67
Showing
12 changed files
with
419 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import React, { ComponentProps } from 'react'; | ||
import tinycolor from 'tinycolor2'; | ||
|
||
import { CoreApp, createTheme, LogLevel, LogRowModel } from '@grafana/data'; | ||
|
||
import { LogRow } from './LogRow'; | ||
import { createLogRow } from './__mocks__/logRow'; | ||
import { getLogRowStyles } from './getLogRowStyles'; | ||
|
||
const theme = createTheme(); | ||
const styles = getLogRowStyles(theme); | ||
const setup = (propOverrides?: Partial<ComponentProps<typeof LogRow>>, rowOverrides?: Partial<LogRowModel>) => { | ||
const props: ComponentProps<typeof LogRow> = { | ||
row: createLogRow({ | ||
entry: 'test123', | ||
uid: 'log-row-id', | ||
logLevel: LogLevel.error, | ||
timeEpochMs: 1546297200000, | ||
...rowOverrides, | ||
}), | ||
enableLogDetails: false, | ||
getRows: () => [], | ||
onOpenContext: () => {}, | ||
prettifyLogMessage: false, | ||
app: CoreApp.Explore, | ||
showDuplicates: false, | ||
showLabels: false, | ||
showTime: false, | ||
wrapLogMessage: false, | ||
timeZone: 'utc', | ||
styles, | ||
...(propOverrides || {}), | ||
}; | ||
|
||
const { container } = render( | ||
<table> | ||
<tbody> | ||
<LogRow {...props} /> | ||
</tbody> | ||
</table> | ||
); | ||
|
||
return { props, container }; | ||
}; | ||
|
||
describe('LogRow', () => { | ||
it('renders row entry', () => { | ||
setup(); | ||
expect(screen.queryByText('test123')).toBeInTheDocument(); | ||
}); | ||
|
||
describe('with permalinking', () => { | ||
it('highlights row with same permalink-id', () => { | ||
const { container } = setup({ permalinkedRowId: 'log-row-id' }); | ||
const row = container.querySelector('tr'); | ||
expect(row).toHaveStyle( | ||
`background-color: ${tinycolor(theme.colors.info.transparent).setAlpha(0.25).toString()}` | ||
); | ||
}); | ||
|
||
it('does not highlight row details with different permalink-id', async () => { | ||
const { container } = setup({ permalinkedRowId: 'log-row-id', enableLogDetails: true }); | ||
const row = container.querySelector('tr'); | ||
await userEvent.click(row!); | ||
const allRows = container.querySelectorAll('tr'); | ||
|
||
expect(row).toHaveStyle( | ||
`background-color: ${tinycolor(theme.colors.info.transparent).setAlpha(0.25).toString()}` | ||
); | ||
expect(allRows[allRows.length - 1]).not.toHaveStyle( | ||
`background-color: ${tinycolor(theme.colors.info.transparent).setAlpha(0.25).toString()}` | ||
); | ||
}); | ||
|
||
it('not highlights row with different permalink-id', () => { | ||
const { container } = setup({ permalinkedRowId: 'wrong-log-row-id' }); | ||
const row = container.querySelector('tr'); | ||
expect(row).not.toHaveStyle( | ||
`background-color: ${tinycolor(theme.colors.info.transparent).setAlpha(0.25).toString()}` | ||
); | ||
}); | ||
|
||
it('calls `scrollIntoView` if permalink matches', () => { | ||
const scrollIntoView = jest.fn(); | ||
setup({ permalinkedRowId: 'log-row-id', scrollIntoView }); | ||
expect(scrollIntoView).toHaveBeenCalled(); | ||
}); | ||
|
||
it('not calls `scrollIntoView` if permalink does not match', () => { | ||
const scrollIntoView = jest.fn(); | ||
setup({ permalinkedRowId: 'wrong-log-row-id', scrollIntoView }); | ||
expect(scrollIntoView).not.toHaveBeenCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.