From ec1dffca2e2bdae0a2e2c27375be7a2f9e975aab Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Tue, 28 Sep 2021 21:33:26 +0100 Subject: [PATCH] Link to dependencies from crate page Fixes #19 --- chartered-frontend/src/pages/crate/CrateView.tsx | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/chartered-frontend/src/pages/crate/CrateView.tsx b/chartered-frontend/src/pages/crate/CrateView.tsx index e6ef835..2f6317e 100644 --- a/chartered-frontend/src/pages/crate/CrateView.tsx +++ a/chartered-frontend/src/pages/crate/CrateView.tsx @@ -57,6 +57,7 @@ export interface CrateInfoVersionDependency { name: string; version_req: string; + registry?: string; } export default function SingleCrate() { @@ -71,7 +72,7 @@ const { response: crateInfo, error } = useAuthenticatedRequest({ auth, endpoint: `crates/${organisation}/${crate}`, - }); + }, [organisation, crate]); if (error) { return ; @@ -223,14 +224,7 @@ ) : ( <> )} - {crateVersion.deps.map((dep) => ( -
  • - {dep.name} = "{dep.version_req}" -
  • - ))} + {crateVersion.deps.map((dep) => )} @@ -249,6 +243,28 @@ uuid: string; username: string; permissions: string[]; +} + +function Dependency({ organisation, dep }: { organisation: string, dep: CrateInfoVersionDependency }) { + let link = <>{dep.name}; + + if (dep.registry === null) { + link = {link}; + } else if (dep.registry === "https://github.com/rust-lang/crates.io-index") { + link = {link}; + } else if (dep.registry.indexOf("ssh://") === 0) { + const parts = dep.registry.split('/'); + const org = parts[parts.length - 1]; + if (org) { + link = {link}; + } + } + + return ( +
  • + {link} = "{dep.version_req}" +
  • + ); } function Members({ -- rgit 0.1.3