2020-09-01 14:51:59 +00:00
|
|
|
import React from "react";
|
|
|
|
import { ExternalLinkAltIcon } from "@patternfly/react-icons";
|
2020-09-22 12:12:16 +00:00
|
|
|
import { Button, ButtonProps } from "@patternfly/react-core";
|
2021-01-11 19:29:52 +00:00
|
|
|
import { IFormatter, IFormatterValueType } from "@patternfly/react-table";
|
2020-09-01 08:25:24 +00:00
|
|
|
|
2021-01-11 19:29:52 +00:00
|
|
|
export const FormattedLink = ({ title, href, ...rest }: ButtonProps) => {
|
2020-09-01 08:25:24 +00:00
|
|
|
return (
|
2020-09-21 20:12:53 +00:00
|
|
|
<Button
|
|
|
|
variant="link"
|
|
|
|
icon={href?.startsWith("http") && <ExternalLinkAltIcon />}
|
|
|
|
iconPosition="right"
|
|
|
|
component="a"
|
|
|
|
href={href}
|
2020-11-10 20:26:20 +00:00
|
|
|
target="_blank"
|
2020-09-21 20:12:53 +00:00
|
|
|
{...rest}
|
|
|
|
>
|
|
|
|
{title ? title : href}
|
|
|
|
</Button>
|
2020-09-01 08:25:24 +00:00
|
|
|
);
|
|
|
|
};
|
2021-01-11 19:29:52 +00:00
|
|
|
|
|
|
|
export const formattedLinkTableCell = (): IFormatter => (
|
|
|
|
data?: IFormatterValueType
|
|
|
|
) => {
|
|
|
|
return (data ? (
|
|
|
|
<FormattedLink href={data.toString()} />
|
|
|
|
) : undefined) as object;
|
|
|
|
};
|