-
-
Notifications
You must be signed in to change notification settings - Fork 366
feat: add package dependents list page #2208
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
Open
thealxlabs
wants to merge
7
commits into
npmx-dev:main
Choose a base branch
from
thealxlabs:feat/dependents-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+444
−3
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f6b48d6
feat: add package dependents list page (#2036)
thealxlabs 22cb7f5
fix(a11y): increase provenance link touch target size to meet 24px mi…
thealxlabs 143ad3f
fix: resolve type errors and i18n schema for dependents page
thealxlabs b8dd395
test: add dependents API response mapping unit tests
thealxlabs f6f50c0
[autofix.ci] apply automated fixes
autofix-ci[bot] c260e85
fix: add missing dependents i18n keys and regenerate schema
thealxlabs 23ac526
fix: resolve TypeScript noUncheckedIndexedAccess error in dependents …
thealxlabs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| <script setup lang="ts"> | ||
| definePageMeta({ | ||
| name: 'package-dependents', | ||
| scrollMargin: 200, | ||
| }) | ||
|
|
||
| const route = useRoute('package-dependents') | ||
|
|
||
| const packageName = computed(() => { | ||
| const { org, name } = route.params | ||
| return org ? `${org}/${name}` : name | ||
| }) | ||
|
|
||
| const { data: pkg } = usePackage(packageName) | ||
|
|
||
| const resolvedVersion = computed(() => { | ||
| const latest = pkg.value?.['dist-tags']?.latest | ||
| if (!latest) return null | ||
| return latest | ||
| }) | ||
|
|
||
| const displayVersion = computed(() => pkg.value?.requestedVersion ?? null) | ||
|
|
||
| const latestVersion = computed(() => { | ||
| if (!pkg.value) return null | ||
| const latestTag = pkg.value['dist-tags']?.latest | ||
| if (!latestTag) return null | ||
| return pkg.value.versions[latestTag] ?? null | ||
| }) | ||
|
|
||
| const versionUrlPattern = computed(() => { | ||
| const split = packageName.value.split('/') | ||
| if (split.length === 2) { | ||
| return `/package/${split[0]}/${split[1]}/v/{version}` | ||
| } | ||
| return `/package/${packageName.value}/v/{version}` | ||
| }) | ||
|
|
||
| const page = shallowRef(0) | ||
| const PAGE_SIZE = 20 | ||
|
|
||
| interface DependentsResponse { | ||
| total: number | ||
| page: number | ||
| size: number | ||
| packages: Array<{ | ||
| name: string | ||
| version: string | ||
| description: string | null | ||
| date: string | null | ||
| score: number | ||
| }> | ||
| } | ||
|
|
||
| const { data, status, refresh } = useLazyFetch<DependentsResponse>( | ||
| () => `/api/registry/dependents/${packageName.value}`, | ||
| { | ||
| query: computed(() => ({ page: page.value, size: PAGE_SIZE })), | ||
| watch: [page], | ||
| }, | ||
| ) | ||
|
|
||
| const totalPages = computed(() => { | ||
| if (!data.value?.total) return 0 | ||
| return Math.ceil(data.value.total / PAGE_SIZE) | ||
| }) | ||
|
|
||
| function prevPage() { | ||
| if (page.value > 0) { | ||
| page.value-- | ||
| window.scrollTo({ top: 0, behavior: 'smooth' }) | ||
| } | ||
| } | ||
|
|
||
| function nextPage() { | ||
| if (page.value < totalPages.value - 1) { | ||
| page.value++ | ||
| window.scrollTo({ top: 0, behavior: 'smooth' }) | ||
| } | ||
| } | ||
|
|
||
| const numberFormatter = useNumberFormatter() | ||
|
|
||
| useSeoMeta({ | ||
| title: () => `Dependents - ${packageName.value} - npmx`, | ||
| description: () => `Packages that depend on ${packageName.value}`, | ||
| }) | ||
| </script> | ||
|
|
||
| <template> | ||
| <main class="flex-1 pb-8"> | ||
| <PackageHeader | ||
| :pkg="pkg ?? null" | ||
| :resolved-version="resolvedVersion" | ||
| :display-version="displayVersion" | ||
| :latest-version="latestVersion" | ||
| :version-url-pattern="versionUrlPattern" | ||
| page="dependents" | ||
| /> | ||
|
|
||
| <div class="container py-6"> | ||
| <h1 class="font-mono text-xl font-semibold mb-1"> | ||
| {{ $t('package.dependents.title') }} | ||
| </h1> | ||
| <p class="text-sm text-fg-muted mb-6"> | ||
| {{ $t('package.dependents.subtitle', { name: packageName }) }} | ||
| </p> | ||
|
|
||
| <!-- Loading state --> | ||
| <div v-if="status === 'pending'" class="space-y-2"> | ||
| <SkeletonInline v-for="i in 10" :key="i" class="h-16 w-full rounded-md" /> | ||
| </div> | ||
|
|
||
| <!-- Error state --> | ||
| <div v-else-if="status === 'error'" class="py-12 text-center"> | ||
| <p class="text-fg-muted mb-4">{{ $t('package.dependents.error') }}</p> | ||
| <ButtonBase @click="refresh()">{{ $t('common.retry') }}</ButtonBase> | ||
| </div> | ||
|
|
||
| <!-- Empty state --> | ||
| <div v-else-if="!data?.packages?.length" class="py-12 text-center"> | ||
| <span class="i-lucide:package-x w-12 h-12 mx-auto mb-4 text-fg-subtle block" /> | ||
| <p class="text-fg-muted">{{ $t('package.dependents.none', { name: packageName }) }}</p> | ||
| </div> | ||
|
|
||
| <!-- Results --> | ||
| <template v-else> | ||
| <p class="text-xs text-fg-subtle mb-4 font-mono"> | ||
| {{ | ||
| $t( | ||
| 'package.dependents.count', | ||
| { count: numberFormatter.format(data.total) }, | ||
| data.total, | ||
| ) | ||
| }} | ||
| </p> | ||
|
|
||
| <ul class="space-y-2 list-none m-0 p-0"> | ||
| <li | ||
| v-for="dep in data.packages" | ||
| :key="dep.name" | ||
| class="border border-border rounded-md p-4 hover:border-border-hover transition-colors" | ||
| > | ||
| <div class="flex items-start justify-between gap-4"> | ||
| <div class="min-w-0 flex-1"> | ||
| <LinkBase | ||
| :to="packageRoute(dep.name)" | ||
| class="font-mono text-sm font-medium" | ||
| dir="ltr" | ||
| > | ||
| {{ dep.name }} | ||
| </LinkBase> | ||
| <p v-if="dep.description" class="text-xs text-fg-muted mt-1 line-clamp-2"> | ||
| {{ dep.description }} | ||
| </p> | ||
| </div> | ||
| <span class="font-mono text-xs text-fg-subtle shrink-0" dir="ltr"> | ||
| {{ dep.version }} | ||
| </span> | ||
| </div> | ||
| </li> | ||
| </ul> | ||
|
|
||
| <!-- Pagination --> | ||
| <div v-if="totalPages > 1" class="flex items-center justify-between mt-6"> | ||
| <ButtonBase | ||
| variant="secondary" | ||
| classicon="i-lucide:chevron-left" | ||
| :disabled="page === 0" | ||
| @click="prevPage" | ||
| > | ||
| {{ $t('common.previous') }} | ||
| </ButtonBase> | ||
| <span class="text-sm text-fg-muted font-mono"> {{ page + 1 }} / {{ totalPages }} </span> | ||
| <ButtonBase variant="secondary" :disabled="page >= totalPages - 1" @click="nextPage"> | ||
| {{ $t('common.next') }} | ||
| <span class="i-lucide:chevron-right w-4 h-4" aria-hidden="true" /> | ||
| </ButtonBase> | ||
| </div> | ||
| </template> | ||
| </div> | ||
| </main> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.