Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: include module paths in Dependencies page #556

Merged
merged 13 commits into from
Nov 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 48 additions & 4 deletions frontend/routes/package/dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,32 @@ export default define.page<typeof handler>(function Deps(
) {
const iam = scopeIAM(state, data.member);

const deps: Record<string, { link: string; constraints: Set<string> }> = {};
const deps: Record<
string,
{
link: string;
constraints: Set<string>;
modules: Record<string, string | undefined>;
defaultModule: boolean;
}
> = {};

for (const dep of data.deps) {
const key = `${dep.kind}:${dep.name}`;
deps[key] ??= {
link: getDependencyLink(dep),
constraints: new Set(),
modules: {},
defaultModule: false,
};
deps[key].constraints.add(dep.constraint);
if (dep.path) {
deps[key].modules[dep.path] = dep.kind === "jsr"
? `/${dep.name}/doc/${dep.path}/~`
: undefined;
} else {
deps[key].defaultModule = true;
}
}

const list = Object.entries(deps);
Expand Down Expand Up @@ -67,8 +84,9 @@ export default define.page<typeof handler>(function Deps(
: (
<Table
columns={[
{ title: "Name", class: "w-1/3" },
{ title: "Versions", class: "w-auto" },
{ title: "Package", class: "w-1/3" },
{ title: "Versions", class: "w-1/3" },
{ title: "Modules", class: "w-auto" },
]}
currentUrl={url}
>
Expand All @@ -77,6 +95,8 @@ export default define.page<typeof handler>(function Deps(
name={name}
link={info.link}
constraints={[...info.constraints]}
modules={Object.entries(info.modules)}
defaultModule={info.defaultModule}
/>
))}
</Table>
Expand All @@ -87,10 +107,12 @@ export default define.page<typeof handler>(function Deps(
});

function Dependency(
{ name, link, constraints }: {
{ name, link, constraints, modules, defaultModule }: {
name: string;
link: string;
constraints: string[];
modules: [path: string, link?: string][];
defaultModule: boolean;
},
) {
return (
Expand All @@ -103,6 +125,28 @@ function Dependency(
<TableData class="space-x-4">
{constraints.map((constraint) => <span>{constraint}</span>)}
</TableData>
<TableData>
{modules.length > 0 && (
<ul>
{defaultModule && <li class="italic">(default)</li>}
{modules.map(([path, link]) => (
<li>
{link
? (
<a href={link} class="link">
{path}
</a>
)
: (
<span>
{path}
</span>
)}
</li>
))}
</ul>
)}
</TableData>
</TableRow>
);
}
Expand Down
Loading