2019-11-11 13:42:24 -08:00
|
|
|
import React, { FC } from 'react';
|
|
|
|
import { Badge, Alert } from 'reactstrap';
|
|
|
|
|
|
|
|
export interface EndpointLinkProps {
|
|
|
|
endpoint: string;
|
2020-02-17 09:19:15 -08:00
|
|
|
globalUrl: string;
|
2019-11-11 13:42:24 -08:00
|
|
|
}
|
|
|
|
|
2020-02-17 09:19:15 -08:00
|
|
|
const EndpointLink: FC<EndpointLinkProps> = ({ endpoint, globalUrl }) => {
|
2019-11-11 13:42:24 -08:00
|
|
|
let url: URL;
|
|
|
|
try {
|
|
|
|
url = new URL(endpoint);
|
|
|
|
} catch (e) {
|
|
|
|
return (
|
|
|
|
<Alert color="danger">
|
|
|
|
<strong>Error:</strong> {e.message}
|
|
|
|
</Alert>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const { host, pathname, protocol, searchParams }: URL = url;
|
|
|
|
const params = Array.from(searchParams.entries());
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2020-02-17 09:19:15 -08:00
|
|
|
<a href={globalUrl}>{`${protocol}//${host}${pathname}`}</a>
|
2019-11-11 13:42:24 -08:00
|
|
|
{params.length > 0 ? <br /> : null}
|
|
|
|
{params.map(([labelName, labelValue]: [string, string]) => {
|
|
|
|
return (
|
2021-02-08 13:17:04 -08:00
|
|
|
<Badge color="primary" className={`mr-1 ${labelName}`} key={`${labelName}/${labelValue}`}>
|
2019-11-11 13:42:24 -08:00
|
|
|
{`${labelName}="${labelValue}"`}
|
|
|
|
</Badge>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EndpointLink;
|