Commit 74123332 authored by Phil Hughes's avatar Phil Hughes

Added submodule support in multi-file editor

parent b4dc0ba2
...@@ -28,6 +28,9 @@ ...@@ -28,6 +28,9 @@
marginLeft: `${this.file.level * 16}px`, marginLeft: `${this.file.level * 16}px`,
}; };
}, },
shortId() {
return this.file.id.substr(0, 8);
},
}, },
methods: { methods: {
linkClicked(file) { linkClicked(file) {
...@@ -55,6 +58,17 @@ ...@@ -55,6 +58,17 @@
> >
{{ file.name }} {{ file.name }}
</a> </a>
<template v-if="file.type === 'submodule' && file.id">
@
<span class="commit-sha">
<a
@click.stop
:href="file.tree_url"
>
{{ shortId }}
</a>
</span>
</template>
</td> </td>
<template v-if="!isMini"> <template v-if="!isMini">
...@@ -69,7 +83,10 @@ ...@@ -69,7 +83,10 @@
</td> </td>
<td class="commit-update hidden-xs text-right"> <td class="commit-update hidden-xs text-right">
<span :title="tooltipTitle(file.lastCommit.updatedAt)"> <span
v-if="file.lastCommit.updatedAt"
:title="tooltipTitle(file.lastCommit.updatedAt)"
>
{{ timeFormated(file.lastCommit.updatedAt) }} {{ timeFormated(file.lastCommit.updatedAt) }}
</span> </span>
</td> </td>
......
...@@ -74,6 +74,10 @@ export default { ...@@ -74,6 +74,10 @@ export default {
if (file.type === 'tree' && file.opened) { if (file.type === 'tree' && file.opened) {
Helper.setDirectoryToClosed(file); Helper.setDirectoryToClosed(file);
Store.setActiveLine(lineNumber); Store.setActiveLine(lineNumber);
} else if (file.type === 'submodule') {
file.loading = true;
gl.utils.visitUrl(file.url);
} else { } else {
const openFile = Helper.getFileFromPath(file.url); const openFile = Helper.getFileFromPath(file.url);
......
...@@ -157,12 +157,14 @@ const RepoHelper = { ...@@ -157,12 +157,14 @@ const RepoHelper = {
}, },
serializeRepoEntity(type, entity, level = 0) { serializeRepoEntity(type, entity, level = 0) {
const { url, name, icon, last_commit } = entity; const { id, url, name, icon, last_commit, tree_url } = entity;
return { return {
id,
type, type,
name, name,
url, url,
tree_url,
level, level,
icon: `fa-${icon}`, icon: `fa-${icon}`,
files: [], files: [],
......
...@@ -7,7 +7,7 @@ class SubmoduleEntity < Grape::Entity ...@@ -7,7 +7,7 @@ class SubmoduleEntity < Grape::Entity
'archive' 'archive'
end end
expose :project_url do |blob| expose :url do |blob|
submodule_links(blob, request).first submodule_links(blob, request).first
end end
......
---
title: Added submodule support in multi-file editor
merge_request:
author:
type: added
...@@ -93,6 +93,32 @@ describe('RepoFile', () => { ...@@ -93,6 +93,32 @@ describe('RepoFile', () => {
expect(vm.linkClicked).toHaveBeenCalledWith(vm.file); expect(vm.linkClicked).toHaveBeenCalledWith(vm.file);
}); });
describe('submodule', () => {
let f;
let vm;
beforeEach(() => {
f = file('submodule name', '123456789');
f.type = 'submodule';
vm = createComponent({
file: f,
});
});
afterEach(() => {
vm.$destroy();
});
it('renders submodule short ID', () => {
expect(vm.$el.querySelector('.commit-sha').textContent.trim()).toBe('12345678');
});
it('renders ID next to submodule name', () => {
expect(vm.$el.querySelector('td').textContent.replace(/\s+/g, ' ')).toContain('submodule name @ 12345678');
});
});
describe('methods', () => { describe('methods', () => {
describe('linkClicked', () => { describe('linkClicked', () => {
it('$emits fileNameClicked with file obj', () => { it('$emits fileNameClicked with file obj', () => {
......
...@@ -117,6 +117,21 @@ describe('RepoSidebar', () => { ...@@ -117,6 +117,21 @@ describe('RepoSidebar', () => {
expect(Helper.setDirectoryToClosed).toHaveBeenCalledWith(RepoStore.files[0]); expect(Helper.setDirectoryToClosed).toHaveBeenCalledWith(RepoStore.files[0]);
}); });
describe('submodule', () => {
it('opens submodule project URL', () => {
spyOn(gl.utils, 'visitUrl');
const f = file();
f.type = 'submodule';
vm = createComponent();
vm.fileClicked(f);
expect(gl.utils.visitUrl).toHaveBeenCalledWith('url');
});
});
}); });
describe('goToPreviousDirectoryClicked', () => { describe('goToPreviousDirectoryClicked', () => {
......
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 = (name = 'name') => RepoHelper.serializeRepoEntity('blob', { export const file = (name = 'name', id = name) => RepoHelper.serializeRepoEntity('blob', {
id,
icon: 'icon', icon: 'icon',
url: 'url', url: 'url',
name, name,
last_commit: { last_commit: {
id: '123', id: '123',
message: 'test', message: 'test',
committed_date: '', committed_date: new Date().toISOString(),
}, },
}); });
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