summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipa Lacerda <filipa@gitlab.com>2017-10-20 19:30:05 +0000
committerFilipa Lacerda <filipa@gitlab.com>2017-10-20 19:30:05 +0000
commite1122c9f6daff16b900a0837d25789e1e5bdc56c (patch)
tree92e24cf5c600253a83df1a5bebd3d4a31df03b99
parent3b54907f13c52e76fa0dd81d20b045b21a79afe4 (diff)
parent741233321d93ed3d33938e5856658c4b321d69fe (diff)
downloadgitlab-ce-e1122c9f6daff16b900a0837d25789e1e5bdc56c.tar.gz
Merge branch 'multi-file-editor-submodules' into 'master'
Added submodule support in multi-file editor See merge request gitlab-org/gitlab-ce!14971
-rw-r--r--app/assets/javascripts/repo/components/repo_file.vue19
-rw-r--r--app/assets/javascripts/repo/components/repo_sidebar.vue4
-rw-r--r--app/assets/javascripts/repo/helpers/repo_helper.js4
-rw-r--r--app/serializers/submodule_entity.rb2
-rw-r--r--changelogs/unreleased/multi-file-editor-submodules.yml5
-rw-r--r--spec/javascripts/repo/components/repo_file_spec.js26
-rw-r--r--spec/javascripts/repo/components/repo_sidebar_spec.js15
-rw-r--r--spec/javascripts/repo/mock_data.js5
8 files changed, 75 insertions, 5 deletions
diff --git a/app/assets/javascripts/repo/components/repo_file.vue b/app/assets/javascripts/repo/components/repo_file.vue
index c7e69340f17..8c86e87ed3a 100644
--- a/app/assets/javascripts/repo/components/repo_file.vue
+++ b/app/assets/javascripts/repo/components/repo_file.vue
@@ -28,6 +28,9 @@
marginLeft: `${this.file.level * 16}px`,
};
},
+ shortId() {
+ return this.file.id.substr(0, 8);
+ },
},
methods: {
linkClicked(file) {
@@ -55,6 +58,17 @@
>
{{ file.name }}
</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>
<template v-if="!isMini">
@@ -69,7 +83,10 @@
</td>
<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) }}
</span>
</td>
diff --git a/app/assets/javascripts/repo/components/repo_sidebar.vue b/app/assets/javascripts/repo/components/repo_sidebar.vue
index 5832e603907..09dc9ee25d7 100644
--- a/app/assets/javascripts/repo/components/repo_sidebar.vue
+++ b/app/assets/javascripts/repo/components/repo_sidebar.vue
@@ -74,6 +74,10 @@ export default {
if (file.type === 'tree' && file.opened) {
Helper.setDirectoryToClosed(file);
Store.setActiveLine(lineNumber);
+ } else if (file.type === 'submodule') {
+ file.loading = true;
+
+ gl.utils.visitUrl(file.url);
} else {
const openFile = Helper.getFileFromPath(file.url);
diff --git a/app/assets/javascripts/repo/helpers/repo_helper.js b/app/assets/javascripts/repo/helpers/repo_helper.js
index 19425cedc90..f7b7f93e4b8 100644
--- a/app/assets/javascripts/repo/helpers/repo_helper.js
+++ b/app/assets/javascripts/repo/helpers/repo_helper.js
@@ -157,12 +157,14 @@ const RepoHelper = {
},
serializeRepoEntity(type, entity, level = 0) {
- const { url, name, icon, last_commit } = entity;
+ const { id, url, name, icon, last_commit, tree_url } = entity;
return {
+ id,
type,
name,
url,
+ tree_url,
level,
icon: `fa-${icon}`,
files: [],
diff --git a/app/serializers/submodule_entity.rb b/app/serializers/submodule_entity.rb
index 9a7eb5e7880..ed1f1ae0ef0 100644
--- a/app/serializers/submodule_entity.rb
+++ b/app/serializers/submodule_entity.rb
@@ -7,7 +7,7 @@ class SubmoduleEntity < Grape::Entity
'archive'
end
- expose :project_url do |blob|
+ expose :url do |blob|
submodule_links(blob, request).first
end
diff --git a/changelogs/unreleased/multi-file-editor-submodules.yml b/changelogs/unreleased/multi-file-editor-submodules.yml
new file mode 100644
index 00000000000..b83a50957c5
--- /dev/null
+++ b/changelogs/unreleased/multi-file-editor-submodules.yml
@@ -0,0 +1,5 @@
+---
+title: Added submodule support in multi-file editor
+merge_request:
+author:
+type: added
diff --git a/spec/javascripts/repo/components/repo_file_spec.js b/spec/javascripts/repo/components/repo_file_spec.js
index 334bf0997ca..107f6797f8a 100644
--- a/spec/javascripts/repo/components/repo_file_spec.js
+++ b/spec/javascripts/repo/components/repo_file_spec.js
@@ -93,6 +93,32 @@ describe('RepoFile', () => {
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('linkClicked', () => {
it('$emits fileNameClicked with file obj', () => {
diff --git a/spec/javascripts/repo/components/repo_sidebar_spec.js b/spec/javascripts/repo/components/repo_sidebar_spec.js
index 61283da8257..148f275e03d 100644
--- a/spec/javascripts/repo/components/repo_sidebar_spec.js
+++ b/spec/javascripts/repo/components/repo_sidebar_spec.js
@@ -117,6 +117,21 @@ describe('RepoSidebar', () => {
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', () => {
diff --git a/spec/javascripts/repo/mock_data.js b/spec/javascripts/repo/mock_data.js
index 836b867205e..71e275caf09 100644
--- a/spec/javascripts/repo/mock_data.js
+++ b/spec/javascripts/repo/mock_data.js
@@ -1,13 +1,14 @@
import RepoHelper from '~/repo/helpers/repo_helper';
// 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',
url: 'url',
name,
last_commit: {
id: '123',
message: 'test',
- committed_date: '',
+ committed_date: new Date().toISOString(),
},
});