diff --git a/src/components/shared/TaskDetails/Details.tsx b/src/components/shared/TaskDetails/Details.tsx index dfd7e2181..ee8dfb466 100644 --- a/src/components/shared/TaskDetails/Details.tsx +++ b/src/components/shared/TaskDetails/Details.tsx @@ -53,29 +53,47 @@ const TaskDetailsInternal = ({ const canonicalUrl = hydratedComponentRef.spec.metadata?.annotations?.canonical_location; + + // Try reconstruct URLs from componentSpec.metadata.annotations + const annotations = hydratedComponentRef.spec.metadata?.annotations || {}; + const { + git_remote_url, + git_remote_branch, + git_relative_dir, + component_yaml_path, + documentation_path, + } = annotations; + let reconstructedUrl; - if (!url) { - // Try reconstruct the url from componentSpec.metadata.annotations - const annotations = hydratedComponentRef.spec.metadata?.annotations || {}; - const { - git_remote_url, - git_remote_branch, - git_relative_dir, - component_yaml_path, - } = annotations; - - if ( - typeof git_remote_url === "string" && - typeof git_remote_branch === "string" && - typeof git_relative_dir === "string" && - typeof component_yaml_path === "string" - ) { - reconstructedUrl = `https://github.com/${git_remote_url - .replace(/^https:\/\/github\.com\//, "") - .replace( - /\.git$/, - "", - )}/blob/${git_remote_branch}/${git_relative_dir}/${component_yaml_path}`; + let documentationUrl; + + if ( + typeof git_remote_url === "string" && + typeof git_remote_branch === "string" && + typeof git_relative_dir === "string" + ) { + const repoPath = git_remote_url + .replace(/^https:\/\/github\.com\//, "") + .replace(/\.git$/, ""); + + const buildGitHubUrl = (filePath: string) => { + const url = new URL(`https://github.com`); + url.pathname = [ + repoPath, + "blob", + git_remote_branch, + git_relative_dir, + filePath, + ].join("/"); + return url.toString(); + }; + + if (!url && typeof component_yaml_path === "string") { + reconstructedUrl = buildGitHubUrl(component_yaml_path); + } + + if (typeof documentation_path === "string") { + documentationUrl = buildGitHubUrl(documentation_path); } } @@ -109,6 +127,7 @@ const TaskDetailsInternal = ({ 0 ? url : reconstructedUrl} canonicalUrl={canonicalUrl} + documentationUrl={documentationUrl} className={BASE_BLOCK_CLASS} /> diff --git a/src/components/shared/TaskDetails/GithubDetails.tsx b/src/components/shared/TaskDetails/GithubDetails.tsx index 5ec2b43e9..0095a31d6 100644 --- a/src/components/shared/TaskDetails/GithubDetails.tsx +++ b/src/components/shared/TaskDetails/GithubDetails.tsx @@ -14,44 +14,73 @@ const linkProps = { export function GithubDetails({ url, canonicalUrl, + documentationUrl, className, }: { url?: string; canonicalUrl?: string; + documentationUrl?: string; className?: string; }) { - if (!url && !canonicalUrl) return null; + const hasUrl = url || canonicalUrl; + + if (!hasUrl && !documentationUrl) return null; return ( - - URL - {url && ( - <> - - View raw component.yaml - + + {!!hasUrl && ( + + URL + {!!url && ( + <> + + View raw component.yaml + - - View directory on GitHub - - + + View directory on GitHub + + + )} + {!!canonicalUrl && ( + <> + + View canonical URL + + + + View canonical URL on GitHub + + + )} + )} - {canonicalUrl && ( - <> - - View canonical URL + {!!documentationUrl && ( + + Documentation + + View documentation - View canonical URL on GitHub + View directory on GitHub - + )} );