Skip to content

Commit ea59266

Browse files
committed
CrateSidebar: Show Package URL in "Metadata" section
1 parent 40e5893 commit ea59266

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

app/components/crate-sidebar.hbs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
<div local-class="metadata">
77
<h2 local-class="heading">Metadata</h2>
88

9+
<div local-class="purl" data-test-purl>
10+
{{svg-jar "link"}}
11+
<CopyButton
12+
@copyText={{@version.purl}}
13+
class="button-reset"
14+
local-class="purl-copy-button"
15+
>
16+
<span local-class="purl-text">{{@version.purl}}</span>
17+
<Tooltip local-class="purl-tooltip"><strong>Package URL:</strong> {{@version.purl}} <small>(click to copy)</small></Tooltip>
18+
</CopyButton>
19+
</div>
20+
921
<time
1022
datetime={{date-format-iso @version.created_at}}
1123
local-class="date"

app/components/crate-sidebar.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { action } from '@ember/object';
12
import { service } from '@ember/service';
23
import Component from '@glimmer/component';
34

@@ -6,6 +7,7 @@ import { didCancel } from 'ember-concurrency';
67
import { simplifyUrl } from './crate-sidebar/link';
78

89
export default class CrateSidebar extends Component {
10+
@service notifications;
911
@service playground;
1012
@service sentry;
1113

@@ -39,4 +41,14 @@ export default class CrateSidebar extends Component {
3941
}
4042
});
4143
}
44+
45+
@action
46+
async copyToClipboard(text) {
47+
try {
48+
await navigator.clipboard.writeText(text);
49+
this.notifications.success('Copied to clipboard!');
50+
} catch {
51+
this.notifications.error('Copy to clipboard failed!');
52+
}
53+
}
4254
}

app/components/crate-sidebar.module.css

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
.msrv,
2323
.edition,
2424
.license,
25-
.bytes {
25+
.bytes,
26+
.purl {
2627
display: flex;
2728
align-items: center;
2829

@@ -52,6 +53,40 @@
5253
font-variant-numeric: tabular-nums;
5354
}
5455

56+
.purl {
57+
align-items: flex-start;
58+
}
59+
60+
.purl-copy-button {
61+
text-align: left;
62+
width: 100%;
63+
min-width: 0;
64+
cursor: pointer;
65+
66+
&:focus {
67+
outline: 2px solid var(--yellow500);
68+
outline-offset: 1px;
69+
border-radius: var(--space-3xs);
70+
}
71+
}
72+
73+
.purl-text {
74+
word-break: break-all;
75+
max-width: 100%;
76+
overflow: hidden;
77+
text-overflow: ellipsis;
78+
white-space: nowrap;
79+
display: block;
80+
}
81+
82+
.purl-tooltip {
83+
word-break: break-all;
84+
85+
> small {
86+
word-break: normal;
87+
}
88+
}
89+
5590
.links {
5691
> * + * {
5792
margin-top: var(--space-m);

0 commit comments

Comments
 (0)