🏡 index : ~doyle/chartered.git

author Jordan Doyle <jordan@doyle.la> 2021-09-28 21:33:26.0 +01:00:00
committer Jordan Doyle <jordan@doyle.la> 2021-09-28 21:33:26.0 +01:00:00
commit
ec1dffca2e2bdae0a2e2c27375be7a2f9e975aab [patch]
tree
a37810a640e83299a48af1b5e9b15102dc56259a
parent
4fda1c2e66d5407d127b75a8df5f146704337d13
download
ec1dffca2e2bdae0a2e2c27375be7a2f9e975aab.tar.gz

Link to dependencies from crate page

Fixes #19

Diff

 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<CrateInfo>({
    auth,
    endpoint: `crates/${organisation}/${crate}`,
  });
  }, [organisation, crate]);

  if (error) {
    return <ErrorPage message={error} />;
@@ -223,14 +224,7 @@
                ) : (
                  <></>
                )}
                {crateVersion.deps.map((dep) => (
                  <li
                    key={`${dep.name}-${dep.version_req}`}
                    className="list-group-item"
                  >
                    {dep.name} = "<strong>{dep.version_req}</strong>"
                  </li>
                ))}
                {crateVersion.deps.map((dep) => <Dependency key={`${dep.name}-${dep.version_req}`} organisation={organisation} dep={dep} /> )}
              </ul>
            </div>
          </div>
@@ -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 = <a target="_blank" href={`/crates/${organisation}/${dep.name}`}>{link}</a>;
  } else if (dep.registry === "https://github.com/rust-lang/crates.io-index") {
    link = <a target="_blank" href={`https://crates.io/crates/${dep.name}`}>{link}</a>;
  } else if (dep.registry.indexOf("ssh://") === 0) {
    const parts = dep.registry.split('/');
    const org = parts[parts.length - 1];
    if (org) {
      link = <Link to={`/crates/${org}/${dep.name}`}>{link}</Link>;
    }
  }

  return (
    <li className="list-group-item">
      {link} = "<strong>{dep.version_req}</strong>"
    </li>
  );
}

function Members({