Skip to content

feat: add new useVisibleItems composable#2395

Open
43081j wants to merge 5 commits intomainfrom
jg/visible-invisibilities
Open

feat: add new useVisibleItems composable#2395
43081j wants to merge 5 commits intomainfrom
jg/visible-invisibilities

Conversation

@43081j
Copy link
Copy Markdown
Contributor

@43081j 43081j commented Apr 5, 2026

🔗 Linked issue

N/A

🧭 Context

Reducing duplicated logic for determining which items are visible in a page.

📚 Description

This adds a new useVisibleItems composable and initially adopts it in
the dependencies view of a package.

In follow ups, we can adopt it in more pages to reduce duplicated logic.

This adds a new `useVisibleItems` composable and initially adopts it in
the dependencies view of a package.

In follow ups, we can adopt it in more pages to reduce duplicated logic.
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
npmx.dev Ready Ready Preview, Comment Apr 5, 2026 9:07pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Apr 5, 2026 9:07pm
npmx-lunaria Ignored Ignored Apr 5, 2026 9:07pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 5, 2026

📝 Walkthrough

Walkthrough

A new composable useVisibleItems was added to provide visibleItems, hiddenCount, hasMore, showAll, expand, collapse, and toggle for a configurable limit. The Package Dependencies component was refactored to replace three per-section boolean refs with three instances of this composable (dependencies, peer and optional). Lists now render from each composable's visibleItems, and "show all" buttons use hasMore and call expand. Unit tests for useVisibleItems were added.

🚥 Pre-merge checks | ✅ 1
✅ Passed checks (1 passed)
Check name Status Explanation
Description check ✅ Passed The pull request description accurately describes the changeset: introducing a new useVisibleItems composable to reduce duplicated logic for determining visible items, with initial adoption in the dependencies view.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jg/visible-invisibilities

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/components/Package/Dependencies.vue (1)

87-103: Consider extracting the repeated visible-item limit into a single constant.

Using 10 three times makes future tuning error-prone. A shared constant keeps the three sections aligned.

Suggested refactor
+const DEPENDENCY_VISIBLE_LIMIT = 10
+
 const {
   visibleItems: visibleDeps,
   hasMore: hasMoreDeps,
   expand: expandDeps,
-} = useVisibleItems(sortedDependencies, 10)
+} = useVisibleItems(sortedDependencies, DEPENDENCY_VISIBLE_LIMIT)
 
 const {
   visibleItems: visiblePeerDeps,
   hasMore: hasMorePeerDeps,
   expand: expandPeerDeps,
-} = useVisibleItems(sortedPeerDependencies, 10)
+} = useVisibleItems(sortedPeerDependencies, DEPENDENCY_VISIBLE_LIMIT)
 
 const {
   visibleItems: visibleOptionalDeps,
   hasMore: hasMoreOptionalDeps,
   expand: expandOptionalDeps,
-} = useVisibleItems(sortedOptionalDependencies, 10)
+} = useVisibleItems(sortedOptionalDependencies, DEPENDENCY_VISIBLE_LIMIT)

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cfe299c8-0c1a-4e32-aba0-8fd307d0639b

📥 Commits

Reviewing files that changed from the base of the PR and between 051f8a7 and 26f7bbb.

📒 Files selected for processing (2)
  • app/components/Package/Dependencies.vue
  • app/composables/useVisibleItems.ts

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 71.42857% with 6 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
app/composables/useVisibleItems.ts 73.33% 3 Missing and 1 partial ⚠️
app/components/Package/Dependencies.vue 66.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
test/unit/app/composables/use-visible-items.spec.ts (2)

6-40: Consider parameterising the initial-state tests with it.each.

The four cases share the same arrange/assert pattern; a table-driven structure would reduce duplication and make future scenarios easier to add.

♻️ Example refactor
 describe('initial state', () => {
-  it('returns all items when list is within limit', () => {
-    const { visibleItems, hasMore, hiddenCount } = useVisibleItems(['a', 'b', 'c'], 5)
-    expect(visibleItems.value).toEqual(['a', 'b', 'c'])
-    expect(hasMore.value).toBe(false)
-    expect(hiddenCount.value).toBe(0)
-  })
+  it.each([
+    { name: 'within limit', items: ['a', 'b', 'c'], limit: 5, visible: ['a', 'b', 'c'], hasMore: false, hidden: 0 },
+    { name: 'exceeds limit', items: [1,2,3,4,5,6,7,8,9,10], limit: 5, visible: [1,2,3,4,5], hasMore: true, hidden: 5 },
+    { name: 'equals limit', items: [1,2,3], limit: 3, visible: [1,2,3], hasMore: false, hidden: 0 },
+    { name: 'empty list', items: [], limit: 5, visible: [], hasMore: false, hidden: 0 },
+  ])('returns correct state when $name', ({ items, limit, visible, hasMore, hidden }) => {
+    const state = useVisibleItems(items, limit)
+    expect(state.visibleItems.value).toEqual(visible)
+    expect(state.hasMore.value).toBe(hasMore)
+    expect(state.hiddenCount.value).toBe(hidden)
+  })
 })

103-146: Add explicit boundary tests for non-positive limits.

Please add contract tests for limit = 0 and negative limits (either clamped behaviour or thrown error), so this edge behaviour is pinned down and protected from regressions.

As per coding guidelines, "Write unit tests for core functionality using vitest."


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4c97c3d9-f61e-4ff4-9e75-3dfc80a7bfdc

📥 Commits

Reviewing files that changed from the base of the PR and between 65fc79f and bfbf554.

📒 Files selected for processing (2)
  • app/composables/useVisibleItems.ts
  • test/unit/app/composables/use-visible-items.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/composables/useVisibleItems.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant