Commit 630f2e18 authored by Brandon Labuschagne's avatar Brandon Labuschagne

Merge branch '323200-view-blobs-through-view' into 'master'

Use Editor Lite in readonly mode to view blobs

See merge request gitlab-org/gitlab!57705
parents f84fd813 ff6826fc
...@@ -21,6 +21,11 @@ export default { ...@@ -21,6 +21,11 @@ export default {
default: '', default: '',
required: false, required: false,
}, },
isRawContent: {
type: Boolean,
default: false,
required: false,
},
loading: { loading: {
type: Boolean, type: Boolean,
default: true, default: true,
...@@ -65,6 +70,8 @@ export default { ...@@ -65,6 +70,8 @@ export default {
v-else v-else
ref="contentViewer" ref="contentViewer"
:content="content" :content="content"
:is-raw-content="isRawContent"
:file-name="blob.name"
:type="activeViewer.fileType" :type="activeViewer.fileType"
data-qa-selector="file_content" data-qa-selector="file_content"
/> />
......
...@@ -36,6 +36,12 @@ export default { ...@@ -36,6 +36,12 @@ export default {
blobHash: uniqueId(), blobHash: uniqueId(),
}; };
}, },
props: {
path: {
type: String,
required: true,
},
},
data() { data() {
return { return {
projectPath: '', projectPath: '',
...@@ -85,6 +91,7 @@ export default { ...@@ -85,6 +91,7 @@ export default {
<blob-content <blob-content
:blob="blobInfo" :blob="blobInfo"
:content="blobInfo.rawBlob" :content="blobInfo.rawBlob"
:is-raw-content="true"
:active-viewer="viewer" :active-viewer="viewer"
:loading="false" :loading="false"
/> />
......
...@@ -2,16 +2,21 @@ ...@@ -2,16 +2,21 @@
// This file is in progress and behind a feature flag, please see the following issue for more: // This file is in progress and behind a feature flag, please see the following issue for more:
// https://gitlab.com/gitlab-org/gitlab/-/issues/323200 // https://gitlab.com/gitlab-org/gitlab/-/issues/323200
// TODO (follow-up MR): import BlobContentViewer from '../components/blob_content_viewer.vue'; import BlobContentViewer from '../components/blob_content_viewer.vue';
export default { export default {
components: { components: {
// TODO (follow-up MR): BlobContentViewer, BlobContentViewer,
},
props: {
path: {
type: String,
required: true,
},
}, },
}; };
</script> </script>
<template> <template>
<div></div> <blob-content-viewer :path="path" />
<!-- TODO (follow-up MR): <blob-content-viewer/> -->
</template> </template>
...@@ -11,6 +11,16 @@ export default { ...@@ -11,6 +11,16 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
isRawContent: {
type: Boolean,
default: false,
required: false,
},
fileName: {
type: String,
required: false,
default: '',
},
}, },
mounted() { mounted() {
eventHub.$emit(SNIPPET_MEASURE_BLOBS_CONTENT); eventHub.$emit(SNIPPET_MEASURE_BLOBS_CONTENT);
......
<script> <script>
/* eslint-disable vue/no-v-html */ /* eslint-disable vue/no-v-html */
import { GlIcon } from '@gitlab/ui'; import { GlIcon } from '@gitlab/ui';
import EditorLite from '~/vue_shared/components/editor_lite.vue';
import { HIGHLIGHT_CLASS_NAME } from './constants'; import { HIGHLIGHT_CLASS_NAME } from './constants';
import ViewerMixin from './mixins'; import ViewerMixin from './mixins';
export default { export default {
components: { components: {
GlIcon, GlIcon,
EditorLite,
}, },
mixins: [ViewerMixin], mixins: [ViewerMixin],
inject: ['blobHash'], inject: ['blobHash'],
...@@ -45,27 +47,36 @@ export default { ...@@ -45,27 +47,36 @@ export default {
}; };
</script> </script>
<template> <template>
<div <div>
class="file-content code js-syntax-highlight" <editor-lite
data-qa-selector="file_content" v-if="isRawContent"
:class="$options.userColorScheme" :value="content"
> :file-name="fileName"
<div class="line-numbers"> :editor-options="{ readOnly: true }"
<a />
v-for="line in lineNumbers" <div
:id="`L${line}`" v-else
:key="line" class="file-content code js-syntax-highlight"
class="diff-line-num js-line-number" data-qa-selector="file_content"
:href="`#LC${line}`" :class="$options.userColorScheme"
:data-line-number="line" >
@click="scrollToLine(`#LC${line}`)" <div class="line-numbers">
> <a
<gl-icon :size="12" name="link" /> v-for="line in lineNumbers"
{{ line }} :id="`L${line}`"
</a> :key="line"
</div> class="diff-line-num js-line-number"
<div class="blob-content"> :href="`#LC${line}`"
<pre class="code highlight"><code :data-blob-hash="blobHash" v-html="content"></code></pre> :data-line-number="line"
@click="scrollToLine(`#LC${line}`)"
>
<gl-icon :size="12" name="link" />
{{ line }}
</a>
</div>
<div class="blob-content">
<pre class="code highlight"><code :data-blob-hash="blobHash" v-html="content"></code></pre>
</div>
</div> </div>
</div> </div>
</template> </template>
...@@ -76,6 +76,7 @@ describe('Blob content viewer component', () => { ...@@ -76,6 +76,7 @@ describe('Blob content viewer component', () => {
expect(findBlobContent().props('loading')).toEqual(false); expect(findBlobContent().props('loading')).toEqual(false);
expect(findBlobContent().props('content')).toEqual('raw content'); expect(findBlobContent().props('content')).toEqual('raw content');
expect(findBlobContent().props('isRawContent')).toBe(true);
expect(findBlobContent().props('activeViewer')).toEqual({ expect(findBlobContent().props('activeViewer')).toEqual({
fileType: 'text', fileType: 'text',
tooLarge: false, tooLarge: false,
......
import { shallowMount } from '@vue/test-utils';
import BlobContentViewer from '~/repository/components/blob_content_viewer.vue';
import BlobPage from '~/repository/pages/blob.vue';
jest.mock('~/repository/utils/dom');
describe('Repository blob page component', () => {
let wrapper;
const findBlobContentViewer = () => wrapper.find(BlobContentViewer);
const path = 'file.js';
beforeEach(() => {
wrapper = shallowMount(BlobPage, { propsData: { path } });
});
afterEach(() => {
wrapper.destroy();
});
it('has a Blob Content Viewer component', () => {
expect(findBlobContentViewer().exists()).toBe(true);
expect(findBlobContentViewer().props('path')).toBe(path);
});
});
// Jest Snapshot v1, https://goo.gl/fbAQLP // Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Blob Simple Viewer component rendering matches the snapshot 1`] = ` exports[`Blob Simple Viewer component rendering matches the snapshot 1`] = `
<div <div>
class="file-content code js-syntax-highlight"
data-qa-selector="file_content"
>
<div <div
class="line-numbers" class="file-content code js-syntax-highlight"
data-qa-selector="file_content"
> >
<a <div
class="diff-line-num js-line-number" class="line-numbers"
data-line-number="1"
href="#LC1"
id="L1"
> >
<gl-icon-stub <a
name="link" class="diff-line-num js-line-number"
size="12" data-line-number="1"
/> href="#LC1"
id="L1"
>
<gl-icon-stub
name="link"
size="12"
/>
1
1 </a>
<a
</a> class="diff-line-num js-line-number"
<a data-line-number="2"
class="diff-line-num js-line-number" href="#LC2"
data-line-number="2" id="L2"
href="#LC2" >
id="L2" <gl-icon-stub
> name="link"
<gl-icon-stub size="12"
name="link" />
size="12"
/> 2
2 </a>
<a
</a> class="diff-line-num js-line-number"
<a data-line-number="3"
class="diff-line-num js-line-number" href="#LC3"
data-line-number="3" id="L3"
href="#LC3" >
id="L3" <gl-icon-stub
> name="link"
<gl-icon-stub size="12"
name="link" />
size="12"
/> 3
3 </a>
</div>
</a>
</div> <div
class="blob-content"
<div
class="blob-content"
>
<pre
class="code highlight"
> >
<code <pre
data-blob-hash="foo-bar" class="code highlight"
> >
<span <code
id="LC1" data-blob-hash="foo-bar"
> >
First <span
</span> id="LC1"
>
First
</span>
<span <span
id="LC2" id="LC2"
> >
Second Second
</span> </span>
<span <span
id="LC3" id="LC3"
> >
Third Third
</span> </span>
</code> </code>
</pre> </pre>
</div>
</div> </div>
</div> </div>
`; `;
import { shallowMount } from '@vue/test-utils'; import { shallowMount } from '@vue/test-utils';
import { HIGHLIGHT_CLASS_NAME } from '~/vue_shared/components/blob_viewers/constants'; import { HIGHLIGHT_CLASS_NAME } from '~/vue_shared/components/blob_viewers/constants';
import SimpleViewer from '~/vue_shared/components/blob_viewers/simple_viewer.vue'; import SimpleViewer from '~/vue_shared/components/blob_viewers/simple_viewer.vue';
import EditorLite from '~/vue_shared/components/editor_lite.vue';
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'; const blobHash = 'foo-bar';
function createComponent(content = contentMock) { function createComponent(content = contentMock, isRawContent = false) {
wrapper = shallowMount(SimpleViewer, { wrapper = shallowMount(SimpleViewer, {
provide: { provide: {
blobHash, blobHash,
...@@ -15,6 +16,8 @@ describe('Blob Simple Viewer component', () => { ...@@ -15,6 +16,8 @@ describe('Blob Simple Viewer component', () => {
propsData: { propsData: {
content, content,
type: 'text', type: 'text',
fileName: 'test.js',
isRawContent,
}, },
}); });
} }
...@@ -83,4 +86,18 @@ describe('Blob Simple Viewer component', () => { ...@@ -83,4 +86,18 @@ describe('Blob Simple Viewer component', () => {
}); });
}); });
}); });
describe('raw content', () => {
const findEditorLite = () => wrapper.find(EditorLite);
const isRawContent = true;
it('uses the Editor Lite component in readonly mode when viewing raw content', () => {
createComponent('raw content', isRawContent);
expect(findEditorLite().exists()).toBe(true);
expect(findEditorLite().props('value')).toBe('raw content');
expect(findEditorLite().props('fileName')).toBe('test.js');
expect(findEditorLite().props('editorOptions')).toEqual({ readOnly: true });
});
});
}); });
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