Skip to content

Commit

Permalink
small azure patches (#4341)
Browse files Browse the repository at this point in the history
  • Loading branch information
d-g-town authored Feb 28, 2024
1 parent b6c25dc commit 63cbe42
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 12 deletions.
49 changes: 40 additions & 9 deletions dashboard/src/components/porter/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import DynamicLink from "components/DynamicLink";
import React from "react";
import styled from "styled-components";

import DynamicLink from "components/DynamicLink";

type Props = {
to?: string;
onClick?: () => void;
Expand All @@ -11,6 +12,7 @@ type Props = {
color?: string;
hoverColor?: string;
showTargetBlankIcon?: boolean;
inline?: boolean;
};

const Link: React.FC<Props> = ({
Expand All @@ -22,14 +24,39 @@ const Link: React.FC<Props> = ({
color = "#ffffff",
hoverColor,
showTargetBlankIcon = true,
inline = true,
}) => {
return (
<LinkWrapper hoverColor={hoverColor} color={color}>
{to ? (
<StyledLink to={to} target={target} color={color}>
<StyledLink
to={to}
target={target}
color={color}
inline={inline}
>
{children}
{target === "_blank" && showTargetBlankIcon && (
<Svg color={color} hoverColor={hoverColor} data-testid="geist-icon" fill="none" height="1em" shape-rendering="geometricPrecision" stroke="currentColor" stroke-linecap="round" strokeLinejoin="round" stroke-width="2" viewBox="0 0 24 24" width="1em" data-darkreader-inline-stroke="" data-darkreader-inline-color=""><path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"></path><path d="M15 3h6v6"></path><path d="M10 14L21 3"></path></Svg>
<Svg
color={color}
hoverColor={hoverColor}
data-testid="geist-icon"
fill="none"
height="1em"
shape-rendering="geometricPrecision"
stroke="currentColor"
stroke-linecap="round"
strokeLinejoin="round"
stroke-width="2"
viewBox="0 0 24 24"
width="1em"
data-darkreader-inline-stroke=""
data-darkreader-inline-color=""
>
<path d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6"></path>
<path d="M15 3h6v6"></path>
<path d="M10 14L21 3"></path>
</Svg>
)}
</StyledLink>
) : (
Expand All @@ -44,7 +71,7 @@ const Link: React.FC<Props> = ({

export default Link;

const Svg = styled.svg<{ color: string, hoverColor?: string }>`
const Svg = styled.svg<{ color: string; hoverColor?: string }>`
margin-left: 5px;
stroke: ${(props) => props.color};
stroke-width: 2;
Expand All @@ -59,9 +86,13 @@ const Underline = styled.div<{ color: string }>`
background: ${(props) => props.color};
`;

const StyledLink = styled(DynamicLink) <{ hasunderline?: boolean, color: string, removeInline?: boolean }>`
const StyledLink = styled(DynamicLink)<{
hasunderline?: boolean;
color: string;
inline: boolean;
}>`
color: ${(props) => props.color};
${(props) => !props.removeInline && "display: inline-flex;"};
${(props) => props.inline && "display: inline-flex;"};
font-size: 13px;
cursor: pointer;
align-items: center;
Expand All @@ -75,7 +106,7 @@ const Div = styled.span<{ color: string }>`
align-items: center;
`;

const LinkWrapper = styled.span<{ hoverColor?: string, color: string }>`
const LinkWrapper = styled.span<{ hoverColor?: string; color: string }>`
position: relative;
display: inline-flex;
align-items: center;
Expand All @@ -95,5 +126,5 @@ const LinkWrapper = styled.span<{ hoverColor?: string, color: string }>`
svg {
stroke: ${({ hoverColor, color }) => hoverColor ?? color};
}
};
`;
}
`;
21 changes: 19 additions & 2 deletions dashboard/src/lib/hooks/useCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,11 @@ export const useUpdateCluster = ({
// otherwise, continue to create the contract
} catch (err) {
throw new Error(
getErrorMessageFromNetworkCall(err, "Cluster preflight checks")
getErrorMessageFromNetworkCall(
err,
"Cluster preflight checks",
preflightCheckErrorReplacements
)
);
} finally {
setIsHandlingPreflightChecks(false);
Expand Down Expand Up @@ -531,15 +535,28 @@ export const useClusterNodeList = ({
};
};

const preflightCheckErrorReplacements = {
RequestThrottled:
"Your cloud provider is currently throttling API requests. Please try again in a few minutes.",
};

const getErrorMessageFromNetworkCall = (
err: unknown,
networkCallDescription: string
networkCallDescription: string,
replaceError?: Record<string, string>
): string => {
if (axios.isAxiosError(err)) {
const parsed = z
.object({ error: z.string() })
.safeParse(err.response?.data);
if (parsed.success) {
if (replaceError) {
for (const key in replaceError) {
if (parsed.data.error.includes(key)) {
return `${networkCallDescription} failed: ${replaceError[key]}`;
}
}
}
return `${networkCallDescription} failed: ${parsed.data.error}`;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const ResolutionStepsModalContents: React.FC<Props> = ({ resolution }) => {
{resolution.steps.map((step, i) => (
<Step number={i + 1} key={i}>
{step.externalLink ? (
<Link to={step.externalLink} target="_blank">
<Link to={step.externalLink} target="_blank" inline={false}>
{step.text}
</Link>
) : (
Expand Down

0 comments on commit 63cbe42

Please sign in to comment.