Skip to content

Commit d969832

Browse files
committed
refactor(gs): use ExternalLink with display prop instead of custom StyledLink
1 parent 136cd84 commit d969832

File tree

2 files changed

+29
-30
lines changed

2 files changed

+29
-30
lines changed

plugins/gs/src/components/UI/Version/Version.tsx

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import semver from 'semver';
2-
import { Box, Link, Tooltip, styled } from '@material-ui/core';
3-
import LaunchOutlinedIcon from '@material-ui/icons/LaunchOutlined';
2+
import { Box, Tooltip, styled } from '@material-ui/core';
43
import ReportProblemOutlined from '@material-ui/icons/ReportProblemOutlined';
54
import MiddleEllipsis from 'react-middle-ellipsis';
65
import { getCommitURL, getReleaseNotesURL } from '../../utils/helpers';
76
import { ColorWrapper } from '../ColorWrapper';
7+
import { ExternalLink } from '@giantswarm/backstage-plugin-ui-react';
88

99
const StyledReportProblemOutlined = styled(ReportProblemOutlined)(
1010
({ theme }) => ({
@@ -14,21 +14,6 @@ const StyledReportProblemOutlined = styled(ReportProblemOutlined)(
1414
}),
1515
);
1616

17-
// Block-level flex link so the width constraint chain works for MiddleEllipsis truncation.
18-
// ExternalLink uses inline-flex which breaks percentage-based maxWidth resolution.
19-
const StyledLink = styled(Link)({
20-
display: 'flex',
21-
alignItems: 'center',
22-
overflow: 'hidden',
23-
minWidth: 0,
24-
});
25-
26-
const StyledLaunchOutlinedIcon = styled(LaunchOutlinedIcon)(({ theme }) => ({
27-
marginLeft: theme.spacing(0.5),
28-
fontSize: 'inherit',
29-
flexShrink: 0,
30-
}));
31-
3217
const COMMIT_HASH_REGEXP = /\b[0-9a-f]{40}\b/;
3318
const INVALID_VERSION = 'n/a';
3419

@@ -213,18 +198,21 @@ export const Version = ({
213198
maxWidth={truncate ? '100%' : undefined}
214199
>
215200
{displayLinkToProject ? (
216-
<StyledLink
217-
href={
218-
commitHash
219-
? getCommitURL(sourceLocation, commitHash)
220-
: getReleaseNotesURL(sourceLocation, versionLabel)
221-
}
222-
target="_blank"
223-
rel="noopener noreferrer"
201+
<Box
202+
overflow={truncate ? 'hidden' : undefined}
203+
minWidth={truncate ? 0 : undefined}
224204
>
225-
{versionComponent}
226-
<StyledLaunchOutlinedIcon />
227-
</StyledLink>
205+
<ExternalLink
206+
href={
207+
commitHash
208+
? getCommitURL(sourceLocation, commitHash)
209+
: getReleaseNotesURL(sourceLocation, versionLabel)
210+
}
211+
display={truncate ? 'flex' : 'inline-flex'}
212+
>
213+
{versionComponent}
214+
</ExternalLink>
215+
</Box>
228216
) : (
229217
versionComponent
230218
)}

plugins/ui-react/src/components/ExternalLink/ExternalLink.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,23 @@ const StyledLaunchOutlinedIcon = styled(LaunchOutlinedIcon)(({ theme }) => ({
99
type ExternalLinkProps = {
1010
href: string;
1111
children: React.ReactNode;
12+
/**
13+
* CSS display value for the inner flex container.
14+
* Use 'flex' (block-level) when the link needs to participate in a width
15+
* constraint chain (e.g. inside a flex/grid item for text truncation).
16+
* @default 'inline-flex'
17+
*/
18+
display?: 'flex' | 'inline-flex';
1219
};
1320

14-
export const ExternalLink = ({ href, children }: ExternalLinkProps) => {
21+
export const ExternalLink = ({
22+
href,
23+
children,
24+
display = 'inline-flex',
25+
}: ExternalLinkProps) => {
1526
return (
1627
<Link href={href} target="_blank" rel="noopener noreferrer">
17-
<Box display="inline-flex" alignItems="center">
28+
<Box display={display} alignItems="center">
1829
{children}
1930
<StyledLaunchOutlinedIcon />
2031
</Box>

0 commit comments

Comments
 (0)