Skip to content

Commit

Permalink
fix(TitleColumn): Use react router Link
Browse files Browse the repository at this point in the history
InsightsLink is not fully working in scenarios where the Link is in another applications.
  • Loading branch information
bastilian committed Nov 23, 2023
1 parent 228d183 commit 0664aba
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/components/InventoryTable/TitleColumn.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable react/prop-types */
import React from 'react';
import Link from '@redhat-cloud-services/frontend-components/InsightsLink';
import { Link } from 'react-router-dom';

/**
* Helper function to proprly calculate what to do when user clicks on first cell.
Expand Down Expand Up @@ -39,9 +39,8 @@ const TitleColumn = ({ children, id, item, ...props }) => (
children
) : (
<Link
to={item?.href || id}
to={item?.href || item?.to || id}
{...{
...(!item?.href ? { app: 'inventory' } : {}),
...(props?.onRowClick
? {
onClick: (event) => {
Expand Down
12 changes: 11 additions & 1 deletion src/components/InventoryTable/TitleColumn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { act, fireEvent, render } from '@testing-library/react';

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
Link: ({ children, ...props }) => <a {...props}>{children}</a>, // eslint-disable-line
Link: ({ children, ...props }) => <a class="fakeLink" {...props}>{children}</a>, // eslint-disable-line
}));

describe('TitleColumn', () => {
Expand Down Expand Up @@ -40,6 +40,16 @@ describe('TitleColumn', () => {
expect(asFragment()).toMatchSnapshot();
});

it('should render correctly with to', () => {
const { asFragment } = render(
<TitleColumn id="testId" item={{ to: { pathname: '/link/to/item' } }}>
something
</TitleColumn>
);

expect(asFragment()).toMatchSnapshot();
});

it('should render correctly no detail with data', () => {
const { asFragment } = render(
<TitleColumn
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports[`TitleColumn should render correctly with NO data 1`] = `
class=""
>
<a
to=""
class="fakeLink"
/>
</div>
</div>
Expand All @@ -42,6 +42,7 @@ exports[`TitleColumn should render correctly with data 1`] = `
class=""
>
<a
class="fakeLink"
to="testId"
>
something
Expand All @@ -60,7 +61,8 @@ exports[`TitleColumn should render correctly with href 1`] = `
class=""
>
<a
to="///link/to/item"
class="fakeLink"
to="/link/to/item"
>
something
</a>
Expand All @@ -81,6 +83,7 @@ exports[`TitleColumn should render correctly with os_release 1`] = `
class=""
>
<a
class="fakeLink"
to="testId"
>
something
Expand All @@ -89,3 +92,22 @@ exports[`TitleColumn should render correctly with os_release 1`] = `
</div>
</DocumentFragment>
`;

exports[`TitleColumn should render correctly with to 1`] = `
<DocumentFragment>
<div
class="ins-composed-col sentry-mask data-hj-suppress"
>
<div
class=""
>
<a
class="fakeLink"
to="[object Object]"
>
something
</a>
</div>
</div>
</DocumentFragment>
`;

0 comments on commit 0664aba

Please sign in to comment.