Commit 336bbd9d authored by Jacques Erasmus's avatar Jacques Erasmus Committed by Simon Knox

Add blob content viewer

Added blob content viewer to the app
parent 825552bb
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { uniqueId } from 'lodash';
import BlobContent from '~/blob/components/blob_content.vue';
import BlobHeader from '~/blob/components/blob_header.vue';
import createFlash from '~/flash';
import { __ } from '~/locale';
import blobInfoQuery from '../queries/blob_info.query.graphql';
import projectPathQuery from '../queries/project_path.query.graphql';
export default {
components: {
BlobHeader,
BlobContent,
GlLoadingIcon,
},
apollo: {
projectPath: {
query: projectPathQuery,
},
blobInfo: {
query: blobInfoQuery,
variables() {
return {
projectPath: this.projectPath,
filePath: this.path,
};
},
error() {
createFlash({ message: __('An error occurred while loading the file. Please try again.') });
},
},
},
provide() {
return {
blobHash: uniqueId(),
};
},
data() {
return {
projectPath: '',
blobInfo: {
name: '',
size: '',
rawBlob: '',
type: '',
fileType: '',
tooLarge: false,
path: '',
editBlobPath: '',
ideEditPath: '',
storedExternally: false,
rawPath: '',
externalStorageUrl: '',
replacePath: '',
deletePath: '',
canLock: false,
isLocked: false,
lockLink: '',
canModifyBlob: true,
forkPath: '',
simpleViewer: '',
richViewer: '',
},
};
},
computed: {
isLoading() {
return this.$apollo.queries.blobInfo.loading;
},
viewer() {
const { fileType, tooLarge, type } = this.blobInfo;
return { fileType, tooLarge, type };
},
},
};
</script>
<template>
<div>
<gl-loading-icon v-if="isLoading" />
<div v-if="blobInfo && !isLoading">
<blob-header :blob="blobInfo" />
<blob-content
:blob="blobInfo"
:content="blobInfo.rawBlob"
:active-viewer="viewer"
:loading="false"
/>
</div>
</div>
</template>
query getBlobInfo($projectPath: ID!, $filePath: String!) {
project(fullPath: $projectPath) {
id
repository {
blobs(path: $filePath) {
name
size
rawBlob
type
fileType
tooLarge
path
editBlobPath
ideEditPath
storedExternally
rawPath
externalStorageUrl
replacePath
deletePath
canLock
isLocked
lockLink
canModifyBlob
forkPath
simpleViewer
richViewer
}
}
}
}
...@@ -4,3 +4,4 @@ filenames: ...@@ -4,3 +4,4 @@ filenames:
- ee/app/assets/javascripts/security_configuration/api_fuzzing/graphql/api_fuzzing_ci_configuration.query.graphql - ee/app/assets/javascripts/security_configuration/api_fuzzing/graphql/api_fuzzing_ci_configuration.query.graphql
- ee/app/assets/javascripts/security_configuration/api_fuzzing/graphql/create_api_fuzzing_configuration.mutation.graphql - ee/app/assets/javascripts/security_configuration/api_fuzzing/graphql/create_api_fuzzing_configuration.mutation.graphql
- ee/app/assets/javascripts/security_configuration/dast_profiles/graphql/dast_failed_site_validations.query.graphql - ee/app/assets/javascripts/security_configuration/dast_profiles/graphql/dast_failed_site_validations.query.graphql
- app/assets/javascripts/repository/queries/blob_info.query.graphql
...@@ -3533,6 +3533,9 @@ msgstr "" ...@@ -3533,6 +3533,9 @@ msgstr ""
msgid "An error occurred while loading the file. Please try again later." msgid "An error occurred while loading the file. Please try again later."
msgstr "" msgstr ""
msgid "An error occurred while loading the file. Please try again."
msgstr ""
msgid "An error occurred while loading the merge request changes." msgid "An error occurred while loading the merge request changes."
msgstr "" msgstr ""
......
import { GlLoadingIcon } from '@gitlab/ui';
import { shallowMount } from '@vue/test-utils';
import BlobContent from '~/blob/components/blob_content.vue';
import BlobHeader from '~/blob/components/blob_header.vue';
import BlobContentViewer from '~/repository/components/blob_content_viewer.vue';
let wrapper;
const mockData = {
name: 'some_file.js',
size: 123,
rawBlob: 'raw content',
type: 'text',
fileType: 'text',
tooLarge: false,
path: 'some_file.js',
editBlobPath: 'some_file.js/edit',
ideEditPath: 'some_file.js/ide/edit',
storedExternally: false,
rawPath: 'some_file.js',
externalStorageUrl: 'some_file.js',
replacePath: 'some_file.js/replace',
deletePath: 'some_file.js/delete',
canLock: true,
isLocked: false,
lockLink: 'some_file.js/lock',
canModifyBlob: true,
forkPath: 'some_file.js/fork',
simpleViewer: {},
richViewer: {},
};
function factory(path, loading = false) {
wrapper = shallowMount(BlobContentViewer, {
propsData: {
path,
},
mocks: {
$apollo: {
queries: {
blobInfo: {
loading,
},
},
},
},
});
wrapper.setData({ blobInfo: mockData });
}
describe('Blob content viewer component', () => {
const findLoadingIcon = () => wrapper.find(GlLoadingIcon);
const findBlobHeader = () => wrapper.find(BlobHeader);
const findBlobContent = () => wrapper.find(BlobContent);
afterEach(() => {
wrapper.destroy();
});
beforeEach(() => {
factory('some_file.js');
});
it('renders a GlLoadingIcon component', () => {
factory('some_file.js', true);
expect(findLoadingIcon().exists()).toBe(true);
});
it('renders a BlobHeader component', () => {
expect(findBlobHeader().exists()).toBe(true);
});
it('renders a BlobContent component', () => {
expect(findBlobContent().exists()).toBe(true);
expect(findBlobContent().props('loading')).toEqual(false);
expect(findBlobContent().props('content')).toEqual('raw content');
expect(findBlobContent().props('activeViewer')).toEqual({
fileType: 'text',
tooLarge: false,
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