|
@@ -1,9 +1,9 @@
|
|
|
import styled from '@emotion/styled';
|
|
|
import React from 'react';
|
|
|
-import {LocationDescriptor} from 'history';
|
|
|
import omit from 'lodash/omit';
|
|
|
|
|
|
import Link from 'app/components/links/link';
|
|
|
+import ExternalLink from 'app/components/links/externalLink';
|
|
|
import InlineSvg from 'app/components/inlineSvg';
|
|
|
import {IconChevron} from 'app/icons';
|
|
|
import space from 'app/styles/space';
|
|
@@ -11,30 +11,28 @@ import space from 'app/styles/space';
|
|
|
type Size = 'small' | 'normal';
|
|
|
type Priority = 'info' | 'warning' | 'success' | 'error' | 'muted';
|
|
|
|
|
|
-type PropsWithHref = {href: string};
|
|
|
-type PropsWithTo = {to: LocationDescriptor};
|
|
|
+type LinkProps = React.ComponentPropsWithoutRef<typeof Link>;
|
|
|
+
|
|
|
type OtherProps = {
|
|
|
icon?: string | React.ReactNode;
|
|
|
onClick?: (e: React.MouseEvent) => void;
|
|
|
};
|
|
|
+
|
|
|
type DefaultProps = {
|
|
|
size: Size;
|
|
|
priority: Priority;
|
|
|
withoutMarginBottom: boolean;
|
|
|
openInNewTab: boolean;
|
|
|
+ href?: string;
|
|
|
};
|
|
|
|
|
|
-type Props = (PropsWithHref | PropsWithTo) & OtherProps & DefaultProps;
|
|
|
+type Props = OtherProps & DefaultProps & Partial<Pick<LinkProps, 'to'>>;
|
|
|
|
|
|
-// TODO(Priscila): Improve it as soon as we merge this PR: https://github.com/getsentry/sentry/pull/17346
|
|
|
-type StyledLinkProps = PropsWithHref &
|
|
|
- PropsWithTo &
|
|
|
- Omit<DefaultProps, 'openInNewTab'> &
|
|
|
- Pick<OtherProps, 'onClick'> & {
|
|
|
- target: '_blank' | '_self';
|
|
|
- };
|
|
|
+type StyledLinkProps = DefaultProps &
|
|
|
+ Partial<Pick<LinkProps, 'to'>> &
|
|
|
+ Omit<LinkProps, 'to' | 'size'>;
|
|
|
|
|
|
-export default class AlertLink extends React.Component<Props> {
|
|
|
+class AlertLink extends React.Component<Props> {
|
|
|
static defaultProps: DefaultProps = {
|
|
|
priority: 'warning',
|
|
|
size: 'normal',
|
|
@@ -51,16 +49,18 @@ export default class AlertLink extends React.Component<Props> {
|
|
|
onClick,
|
|
|
withoutMarginBottom,
|
|
|
openInNewTab,
|
|
|
+ to,
|
|
|
+ href,
|
|
|
} = this.props;
|
|
|
return (
|
|
|
<StyledLink
|
|
|
- to={(this.props as PropsWithTo).to}
|
|
|
- href={(this.props as PropsWithHref).href}
|
|
|
+ to={to}
|
|
|
+ href={href}
|
|
|
onClick={onClick}
|
|
|
size={size}
|
|
|
priority={priority}
|
|
|
withoutMarginBottom={withoutMarginBottom}
|
|
|
- target={openInNewTab ? '_blank' : '_self'}
|
|
|
+ openInNewTab={openInNewTab}
|
|
|
>
|
|
|
{icon && (
|
|
|
<IconWrapper>
|
|
@@ -76,9 +76,16 @@ export default class AlertLink extends React.Component<Props> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-const StyledLink = styled((props: StyledLinkProps) => (
|
|
|
- <Link {...omit(props, ['withoutMarginBottom', 'priority', 'size'])} />
|
|
|
-))`
|
|
|
+export default AlertLink;
|
|
|
+
|
|
|
+const StyledLink = styled(({openInNewTab, to, href, ...props}: StyledLinkProps) => {
|
|
|
+ const linkProps = omit(props, ['withoutMarginBottom', 'priority', 'size']);
|
|
|
+ if (href) {
|
|
|
+ return <ExternalLink {...linkProps} href={href} openInNewTab={openInNewTab} />;
|
|
|
+ }
|
|
|
+
|
|
|
+ return <Link {...linkProps} to={to || ''} />;
|
|
|
+})`
|
|
|
display: flex;
|
|
|
background-color: ${p => p.theme.alert[p.priority].backgroundLight};
|
|
|
color: ${p => p.theme.gray4};
|