Commit 6c504c83 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'dmishunov/276913-snippet-copy-content' into 'master'

Fixed copy contents functionality for snippets

See merge request gitlab-org/gitlab!47646
parents ec218553 587f8738
...@@ -32,6 +32,7 @@ export default { ...@@ -32,6 +32,7 @@ export default {
default: false, default: false,
}, },
}, },
inject: ['blobHash'],
computed: { computed: {
downloadUrl() { downloadUrl() {
return `${this.rawPath}?inline=false`; return `${this.rawPath}?inline=false`;
...@@ -39,6 +40,9 @@ export default { ...@@ -39,6 +40,9 @@ export default {
copyDisabled() { copyDisabled() {
return this.activeViewer === RICH_BLOB_VIEWER; return this.activeViewer === RICH_BLOB_VIEWER;
}, },
getBlobHashTarget() {
return `[data-blob-hash="${this.blobHash}"]`;
},
}, },
BTN_COPY_CONTENTS_TITLE, BTN_COPY_CONTENTS_TITLE,
BTN_DOWNLOAD_TITLE, BTN_DOWNLOAD_TITLE,
...@@ -53,7 +57,7 @@ export default { ...@@ -53,7 +57,7 @@ export default {
:aria-label="$options.BTN_COPY_CONTENTS_TITLE" :aria-label="$options.BTN_COPY_CONTENTS_TITLE"
:title="$options.BTN_COPY_CONTENTS_TITLE" :title="$options.BTN_COPY_CONTENTS_TITLE"
:disabled="copyDisabled" :disabled="copyDisabled"
data-clipboard-target="#blob-code-content" :data-clipboard-target="getBlobHashTarget"
data-testid="copyContentsButton" data-testid="copyContentsButton"
icon="copy-to-clipboard" icon="copy-to-clipboard"
category="primary" category="primary"
......
...@@ -51,6 +51,13 @@ export default { ...@@ -51,6 +51,13 @@ export default {
required: true, required: true,
}, },
}, },
provide() {
return {
blobHash: Math.random()
.toString()
.split('.')[1],
};
},
data() { data() {
return { return {
blobContent: '', blobContent: '',
......
...@@ -9,6 +9,7 @@ export default { ...@@ -9,6 +9,7 @@ export default {
GlIcon, GlIcon,
}, },
mixins: [ViewerMixin], mixins: [ViewerMixin],
inject: ['blobHash'],
data() { data() {
return { return {
highlightedLine: null, highlightedLine: null,
...@@ -64,7 +65,7 @@ export default { ...@@ -64,7 +65,7 @@ export default {
</a> </a>
</div> </div>
<div class="blob-content"> <div class="blob-content">
<pre class="code highlight"><code id="blob-code-content" v-html="content"></code></pre> <pre class="code highlight"><code :data-blob-hash="blobHash" v-html="content"></code></pre>
</div> </div>
</div> </div>
</template> </template>
---
title: Fixed copy contents functionality for snippets
merge_request: 47646
author:
type: fixed
...@@ -14,8 +14,13 @@ describe('Blob Header Default Actions', () => { ...@@ -14,8 +14,13 @@ describe('Blob Header Default Actions', () => {
let btnGroup; let btnGroup;
let buttons; let buttons;
const blobHash = 'foo-bar';
function createComponent(propsData = {}) { function createComponent(propsData = {}) {
wrapper = mount(BlobHeaderActions, { wrapper = mount(BlobHeaderActions, {
provide: {
blobHash,
},
propsData: { propsData: {
rawPath: Blob.rawPath, rawPath: Blob.rawPath,
...propsData, ...propsData,
......
...@@ -11,7 +11,11 @@ describe('Blob Header Default Actions', () => { ...@@ -11,7 +11,11 @@ describe('Blob Header Default Actions', () => {
function createComponent(blobProps = {}, options = {}, propsData = {}, shouldMount = false) { function createComponent(blobProps = {}, options = {}, propsData = {}, shouldMount = false) {
const method = shouldMount ? mount : shallowMount; const method = shouldMount ? mount : shallowMount;
const blobHash = 'foo-bar';
wrapper = method.call(this, BlobHeader, { wrapper = method.call(this, BlobHeader, {
provide: {
blobHash,
},
propsData: { propsData: {
blob: { ...Blob, ...blobProps }, blob: { ...Blob, ...blobProps },
...propsData, ...propsData,
......
...@@ -59,7 +59,7 @@ exports[`Blob Simple Viewer component rendering matches the snapshot 1`] = ` ...@@ -59,7 +59,7 @@ exports[`Blob Simple Viewer component rendering matches the snapshot 1`] = `
class="code highlight" class="code highlight"
> >
<code <code
id="blob-code-content" data-blob-hash="foo-bar"
> >
<span <span
id="LC1" id="LC1"
......
...@@ -5,9 +5,13 @@ import { HIGHLIGHT_CLASS_NAME } from '~/vue_shared/components/blob_viewers/const ...@@ -5,9 +5,13 @@ import { HIGHLIGHT_CLASS_NAME } from '~/vue_shared/components/blob_viewers/const
describe('Blob Simple Viewer component', () => { describe('Blob Simple Viewer component', () => {
let wrapper; let wrapper;
const contentMock = `<span id="LC1">First</span>\n<span id="LC2">Second</span>\n<span id="LC3">Third</span>`; const contentMock = `<span id="LC1">First</span>\n<span id="LC2">Second</span>\n<span id="LC3">Third</span>`;
const blobHash = 'foo-bar';
function createComponent(content = contentMock) { function createComponent(content = contentMock) {
wrapper = shallowMount(SimpleViewer, { wrapper = shallowMount(SimpleViewer, {
provide: {
blobHash,
},
propsData: { propsData: {
content, content,
type: 'text', type: 'text',
......
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