Commit fc38a8de authored by Jacques Erasmus's avatar Jacques Erasmus Committed by Denys Mishunov

Blob refactor: Hide copy and view raw buttons when viewing binary files

parent 5912f3de
...@@ -25,6 +25,11 @@ export default { ...@@ -25,6 +25,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
isBinary: {
type: Boolean,
required: false,
default: false,
},
activeViewerType: { activeViewerType: {
type: String, type: String,
required: false, required: false,
...@@ -81,6 +86,7 @@ export default { ...@@ -81,6 +86,7 @@ export default {
:raw-path="blob.rawPath" :raw-path="blob.rawPath"
:active-viewer="viewer" :active-viewer="viewer"
:has-render-error="hasRenderError" :has-render-error="hasRenderError"
:is-binary="isBinary"
@copy="proxyCopyRequest" @copy="proxyCopyRequest"
/> />
</div> </div>
......
...@@ -32,6 +32,11 @@ export default { ...@@ -32,6 +32,11 @@ export default {
required: false, required: false,
default: false, default: false,
}, },
isBinary: {
type: Boolean,
required: false,
default: false,
},
}, },
computed: { computed: {
downloadUrl() { downloadUrl() {
...@@ -43,6 +48,9 @@ export default { ...@@ -43,6 +48,9 @@ export default {
getBlobHashTarget() { getBlobHashTarget() {
return `[data-blob-hash="${this.blobHash}"]`; return `[data-blob-hash="${this.blobHash}"]`;
}, },
showCopyButton() {
return !this.hasRenderError && !this.isBinary;
},
}, },
BTN_COPY_CONTENTS_TITLE, BTN_COPY_CONTENTS_TITLE,
BTN_DOWNLOAD_TITLE, BTN_DOWNLOAD_TITLE,
...@@ -52,7 +60,7 @@ export default { ...@@ -52,7 +60,7 @@ export default {
<template> <template>
<gl-button-group data-qa-selector="default_actions_container"> <gl-button-group data-qa-selector="default_actions_container">
<gl-button <gl-button
v-if="!hasRenderError" v-if="showCopyButton"
v-gl-tooltip.hover v-gl-tooltip.hover
: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"
...@@ -65,6 +73,7 @@ export default { ...@@ -65,6 +73,7 @@ export default {
variant="default" variant="default"
/> />
<gl-button <gl-button
v-if="!isBinary"
v-gl-tooltip.hover v-gl-tooltip.hover
:aria-label="$options.BTN_RAW_TITLE" :aria-label="$options.BTN_RAW_TITLE"
:title="$options.BTN_RAW_TITLE" :title="$options.BTN_RAW_TITLE"
......
...@@ -169,6 +169,7 @@ export default { ...@@ -169,6 +169,7 @@ export default {
<blob-header <blob-header
:blob="blobInfo" :blob="blobInfo"
:hide-viewer-switcher="!hasRichViewer || isBinary" :hide-viewer-switcher="!hasRichViewer || isBinary"
:is-binary="isBinary"
:active-viewer-type="viewer.type" :active-viewer-type="viewer.type"
:has-render-error="hasRenderError" :has-render-error="hasRenderError"
@viewer-changed="switchViewer" @viewer-changed="switchViewer"
......
...@@ -39,6 +39,9 @@ describe('Blob Header Default Actions', () => { ...@@ -39,6 +39,9 @@ describe('Blob Header Default Actions', () => {
}); });
describe('renders', () => { describe('renders', () => {
const findCopyButton = () => wrapper.find('[data-testid="copyContentsButton"]');
const findViewRawButton = () => wrapper.find('[data-testid="viewRawButton"]');
it('gl-button-group component', () => { it('gl-button-group component', () => {
expect(btnGroup.exists()).toBe(true); expect(btnGroup.exists()).toBe(true);
}); });
...@@ -76,7 +79,14 @@ describe('Blob Header Default Actions', () => { ...@@ -76,7 +79,14 @@ describe('Blob Header Default Actions', () => {
hasRenderError: true, hasRenderError: true,
}); });
expect(wrapper.find('[data-testid="copyContentsButton"]').exists()).toBe(false); expect(findCopyButton().exists()).toBe(false);
});
it('does not render the copy and view raw button if isBinary is set to true', () => {
createComponent({ isBinary: true });
expect(findCopyButton().exists()).toBe(false);
expect(findViewRawButton().exists()).toBe(false);
}); });
}); });
}); });
...@@ -29,6 +29,8 @@ describe('Blob Header Default Actions', () => { ...@@ -29,6 +29,8 @@ describe('Blob Header Default Actions', () => {
}); });
describe('rendering', () => { describe('rendering', () => {
const findDefaultActions = () => wrapper.find(DefaultActions);
const slots = { const slots = {
prepend: 'Foo Prepend', prepend: 'Foo Prepend',
actions: 'Actions Bar', actions: 'Actions Bar',
...@@ -42,7 +44,7 @@ describe('Blob Header Default Actions', () => { ...@@ -42,7 +44,7 @@ describe('Blob Header Default Actions', () => {
it('renders all components', () => { it('renders all components', () => {
createComponent(); createComponent();
expect(wrapper.find(ViewerSwitcher).exists()).toBe(true); expect(wrapper.find(ViewerSwitcher).exists()).toBe(true);
expect(wrapper.find(DefaultActions).exists()).toBe(true); expect(findDefaultActions().exists()).toBe(true);
expect(wrapper.find(BlobFilepath).exists()).toBe(true); expect(wrapper.find(BlobFilepath).exists()).toBe(true);
}); });
...@@ -100,7 +102,13 @@ describe('Blob Header Default Actions', () => { ...@@ -100,7 +102,13 @@ describe('Blob Header Default Actions', () => {
hasRenderError: true, hasRenderError: true,
}, },
); );
expect(wrapper.find(DefaultActions).props('hasRenderError')).toBe(true); expect(findDefaultActions().props('hasRenderError')).toBe(true);
});
it('passes the correct isBinary value to default actions when viewing a binary file', () => {
createComponent({}, {}, { isBinary: true });
expect(findDefaultActions().props('isBinary')).toBe(true);
}); });
}); });
......
...@@ -349,6 +349,17 @@ describe('Blob content viewer component', () => { ...@@ -349,6 +349,17 @@ describe('Blob content viewer component', () => {
}); });
}); });
it('passes the correct isBinary value to blob header when viewing a binary file', async () => {
fullFactory({
mockData: { blobInfo: richMockData, isBinary: true },
stubs: { BlobContent: true, BlobReplace: true },
});
await nextTick();
expect(findBlobHeader().props('isBinary')).toBe(true);
});
describe('BlobButtonGroup', () => { describe('BlobButtonGroup', () => {
const { name, path, replacePath, webPath } = simpleMockData; const { name, path, replacePath, webPath } = simpleMockData;
const { const {
......
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