logs: restrict permalinks to datasources with id fields (#71729)

* logs: restrict permalinks to datasources with id fields

* simplified code

* more tests

* more test

* removed unnecessary comment

* fixed tests

* updated tests
This commit is contained in:
Gábor Farkas
2023-07-17 15:01:48 +02:00
committed by GitHub
parent ab58466d09
commit d0351bac57
7 changed files with 192 additions and 9 deletions

View File

@@ -102,7 +102,7 @@ export const LogRowMenuCell = React.memo(
aria-label="Pin line"
/>
)}
{onPermalinkClick && row.uid && (
{onPermalinkClick && row.rowId !== undefined && row.uid && (
<IconButton
tooltip="Copy shortlink"
aria-label="Copy shortlink"

View File

@@ -66,12 +66,18 @@ describe('LogRowMessage', () => {
});
describe('with permalinking', () => {
it('should show permalinking button when `onPermalinkClick` is defined', async () => {
setup({ onPermalinkClick: jest.fn() });
it('should show permalinking button when `onPermalinkClick` is defined and rowId is defined', async () => {
setup({ onPermalinkClick: jest.fn() }, { rowId: 'id1' });
await userEvent.hover(screen.getByText('test123'));
expect(screen.queryByLabelText('Copy shortlink')).toBeInTheDocument();
});
it('should not show permalinking button when `onPermalinkClick` is defined and rowId is not defined', async () => {
setup({ onPermalinkClick: jest.fn() });
await userEvent.hover(screen.getByText('test123'));
expect(screen.queryByLabelText('Copy shortlink')).not.toBeInTheDocument();
});
it('should not show permalinking button when `onPermalinkClick` is not defined', () => {
setup();
expect(screen.queryByLabelText('Copy shortlink')).not.toBeInTheDocument();
@@ -79,7 +85,7 @@ describe('LogRowMessage', () => {
it('should call `onPermalinkClick` with row on click', async () => {
const permalinkClick = jest.fn();
const props = setup({ onPermalinkClick: permalinkClick });
const props = setup({ onPermalinkClick: permalinkClick }, { rowId: 'id1' });
await userEvent.hover(screen.getByText('test123'));
const button = screen.getByLabelText('Copy shortlink');