Commit 39bf8b82 authored by Samantha Ming's avatar Samantha Ming

Switch to use more GraphQL blob info

parent d164e450
...@@ -5,7 +5,6 @@ import PipelineTourSuccessModal from '~/blob/pipeline_tour_success_modal.vue'; ...@@ -5,7 +5,6 @@ import PipelineTourSuccessModal from '~/blob/pipeline_tour_success_modal.vue';
import BlobViewer from '~/blob/viewer/index'; import BlobViewer from '~/blob/viewer/index';
import GpgBadges from '~/gpg_badges'; import GpgBadges from '~/gpg_badges';
import createDefaultClient from '~/lib/graphql'; import createDefaultClient from '~/lib/graphql';
import { parseBoolean } from '~/lib/utils/common_utils';
import initBlob from '~/pages/projects/init_blob'; import initBlob from '~/pages/projects/init_blob';
import initWebIdeLink from '~/pages/projects/shared/web_ide_link'; import initWebIdeLink from '~/pages/projects/shared/web_ide_link';
import commitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue'; import commitPipelineStatus from '~/projects/tree/components/commit_pipeline_status_component.vue';
...@@ -21,14 +20,7 @@ const apolloProvider = new VueApollo({ ...@@ -21,14 +20,7 @@ const apolloProvider = new VueApollo({
const viewBlobEl = document.querySelector('#js-view-blob-app'); const viewBlobEl = document.querySelector('#js-view-blob-app');
if (viewBlobEl) { if (viewBlobEl) {
const { const { blobPath, projectPath, targetBranch, originalBranch } = viewBlobEl.dataset;
blobPath,
projectPath,
targetBranch,
originalBranch,
canPushCode,
replacePath,
} = viewBlobEl.dataset;
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
...@@ -37,8 +29,6 @@ if (viewBlobEl) { ...@@ -37,8 +29,6 @@ if (viewBlobEl) {
provide: { provide: {
targetBranch, targetBranch,
originalBranch, originalBranch,
canPushCode: parseBoolean(canPushCode),
replacePath,
}, },
render(createElement) { render(createElement) {
return createElement(BlobContentViewer, { return createElement(BlobContentViewer, {
......
...@@ -135,7 +135,13 @@ export default { ...@@ -135,7 +135,13 @@ export default {
:edit-path="blobInfo.editBlobPath" :edit-path="blobInfo.editBlobPath"
:web-ide-path="blobInfo.ideEditPath" :web-ide-path="blobInfo.ideEditPath"
/> />
<blob-replace v-if="isLoggedIn" :name="blobInfo.name" :path="path" /> <blob-replace
v-if="isLoggedIn"
:path="path"
:name="blobInfo.name"
:replace-path="blobInfo.replacePath"
:can-push-code="blobInfo.canModifyBlob"
/>
</template> </template>
</blob-header> </blob-header>
<blob-content <blob-content
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlButton, GlModalDirective } from '@gitlab/ui'; import { GlButton, GlModalDirective } from '@gitlab/ui';
import { uniqueId } from 'lodash'; import { uniqueId } from 'lodash';
import { sprintf, __ } from '~/locale'; import { sprintf, __ } from '~/locale';
import getRefMixin from '../mixins/get_ref';
import UploadBlobModal from './upload_blob_modal.vue'; import UploadBlobModal from './upload_blob_modal.vue';
export default { export default {
...@@ -16,6 +17,7 @@ export default { ...@@ -16,6 +17,7 @@ export default {
directives: { directives: {
GlModal: GlModalDirective, GlModal: GlModalDirective,
}, },
mixins: [getRefMixin],
inject: { inject: {
targetBranch: { targetBranch: {
default: '', default: '',
...@@ -23,12 +25,6 @@ export default { ...@@ -23,12 +25,6 @@ export default {
originalBranch: { originalBranch: {
default: '', default: '',
}, },
canPushCode: {
default: false,
},
replacePath: {
default: null,
},
}, },
props: { props: {
name: { name: {
...@@ -39,6 +35,14 @@ export default { ...@@ -39,6 +35,14 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
replacePath: {
type: String,
required: true,
},
canPushCode: {
type: Boolean,
required: true,
},
}, },
computed: { computed: {
replaceModalId() { replaceModalId() {
...@@ -60,8 +64,8 @@ export default { ...@@ -60,8 +64,8 @@ export default {
:modal-id="replaceModalId" :modal-id="replaceModalId"
:modal-title="title" :modal-title="title"
:commit-message="title" :commit-message="title"
:target-branch="targetBranch" :target-branch="targetBranch || ref"
:original-branch="originalBranch" :original-branch="originalBranch || ref"
:can-push-code="canPushCode" :can-push-code="canPushCode"
:path="path" :path="path"
:replace-path="replacePath" :replace-path="replacePath"
......
...@@ -6,7 +6,7 @@ export default { ...@@ -6,7 +6,7 @@ export default {
query: refQuery, query: refQuery,
manual: true, manual: true,
result({ data, loading }) { result({ data, loading }) {
if (!loading) { if (data && !loading) {
this.ref = data.ref; this.ref = data.ref;
this.escapedRef = data.escapedRef; this.escapedRef = data.escapedRef;
} }
......
...@@ -15,6 +15,7 @@ query getBlobInfo($projectPath: ID!, $filePath: String!) { ...@@ -15,6 +15,7 @@ query getBlobInfo($projectPath: ID!, $filePath: String!) {
storedExternally storedExternally
rawPath rawPath
replacePath replacePath
canModifyBlob
simpleViewer { simpleViewer {
fileType fileType
tooLarge tooLarge
......
...@@ -19,9 +19,7 @@ ...@@ -19,9 +19,7 @@
#js-view-blob-app{ data: { blob_path: blob.path, #js-view-blob-app{ data: { blob_path: blob.path,
project_path: @project.full_path, project_path: @project.full_path,
target_branch: project.empty_repo? ? ref : @ref, target_branch: project.empty_repo? ? ref : @ref,
original_branch: @ref, original_branch: @ref } }
can_push_code: can?(current_user, :push_code, @project).to_s,
replace_path: project_update_blob_path(@project, @id) } }
.gl-spinner-container .gl-spinner-container
= loading_icon(size: 'md') = loading_icon(size: 'md')
- else - else
......
...@@ -5,13 +5,13 @@ import UploadBlobModal from '~/repository/components/upload_blob_modal.vue'; ...@@ -5,13 +5,13 @@ import UploadBlobModal from '~/repository/components/upload_blob_modal.vue';
const DEFAULT_PROPS = { const DEFAULT_PROPS = {
name: 'some name', name: 'some name',
path: 'some/path', path: 'some/path',
canPushCode: true,
replacePath: 'some/replace/path',
}; };
const DEFAULT_INJECT = { const DEFAULT_INJECT = {
targetBranch: 'master', targetBranch: 'master',
originalBranch: 'master', originalBranch: 'master',
canPushCode: true,
replacePath: 'some/replace/path',
}; };
describe('BlobReplace component', () => { describe('BlobReplace component', () => {
...@@ -49,8 +49,8 @@ describe('BlobReplace component', () => { ...@@ -49,8 +49,8 @@ describe('BlobReplace component', () => {
it('renders UploadBlobModal', () => { it('renders UploadBlobModal', () => {
createComponent(); createComponent();
const { targetBranch, originalBranch, canPushCode, replacePath } = DEFAULT_INJECT; const { targetBranch, originalBranch } = DEFAULT_INJECT;
const { name, path } = DEFAULT_PROPS; const { name, path, canPushCode, replacePath } = DEFAULT_PROPS;
const title = `Replace ${name}`; const title = `Replace ${name}`;
expect(findUploadBlobModal().props()).toMatchObject({ expect(findUploadBlobModal().props()).toMatchObject({
......
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