Commit 5e2d50aa authored by Denys Mishunov's avatar Denys Mishunov

Passes file type down to ContentViewer

Instead of ContentViewer attempts to compute file type and render
appropriate viewer type, compute it on the parent RepoEditor having all
file-related information at its disposal and pass it down to
ContentViewer as a prop
parent a6a1afe0
<script>
import { mapState, mapGetters, mapActions } from 'vuex';
import { viewerInformationForPath } from '~/vue_shared/components/content_viewer/lib/viewer_utils';
import flash from '~/flash';
import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue';
import DiffViewer from '~/vue_shared/components/diff_viewer/diff_viewer.vue';
......@@ -56,6 +57,10 @@ export default {
active: this.file.viewMode === 'preview',
};
},
fileType() {
const info = viewerInformationForPath(this.file.path);
return (info && info.id) || '';
},
},
watch: {
file(newVal, oldVal) {
......@@ -258,6 +263,7 @@ export default {
:path="file.rawPath || file.path"
:file-size="file.size"
:project-path="file.projectId"
:type="fileType"
/>
<diff-viewer
v-if="showDiffViewer"
......
<script>
import { viewerInformationForPath } from './lib/viewer_utils';
import MarkdownViewer from './viewers/markdown_viewer.vue';
import ImageViewer from './viewers/image_viewer.vue';
import DownloadViewer from './viewers/download_viewer.vue';
......@@ -24,15 +23,18 @@ export default {
required: false,
default: '',
},
type: {
type: String,
required: false,
default: '',
},
},
computed: {
viewer() {
if (!this.path) return null;
if (!this.type) return DownloadViewer;
const previewInfo = viewerInformationForPath(this.path);
if (!previewInfo) return DownloadViewer;
switch (previewInfo.id) {
switch (this.type) {
case 'markdown':
return MarkdownViewer;
case 'image':
......
......@@ -4,6 +4,7 @@ import axios from '~/lib/utils/axios_utils';
import contentViewer from '~/vue_shared/components/content_viewer/content_viewer.vue';
import mountComponent from 'spec/helpers/vue_mount_component_helper';
import { GREEN_BOX_IMAGE_URL } from 'spec/test_constants';
import '~/behaviors/markdown/render_gfm';
describe('ContentViewer', () => {
let vm;
......@@ -29,6 +30,7 @@ describe('ContentViewer', () => {
path: 'test.md',
content: '* Test',
projectPath: 'testproject',
type: 'markdown',
});
const previewContainer = vm.$el.querySelector('.md-previewer');
......@@ -44,6 +46,7 @@ describe('ContentViewer', () => {
createComponent({
path: GREEN_BOX_IMAGE_URL,
fileSize: 1024,
type: 'image',
});
setTimeout(() => {
......
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