github.com/turbot/steampipe@v1.7.0-rc.0.0.20240517123944-7cef272d4458/ui/dashboard/src/components/ExternalLink/index.tsx (about)

     1  import { Link } from "react-router-dom";
     2  import {
     3    DashboardDataModeCLISnapshot,
     4    DashboardDataModeCloudSnapshot,
     5  } from "../../types";
     6  import { ReactNode } from "react";
     7  import { registerComponent } from "../dashboards";
     8  import { useDashboard } from "../../hooks/useDashboard";
     9  
    10  type ExternalLinkProps = {
    11    children: ReactNode;
    12    className?: string;
    13    ignoreDataMode?: boolean;
    14    target?: string;
    15    title?: string;
    16    to: string;
    17    withReferrer?: boolean;
    18  };
    19  
    20  const ExternalLink = ({
    21    children,
    22    className = "link-highlight",
    23    ignoreDataMode = false,
    24    target = "_blank",
    25    title,
    26    to,
    27    withReferrer = false,
    28  }: ExternalLinkProps) => {
    29    const { dataMode } = useDashboard();
    30  
    31    if (!to) {
    32      return null;
    33    }
    34  
    35    if (to.match("^https?://")) {
    36      return (
    37        /*eslint-disable */
    38        <a
    39          className={className}
    40          href={to}
    41          rel={withReferrer ? undefined : "noopener noreferrer"}
    42          target={target}
    43        >
    44          {children}
    45        </a>
    46        /*eslint-enable */
    47      );
    48    }
    49  
    50    if (
    51      (!ignoreDataMode && dataMode === DashboardDataModeCLISnapshot) ||
    52      dataMode === DashboardDataModeCloudSnapshot
    53    ) {
    54      return children || null;
    55    }
    56  
    57    return (
    58      <Link to={to} className={className} title={title}>
    59        {children}
    60      </Link>
    61    );
    62  };
    63  
    64  registerComponent("external_link", ExternalLink);
    65  
    66  export default ExternalLink;