Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MINOR: open links in new tab in DataAssetsHeader #18172

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,24 @@ export const ExtraInfoLink = ({
label,
value,
href,
newTab = false,
}: {
label: string;
value: string | number;
href: string;
newTab?: boolean;
}) => (
<>
<Divider className="self-center" type="vertical" />
<div className="d-flex items-center text-xs">
{!isEmpty(label) && (
<span className="text-grey-muted m-r-xss">{`${label}: `}</span>
)}
<Typography.Link href={href} style={{ fontSize: '12px' }}>
<Typography.Link
href={href}
rel={newTab ? 'noopener noreferrer' : undefined}
style={{ fontSize: '12px' }}
target={newTab ? '_blank' : undefined}>
{value}{' '}
</Typography.Link>
<Icon
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { Container } from '../../../generated/entity/data/container';
import { MOCK_TIER_DATA } from '../../../mocks/TableData.mock';
import { getContainerByName } from '../../../rest/storageAPI';
import { DEFAULT_ENTITY_PERMISSION } from '../../../utils/PermissionsUtils';
import { DataAssetsHeader } from './DataAssetsHeader.component';
import { DataAssetsHeader, ExtraInfoLink } from './DataAssetsHeader.component';
import { DataAssetsHeaderProps } from './DataAssetsHeader.interface';

const mockProps: DataAssetsHeaderProps = {
Expand Down Expand Up @@ -103,6 +103,37 @@ jest.mock('../../../rest/storageAPI', () => ({
.mockImplementation(() => Promise.resolve({ name: 'test' })),
}));

describe('ExtraInfoLink component', () => {
const mockProps = {
label: 'myLabel',
value: 'example',
href: 'http://example.com/',
};

it('should not have target and rel attributes when newTab is false (default)', () => {
const { container } = render(<ExtraInfoLink {...mockProps} />);

const elm = container.querySelector('a');

expect(elm).toHaveAttribute('href', mockProps.href);
expect(elm).not.toHaveAttribute('target');
expect(elm).not.toHaveAttribute('rel');
});

it('should have target and rel attributes when newTab is true', () => {
const { container } = render(<ExtraInfoLink {...mockProps} newTab />);

const elm = container.querySelector('a');

expect(elm).toHaveAttribute('href', mockProps.href);
expect(elm).toHaveAttribute('target', '_blank');

const rel = (elm?.getAttribute('rel') || '').split(/\s+/g);

expect(rel.sort()).toStrictEqual(['noopener', 'noreferrer'].sort());
});
});

describe('DataAssetsHeader component', () => {
it('should call getContainerByName API on Page load for container assets', () => {
const mockGetContainerByName = getContainerByName as jest.Mock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export const getDataAssetsHeaderInfo = (
<>
{dashboardDetails.sourceUrl && (
<ExtraInfoLink
newTab
href={dashboardDetails.sourceUrl}
label=""
value={getEntityName(dashboardDetails)}
Expand Down Expand Up @@ -147,6 +148,7 @@ export const getDataAssetsHeaderInfo = (
<>
{pipelineDetails.sourceUrl && (
<ExtraInfoLink
newTab
href={pipelineDetails.sourceUrl}
label=""
value={getEntityName(pipelineDetails)}
Expand Down Expand Up @@ -178,6 +180,7 @@ export const getDataAssetsHeaderInfo = (
)}
{mlModelDetail.server && (
<ExtraInfoLink
newTab
href={mlModelDetail.server}
label={t('label.server')}
value={mlModelDetail.server}
Expand Down Expand Up @@ -388,6 +391,7 @@ export const getDataAssetsHeaderInfo = (
<>
{storedProcedureDetails.sourceUrl && (
<ExtraInfoLink
newTab
href={storedProcedureDetails.sourceUrl}
label=""
value={getEntityName(storedProcedureDetails)}
Expand Down Expand Up @@ -422,6 +426,7 @@ export const getDataAssetsHeaderInfo = (
<>
{apiCollection.endpointURL && (
<ExtraInfoLink
newTab
Sachin-chaurasiya marked this conversation as resolved.
Show resolved Hide resolved
href={apiCollection.endpointURL}
label={t('label.endpoint-url')}
value={apiCollection.endpointURL}
Expand Down Expand Up @@ -451,6 +456,7 @@ export const getDataAssetsHeaderInfo = (
)}
{apiEndpoint.endpointURL && (
<ExtraInfoLink
newTab
Sachin-chaurasiya marked this conversation as resolved.
Show resolved Hide resolved
href={apiEndpoint.endpointURL}
label={t('label.endpoint-url')}
value={apiEndpoint.endpointURL}
Expand Down
Loading