Commit c3dec96e authored by Phil Hughes's avatar Phil Hughes

Fixed bug when clicking file link causing user to navigate away

Adds a test for flattenedFiles
Changes the data method to not be an arrow method
Various other review fixes
parent 3dc1392d
...@@ -11,7 +11,9 @@ import Helper from '../helpers/repo_helper'; ...@@ -11,7 +11,9 @@ import Helper from '../helpers/repo_helper';
import MonacoLoaderHelper from '../helpers/monaco_loader_helper'; import MonacoLoaderHelper from '../helpers/monaco_loader_helper';
export default { export default {
data: () => Store, data() {
return Store;
},
mixins: [RepoMixin], mixins: [RepoMixin],
components: { components: {
RepoSidebar, RepoSidebar,
......
...@@ -9,7 +9,9 @@ import { visitUrl } from '../../lib/utils/url_utility'; ...@@ -9,7 +9,9 @@ import { visitUrl } from '../../lib/utils/url_utility';
export default { export default {
mixins: [RepoMixin], mixins: [RepoMixin],
data: () => Store, data() {
return Store;
},
components: { components: {
PopupDialog, PopupDialog,
......
...@@ -3,7 +3,9 @@ import Store from '../stores/repo_store'; ...@@ -3,7 +3,9 @@ import Store from '../stores/repo_store';
import RepoMixin from '../mixins/repo_mixin'; import RepoMixin from '../mixins/repo_mixin';
export default { export default {
data: () => Store, data() {
return Store;
},
mixins: [RepoMixin], mixins: [RepoMixin],
computed: { computed: {
buttonLabel() { buttonLabel() {
......
...@@ -5,7 +5,9 @@ import Service from '../services/repo_service'; ...@@ -5,7 +5,9 @@ import Service from '../services/repo_service';
import Helper from '../helpers/repo_helper'; import Helper from '../helpers/repo_helper';
const RepoEditor = { const RepoEditor = {
data: () => Store, data() {
return Store;
},
destroyed() { destroyed() {
if (Helper.monacoInstance) { if (Helper.monacoInstance) {
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
}, },
methods: { methods: {
linkClicked(file) { linkClicked(file) {
eventHub.$emit('linkclicked', file); eventHub.$emit('fileNameClicked', file);
}, },
}, },
}; };
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
<template> <template>
<tr <tr
class="file" class="file"
@click.stop="linkClicked(file)"> @click.prevent="linkClicked(file)">
<td> <td>
<i <i
class="fa fa-fw file-icon" class="fa fa-fw file-icon"
......
...@@ -4,7 +4,9 @@ import Helper from '../helpers/repo_helper'; ...@@ -4,7 +4,9 @@ import Helper from '../helpers/repo_helper';
import RepoMixin from '../mixins/repo_mixin'; import RepoMixin from '../mixins/repo_mixin';
const RepoFileButtons = { const RepoFileButtons = {
data: () => Store, data() {
return Store;
},
mixins: [RepoMixin], mixins: [RepoMixin],
......
...@@ -4,7 +4,9 @@ ...@@ -4,7 +4,9 @@
import Store from '../stores/repo_store'; import Store from '../stores/repo_store';
export default { export default {
data: () => Store, data() {
return Store;
},
computed: { computed: {
html() { html() {
return this.activeFile.html; return this.activeFile.html;
......
...@@ -20,15 +20,17 @@ export default { ...@@ -20,15 +20,17 @@ export default {
window.addEventListener('popstate', this.checkHistory); window.addEventListener('popstate', this.checkHistory);
}, },
destroyed() { destroyed() {
eventHub.$off('linkclicked', this.fileClicked); eventHub.$off('fileNameClicked', this.fileClicked);
eventHub.$off('goToPreviousDirectoryClicked', this.goToPreviousDirectoryClicked); eventHub.$off('goToPreviousDirectoryClicked', this.goToPreviousDirectoryClicked);
window.removeEventListener('popstate', this.checkHistory); window.removeEventListener('popstate', this.checkHistory);
}, },
mounted() { mounted() {
eventHub.$on('linkclicked', this.fileClicked); eventHub.$on('fileNameClicked', this.fileClicked);
eventHub.$on('goToPreviousDirectoryClicked', this.goToPreviousDirectoryClicked); eventHub.$on('goToPreviousDirectoryClicked', this.goToPreviousDirectoryClicked);
}, },
data: () => Store, data() {
return Store;
},
computed: { computed: {
flattendFiles() { flattendFiles() {
const mapFiles = arr => (!arr.files.length ? [] : _.map(arr.files, a => [a, mapFiles(a)])); const mapFiles = arr => (!arr.files.length ? [] : _.map(arr.files, a => [a, mapFiles(a)]));
......
...@@ -8,7 +8,9 @@ ...@@ -8,7 +8,9 @@
components: { components: {
'repo-tab': RepoTab, 'repo-tab': RepoTab,
}, },
data: () => Store, data() {
return Store;
},
}; };
</script> </script>
......
...@@ -55,18 +55,20 @@ const RepoHelper = { ...@@ -55,18 +55,20 @@ const RepoHelper = {
}, },
setDirectoryOpen(tree, title) { setDirectoryOpen(tree, title) {
const file = tree; if (!tree) return;
if (!file) return;
file.opened = true; Object.assign(tree, {
RepoHelper.updateHistoryEntry(file.url, title); opened: true,
});
RepoHelper.updateHistoryEntry(tree.url, title);
}, },
setDirectoryToClosed(entry) { setDirectoryToClosed(entry) {
const dir = entry; Object.assign(entry, {
opened: false,
dir.opened = false; files: [],
dir.files = []; });
}, },
isRenderable() { isRenderable() {
...@@ -156,7 +158,8 @@ const RepoHelper = { ...@@ -156,7 +158,8 @@ const RepoHelper = {
serializeRepoEntity(type, entity, level = 0) { serializeRepoEntity(type, entity, level = 0) {
const { url, name, icon, last_commit } = entity; const { url, name, icon, last_commit } = entity;
const returnObj = {
return {
type, type,
name, name,
url, url,
...@@ -165,20 +168,13 @@ const RepoHelper = { ...@@ -165,20 +168,13 @@ const RepoHelper = {
files: [], files: [],
loading: false, loading: false,
opened: false, opened: false,
}; // eslint-disable-next-line camelcase
lastCommit: last_commit ? {
// eslint-disable-next-line camelcase
if (last_commit) {
returnObj.lastCommit = {
url: `${Store.projectUrl}/commit/${last_commit.id}`, url: `${Store.projectUrl}/commit/${last_commit.id}`,
message: last_commit.message, message: last_commit.message,
updatedAt: last_commit.committed_date, updatedAt: last_commit.committed_date,
}; } : {},
} else { };
returnObj.lastCommit = {};
}
return returnObj;
}, },
scrollTabsRight() { scrollTabsRight() {
......
...@@ -36,7 +36,7 @@ class Projects::TreeController < Projects::ApplicationController ...@@ -36,7 +36,7 @@ class Projects::TreeController < Projects::ApplicationController
format.json do format.json do
page_title @path.presence || _("Files"), @ref, @project.name_with_namespace page_title @path.presence || _("Files"), @ref, @project.name_with_namespace
response.header['Is-Root'] = @path.empty? response.header['is-root'] = @path.empty?
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/38261 # n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/38261
Gitlab::GitalyClient.allow_n_plus_1_calls do Gitlab::GitalyClient.allow_n_plus_1_calls do
......
...@@ -69,6 +69,19 @@ describe('RepoSidebar', () => { ...@@ -69,6 +69,19 @@ describe('RepoSidebar', () => {
expect(vm.$el.querySelector('tbody .prev-directory')).toBeTruthy(); expect(vm.$el.querySelector('tbody .prev-directory')).toBeTruthy();
}); });
describe('flattendFiles', () => {
it('returns a flattend array of files', () => {
const f = file();
f.files.push(file('testing 123'));
const files = [f, file()];
vm = createComponent();
vm.files = files;
expect(vm.flattendFiles.length).toBe(3);
expect(vm.flattendFiles[1].name).toBe('testing 123');
});
});
describe('methods', () => { describe('methods', () => {
describe('fileClicked', () => { describe('fileClicked', () => {
it('should fetch data for new file', () => { it('should fetch data for new file', () => {
......
import RepoHelper from '~/repo/helpers/repo_helper'; import RepoHelper from '~/repo/helpers/repo_helper';
// eslint-disable-next-line import/prefer-default-export // eslint-disable-next-line import/prefer-default-export
export const file = () => RepoHelper.serializeRepoEntity('blob', { export const file = (name = 'name') => RepoHelper.serializeRepoEntity('blob', {
icon: 'icon', icon: 'icon',
url: 'url', url: 'url',
name: 'name', name,
last_commit: { last_commit: {
id: '123', id: '123',
message: 'test', message: 'test',
......
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