Skip to content

feat: added feature to copy version number by hovering on the version#2660

Open
PreethiPantangi wants to merge 3 commits intonpmx-dev:mainfrom
PreethiPantangi:main
Open

feat: added feature to copy version number by hovering on the version#2660
PreethiPantangi wants to merge 3 commits intonpmx-dev:mainfrom
PreethiPantangi:main

Conversation

@PreethiPantangi
Copy link
Copy Markdown

🔗 Linked issue

Resolves #2646

🧭 Context

The feature provides user with the capability to copy the version number of the package by hovering over it. This helps the user to easily grab the data instead of typing it out.

Adds copy-to-clipboard functionality for package version via hover interaction in the header.

📚 Description

Files changed:
- Header.vue
- en.json

Header.vue
- The VersionSelector component is wrapped with CopyToClipboardButton component to ensure the user is able to copy the version number on hover.

en.json
- Added the key value pair "copy_version": "Copy version number" to ensure internationalization

No tests added as this change is UI-only and does not affect business logic. Existing functionality remains unchanged.

No documentation changes required

I've used co-pilot to understand some parts of the code before diving into making the feature changes

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 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 30, 2026 11:04pm
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs.npmx.dev Ignored Ignored Preview Apr 30, 2026 11:04pm
npmx-lunaria Ignored Ignored Apr 30, 2026 11:04pm

Request Review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

📝 Walkthrough

Walkthrough

The changes implement functionality to copy the resolved package version to the clipboard, accessible via both a UI button integrated into the version selector and a new command palette command with clipboard feedback.

Changes

Cohort / File(s) Summary
Package header / UI
app/components/Package/Header.vue
Adds clipboard support for resolved package version: new resolvedVersionDisplay computed, useClipboard usage, copyPkgVersion() action, wraps VersionSelector in CopyToClipboardButton, and conditionally renders a package-copy-version command for the command palette.
Localisation — strings
i18n/locales/en.json
Adds translation key package.versions.copy_version ("Copy version number") used for the copy action label.
Localisation — schema
i18n/schema.json
Updates JSON schema to include copy_version under package.versions.copy_alt to validate the new translation key.

Sequence Diagram(s)

sequenceDiagram
  participant User as User
  participant UI as PackageHeader (UI)
  participant Clipboard as ClipboardService
  participant Commands as CommandPalette
  participant Announcer as Announcer

  User->>UI: Click "Copy version" button / invoke command
  UI->>Clipboard: copy(resolvedVersionDisplay)
  Clipboard-->>UI: copy result (success/failure)
  UI->>Announcer: announce("Copied version" / error)
  UI->>Commands: update command state (copied = true)
  Announcer-->>User: verbal/ARIA feedback
  Commands-->>User: command executed feedback
Loading
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly relates to the changeset, explaining the context, files modified, and implementation details of the copy-version feature.
Linked Issues check ✅ Passed The PR successfully implements both primary requirements from issue #2646: adding a quick way to copy the package version and making the version more noticeable via the CopyToClipboardButton wrapper.
Out of Scope Changes check ✅ Passed All changes are directly related to the linked issue #2646. The modifications to Header.vue, en.json, and i18n/schema.json are all necessary for implementing the copy-version feature with proper internationalisation support.
Title check ✅ Passed The title accurately describes the main change: adding copy-to-clipboard functionality for package versions via hover interaction in the Header component.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@github-actions
Copy link
Copy Markdown

Hello! Thank you for opening your first PR to npmx, @PreethiPantangi! 🚀

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any issues you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Vercel

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 30, 2026

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
i18n/locales/en.json Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

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

Files with missing lines Patch % Lines
app/components/Package/Header.vue 78.57% 3 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@app/components/Package/Header.vue`:
- Around line 108-118: The command object with id 'package-copy-version'
currently uses props.resolvedVersion directly for keywords and always calls
copyPkgVersion() and announce(), so guard these actions by checking that
props.resolvedVersion is a non-empty string before invoking copyPkgVersion() or
announce(); if absent, no-op (or return) so nothing is copied or announced; also
ensure keywords is strictly string-only by transforming/filtering it to a string
(e.g., use String(props.resolvedVersion) or include only when truthy) so
keywords never contains undefined/null; apply the same guard/keyword fix for the
other similar command block that uses resolvedVersion (the block noted in the
review).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 82e6bf58-7e13-4dac-81e0-768c1f1550c6

📥 Commits

Reviewing files that changed from the base of the PR and between 5eab00c and 8ed5b85.

📒 Files selected for processing (2)
  • app/components/Package/Header.vue
  • i18n/locales/en.json

Comment thread app/components/Package/Header.vue Outdated
Copy link
Copy Markdown
Contributor

@gameroman gameroman left a comment

Choose a reason for hiding this comment

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

Overall very good, just make sure the CI passes, also left a couple of comments

Comment thread app/components/Package/Header.vue Outdated
import type { RouteLocationRaw } from 'vue-router'
import type { CommandPaletteContextCommandInput } from '~/types/command-palette'
import { SCROLL_TO_TOP_THRESHOLD } from '~/composables/useScrollToTop'
import { useClipboard } from '@vueuse/core'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

iirc, this isn't necessary since it's auto-imported

Comment thread app/components/Package/Header.vue Outdated
announce($t('command_palette.announcements.copied_to_clipboard'))
},
},
]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

coderabbit's suggestions makes sense here. I would do something like this here

const commands: CommandPaletteContextCommandInput[] = []

if (packageName.value) {
  commands.push({
    id: 'package-copy-name',
    group: 'package',
    label: $t('package.copy_name'),
    keywords: [packageName.value],
    iconClass: 'i-lucide:copy',
    action: () => {
      copyPkgName()
      announce($t('command_palette.announcements.copied_to_clipboard'))
    },
  })
}

if (props.resolvedVersion) {
  commands.push({
    id: 'package-copy-version',
    group: 'package',
    label: $t('package.versions.copy_version'),
    keywords: [props.resolvedVersion],
    iconClass: 'i-lucide:copy',
    action: () => {
      copyPkgVersion()
      announce($t('command_palette.announcements.copied_to_clipboard'))
    },
  })
}

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.

♻️ Duplicate comments (1)
app/components/Package/Header.vue (1)

312-328: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Gate the version copy wrapper to avoid an empty focusable control.

On Line 312, CopyToClipboardButton always renders, while VersionSelector is gated on Line 320. When version data is missing, this can leave a focusable copy control with no visible anchor and an empty copy value. Apply the same v-if to the wrapper and render VersionSelector unconditionally inside it.

Suggested fix
-          <CopyToClipboardButton
+          <CopyToClipboardButton
+            v-if="resolvedVersion && pkg?.versions && pkg?.['dist-tags']"
             :copied="copiedPkgVersion"
             :copy-text="$t('package.versions.copy_version')"
             class="inline-flex items-center min-w-0"
             `@click`="copyPkgVersion()"
           >
             <!-- Version selector -->
             <VersionSelector
-              v-if="resolvedVersion && pkg?.versions && pkg?.['dist-tags']"
               :package-name="packageName"
               :current-version="resolvedVersion"
               :versions="pkg.versions"
               :dist-tags="pkg['dist-tags']"
               :url-pattern="versionUrlPattern"
               position-class="max-md:inset-is-0 md:inset-ie-0"
             />
           </CopyToClipboardButton>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/components/Package/Header.vue` around lines 312 - 328, The
CopyToClipboardButton wrapper is rendered unconditionally while VersionSelector
is gated by resolvedVersion and pkg data, causing an empty focusable control;
change the v-if condition from the inner VersionSelector to the
CopyToClipboardButton so the whole wrapper (the CopyToClipboardButton that uses
copiedPkgVersion and copyPkgVersion) only renders when resolvedVersion &&
pkg?.versions && pkg?.['dist-tags'] are present, and then render VersionSelector
unconditionally inside it (keep props: :package-name="packageName",
:current-version="resolvedVersion", :versions="pkg.versions",
:dist-tags="pkg['dist-tags']", :url-pattern="versionUrlPattern").
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@app/components/Package/Header.vue`:
- Around line 312-328: The CopyToClipboardButton wrapper is rendered
unconditionally while VersionSelector is gated by resolvedVersion and pkg data,
causing an empty focusable control; change the v-if condition from the inner
VersionSelector to the CopyToClipboardButton so the whole wrapper (the
CopyToClipboardButton that uses copiedPkgVersion and copyPkgVersion) only
renders when resolvedVersion && pkg?.versions && pkg?.['dist-tags'] are present,
and then render VersionSelector unconditionally inside it (keep props:
:package-name="packageName", :current-version="resolvedVersion",
:versions="pkg.versions", :dist-tags="pkg['dist-tags']",
:url-pattern="versionUrlPattern").

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 46061c25-5981-4e68-bad1-638fc48efcfb

📥 Commits

Reviewing files that changed from the base of the PR and between 8ed5b85 and deb30ac.

📒 Files selected for processing (4)
  • Please
  • [👉
  • app/components/Package/Header.vue
  • i18n/schema.json
✅ Files skipped from review due to trivial changes (1)
  • i18n/schema.json

Comment thread [👉 Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is accidental probably?

Comment thread Please Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This too

@PreethiPantangi PreethiPantangi changed the title Added feature to copy version number by hovering on the version feat: Added feature to copy version number by hovering on the version Apr 30, 2026
@PreethiPantangi PreethiPantangi changed the title feat: Added feature to copy version number by hovering on the version feat: added feature to copy version number by hovering on the version Apr 30, 2026
@PreethiPantangi
Copy link
Copy Markdown
Author

@gameroman I’ve addressed the feedback from the code review. Also, deleted the two junk files created accidentally.

@gameroman
Copy link
Copy Markdown
Contributor

Looks good

One thing to change, it probably should hide the copy button when you press the button to change the version

image

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.

A quick way to copy package version

2 participants