BigW Consortium Gitlab

Commit 9f3bf824 by Sam Beckham Committed by Phil Hughes

Resolve "Remove links from Web IDE unexpectedly navigate you to a different page"

parent b8198897
<script> <script>
import { __ } from '~/locale';
import tooltip from '~/vue_shared/directives/tooltip';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
export default { export default {
components: { components: {
Icon, Icon,
}, },
directives: {
tooltip,
},
props: { props: {
file: { file: {
type: Object, type: Object,
...@@ -18,12 +13,7 @@ export default { ...@@ -18,12 +13,7 @@ export default {
}, },
computed: { computed: {
showButtons() { showButtons() {
return ( return this.file.permalink;
this.file.rawPath || this.file.blamePath || this.file.commitsPath || this.file.permalink
);
},
rawDownloadButtonLabel() {
return this.file.binary ? __('Download') : __('Raw');
}, },
}, },
}; };
...@@ -32,51 +22,18 @@ export default { ...@@ -32,51 +22,18 @@ export default {
<template> <template>
<div <div
v-if="showButtons" v-if="showButtons"
class="float-right ide-btn-group" class="pull-right ide-btn-group"
> >
<a <a
v-tooltip
v-if="!file.binary"
:href="file.blamePath"
:title="__('Blame')"
class="btn btn-sm btn-transparent blame"
>
<icon
name="blame"
:size="16"
/>
</a>
<a
v-tooltip
:href="file.commitsPath"
:title="__('History')"
class="btn btn-sm btn-transparent history"
>
<icon
name="history"
:size="16"
/>
</a>
<a
v-tooltip
:href="file.permalink" :href="file.permalink"
:title="__('Permalink')"
class="btn btn-sm btn-transparent permalink"
>
<icon
name="link"
:size="16"
/>
</a>
<a
v-tooltip
:href="file.rawPath"
target="_blank" target="_blank"
class="btn btn-sm btn-transparent prepend-left-10 raw" :title="s__('IDE|Open in file view')"
rel="noopener noreferrer" rel="noopener noreferrer"
:title="rawDownloadButtonLabel"> >
<span class="vertical-align-middle">Open in file view</span>
<icon <icon
name="download" name="external-link"
css-classes="vertical-align-middle space-right"
:size="16" :size="16"
/> />
</a> </a>
......
...@@ -6,12 +6,12 @@ import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer ...@@ -6,12 +6,12 @@ import ContentViewer from '~/vue_shared/components/content_viewer/content_viewer
import { activityBarViews, viewerTypes } from '../constants'; import { activityBarViews, viewerTypes } from '../constants';
import monacoLoader from '../monaco_loader'; import monacoLoader from '../monaco_loader';
import Editor from '../lib/editor'; import Editor from '../lib/editor';
import IdeFileButtons from './ide_file_buttons.vue'; import ExternalLink from './external_link.vue';
export default { export default {
components: { components: {
ContentViewer, ContentViewer,
IdeFileButtons, ExternalLink,
}, },
props: { props: {
file: { file: {
...@@ -224,7 +224,7 @@ export default { ...@@ -224,7 +224,7 @@ export default {
</a> </a>
</li> </li>
</ul> </ul>
<ide-file-buttons <external-link
:file="file" :file="file"
/> />
</div> </div>
......
---
title: Change the IDE file buttons for an "Open in file view" button
merge_request: 19129
author: Sam Beckham
type: changed
import Vue from 'vue'; import Vue from 'vue';
import repoFileButtons from '~/ide/components/ide_file_buttons.vue'; import externalLink from '~/ide/components/external_link.vue';
import createVueComponent from '../../helpers/vue_mount_component_helper'; import createVueComponent from '../../helpers/vue_mount_component_helper';
import { file } from '../helpers'; import { file } from '../helpers';
describe('RepoFileButtons', () => { describe('ExternalLink', () => {
const activeFile = file(); const activeFile = file();
let vm; let vm;
function createComponent() { function createComponent() {
const RepoFileButtons = Vue.extend(repoFileButtons); const ExternalLink = Vue.extend(externalLink);
activeFile.rawPath = 'test'; activeFile.permalink = 'test';
activeFile.blamePath = 'test';
activeFile.commitsPath = 'test';
return createVueComponent(RepoFileButtons, { return createVueComponent(ExternalLink, {
file: activeFile, file: activeFile,
}); });
} }
...@@ -23,38 +21,14 @@ describe('RepoFileButtons', () => { ...@@ -23,38 +21,14 @@ describe('RepoFileButtons', () => {
vm.$destroy(); vm.$destroy();
}); });
it('renders Raw, Blame, History and Permalink', done => { it('renders the external link with the correct href', done => {
vm = createComponent();
vm.$nextTick(() => {
const raw = vm.$el.querySelector('.raw');
const blame = vm.$el.querySelector('.blame');
const history = vm.$el.querySelector('.history');
expect(raw.href).toMatch(`/${activeFile.rawPath}`);
expect(raw.getAttribute('data-original-title')).toEqual('Raw');
expect(blame.href).toMatch(`/${activeFile.blamePath}`);
expect(blame.getAttribute('data-original-title')).toEqual('Blame');
expect(history.href).toMatch(`/${activeFile.commitsPath}`);
expect(history.getAttribute('data-original-title')).toEqual('History');
expect(vm.$el.querySelector('.permalink').getAttribute('data-original-title')).toEqual(
'Permalink',
);
done();
});
});
it('renders Download', done => {
activeFile.binary = true; activeFile.binary = true;
vm = createComponent(); vm = createComponent();
vm.$nextTick(() => { vm.$nextTick(() => {
const raw = vm.$el.querySelector('.raw'); const openLink = vm.$el.querySelector('a');
expect(raw.href).toMatch(`/${activeFile.rawPath}`);
expect(raw.getAttribute('data-original-title')).toEqual('Download');
expect(openLink.href).toMatch(`/${activeFile.permalink}`);
done(); done();
}); });
}); });
......
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