Skip to content

Commit cb2f3ca

Browse files
committed
feat: Add documentation URL to GithubDetails
1 parent 594b730 commit cb2f3ca

File tree

2 files changed

+75
-39
lines changed

2 files changed

+75
-39
lines changed

src/components/shared/TaskDetails/Details.tsx

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -50,29 +50,35 @@ const TaskDetailsInternal = ({
5050

5151
const canonicalUrl =
5252
hydratedComponentRef.spec.metadata?.annotations?.canonical_location;
53+
54+
// Try reconstruct URLs from componentSpec.metadata.annotations
55+
const annotations = hydratedComponentRef.spec.metadata?.annotations || {};
56+
const {
57+
git_remote_url,
58+
git_remote_branch,
59+
git_relative_dir,
60+
component_yaml_path,
61+
documentation_path,
62+
} = annotations;
63+
5364
let reconstructedUrl;
54-
if (!url) {
55-
// Try reconstruct the url from componentSpec.metadata.annotations
56-
const annotations = hydratedComponentRef.spec.metadata?.annotations || {};
57-
const {
58-
git_remote_url,
59-
git_remote_branch,
60-
git_relative_dir,
61-
component_yaml_path,
62-
} = annotations;
63-
64-
if (
65-
typeof git_remote_url === "string" &&
66-
typeof git_remote_branch === "string" &&
67-
typeof git_relative_dir === "string" &&
68-
typeof component_yaml_path === "string"
69-
) {
70-
reconstructedUrl = `https://github.com/${git_remote_url
71-
.replace(/^https:\/\/github\.com\//, "")
72-
.replace(
73-
/\.git$/,
74-
"",
75-
)}/blob/${git_remote_branch}/${git_relative_dir}/${component_yaml_path}`;
65+
let documentationUrl;
66+
67+
if (
68+
typeof git_remote_url === "string" &&
69+
typeof git_remote_branch === "string" &&
70+
typeof git_relative_dir === "string"
71+
) {
72+
const gitHubBaseUrl = `https://github.com/${git_remote_url
73+
.replace(/^https:\/\/github\.com\//, "")
74+
.replace(/\.git$/, "")}/blob/${git_remote_branch}/${git_relative_dir}`;
75+
76+
if (!url && typeof component_yaml_path === "string") {
77+
reconstructedUrl = `${gitHubBaseUrl}/${component_yaml_path}`;
78+
}
79+
80+
if (typeof documentation_path === "string") {
81+
documentationUrl = `${gitHubBaseUrl}/${documentation_path}`;
7682
}
7783
}
7884

@@ -106,6 +112,7 @@ const TaskDetailsInternal = ({
106112
<GithubDetails
107113
url={url && url.length > 0 ? url : reconstructedUrl}
108114
canonicalUrl={canonicalUrl}
115+
documentationUrl={documentationUrl}
109116
className={BASE_BLOCK_CLASS}
110117
/>
111118

src/components/shared/TaskDetails/GithubDetails.tsx

Lines changed: 46 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,71 @@ const linkProps = {
1414
export function GithubDetails({
1515
url,
1616
canonicalUrl,
17+
documentationUrl,
1718
className,
1819
}: {
1920
url?: string;
2021
canonicalUrl?: string;
22+
documentationUrl?: string;
2123
className?: string;
2224
}) {
23-
if (!url && !canonicalUrl) return null;
25+
const hasUrl = url || canonicalUrl;
26+
27+
if (!hasUrl && !documentationUrl) return null;
2428

2529
return (
2630
<BlockStack className={className}>
27-
<Heading level={3}>URL</Heading>
28-
{url && (
31+
{hasUrl && (
2932
<>
30-
<Link href={url} {...linkProps}>
31-
View raw component.yaml
32-
</Link>
33+
<Heading level={3}>URL</Heading>
34+
{url && (
35+
<>
36+
<Link href={url} {...linkProps}>
37+
View raw component.yaml
38+
</Link>
3339

34-
<Link
35-
href={isGithubUrl(url) ? convertGithubUrlToDirectoryUrl(url) : url}
36-
{...linkProps}
37-
>
38-
View directory on GitHub
39-
</Link>
40+
<Link
41+
href={
42+
isGithubUrl(url) ? convertGithubUrlToDirectoryUrl(url) : url
43+
}
44+
{...linkProps}
45+
>
46+
View directory on GitHub
47+
</Link>
48+
</>
49+
)}
50+
{canonicalUrl && (
51+
<>
52+
<Link href={canonicalUrl} {...linkProps}>
53+
View canonical URL
54+
</Link>
55+
56+
<Link
57+
href={convertGithubUrlToDirectoryUrl(canonicalUrl)}
58+
{...linkProps}
59+
>
60+
View canonical URL on GitHub
61+
</Link>
62+
</>
63+
)}
4064
</>
4165
)}
42-
{canonicalUrl && (
66+
{documentationUrl && (
4367
<>
44-
<Link href={canonicalUrl} {...linkProps}>
45-
View canonical URL
68+
<Heading level={3}>Documentation</Heading>
69+
<Link href={documentationUrl} {...linkProps}>
70+
View documentation
4671
</Link>
4772

4873
<Link
49-
href={convertGithubUrlToDirectoryUrl(canonicalUrl)}
74+
href={
75+
isGithubUrl(documentationUrl)
76+
? convertGithubUrlToDirectoryUrl(documentationUrl)
77+
: documentationUrl
78+
}
5079
{...linkProps}
5180
>
52-
View canonical URL on GitHub
81+
View directory on GitHub
5382
</Link>
5483
</>
5584
)}

0 commit comments

Comments
 (0)