Commit b29cc855 authored by Tim Zallmann's avatar Tim Zallmann

Merge branch '35618-add-clipboard-button-to-package-registry-information' into 'master'

Add copy button to package registry metadata

Closes #35618

See merge request gitlab-org/gitlab!19881
parents 8f9855b5 df73a3d8
---
title: Adds a copy button next to package metadata on the details page
merge_request: 19881
author:
type: added
...@@ -209,6 +209,7 @@ export default { ...@@ -209,6 +209,7 @@ export default {
v-if="packageMetadata" v-if="packageMetadata"
:heading="packageMetadataTitle" :heading="packageMetadataTitle"
:information="packageMetadata" :information="packageMetadata"
:show-copy="true"
/> />
<package-installation <package-installation
v-else v-else
......
<script> <script>
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
export default { export default {
name: 'PackageInformation', name: 'PackageInformation',
components: {
ClipboardButton,
},
props: { props: {
heading: { heading: {
type: String, type: String,
...@@ -14,6 +18,11 @@ export default { ...@@ -14,6 +18,11 @@ export default {
default: () => [], default: () => [],
required: true, required: true,
}, },
showCopy: {
type: Boolean,
required: false,
default: false,
},
}, },
}; };
</script> </script>
...@@ -28,7 +37,15 @@ export default { ...@@ -28,7 +37,15 @@ export default {
<ul class="content-list"> <ul class="content-list">
<li v-for="(item, index) in information" :key="index"> <li v-for="(item, index) in information" :key="index">
<span class="text-secondary">{{ item.label }}</span> <span class="text-secondary">{{ item.label }}</span>
<span class="pull-right">{{ item.value }}</span> <div class="pull-right">
<span>{{ item.value }}</span>
<clipboard-button
v-if="showCopy"
:text="item.value"
:title="sprintf(__('Copy %{field}'), { field: item.label })"
css-class="border-0 text-secondary py-0"
/>
</div>
</li> </li>
</ul> </ul>
</div> </div>
......
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import PackageInformation from 'ee/packages/details/components/information.vue'; import PackageInformation from 'ee/packages/details/components/information.vue';
import ClipboardButton from '~/vue_shared/components/clipboard_button.vue';
describe('PackageInformation', () => { describe('PackageInformation', () => {
let wrapper; let wrapper;
...@@ -33,6 +34,7 @@ describe('PackageInformation', () => { ...@@ -33,6 +34,7 @@ describe('PackageInformation', () => {
} }
const headingSelector = () => wrapper.find('.card-header > strong'); const headingSelector = () => wrapper.find('.card-header > strong');
const copyButton = () => wrapper.findAll(ClipboardButton);
const informationSelector = () => wrapper.findAll('ul.content-list li'); const informationSelector = () => wrapper.findAll('ul.content-list li');
const informationRowText = index => const informationRowText = index =>
informationSelector() informationSelector()
...@@ -69,4 +71,21 @@ describe('PackageInformation', () => { ...@@ -69,4 +71,21 @@ describe('PackageInformation', () => {
expect(informationRowText(1)).toContain('two'); expect(informationRowText(1)).toContain('two');
expect(informationRowText(2)).toContain('three'); expect(informationRowText(2)).toContain('three');
}); });
describe('copy button', () => {
it('does not render by default', () => {
createComponent();
expect(copyButton().exists()).toBe(false);
});
it('does render when the prop is set and has correct text set', () => {
createComponent({ showCopy: true });
expect(copyButton().length).toBe(3);
expect(copyButton().at(0).vm.text).toBe(defaultProps.information[0].value);
expect(copyButton().at(1).vm.text).toBe(defaultProps.information[1].value);
expect(copyButton().at(2).vm.text).toBe(defaultProps.information[2].value);
});
});
}); });
...@@ -4682,6 +4682,9 @@ msgstr "" ...@@ -4682,6 +4682,9 @@ msgstr ""
msgid "Copy" msgid "Copy"
msgstr "" msgstr ""
msgid "Copy %{field}"
msgstr ""
msgid "Copy %{http_label} clone URL" msgid "Copy %{http_label} clone URL"
msgstr "" msgstr ""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment