summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Zallmann <tzallmann@gitlab.com>2018-03-25 20:05:54 +0200
committerTim Zallmann <tzallmann@gitlab.com>2018-03-25 20:05:54 +0200
commitc93744de25ad57e89454cfe60491d5802e56a37c (patch)
treeb2ee99cf08d77eab8a79198e257d5b72e2f78a82
parent1bb1c6a0eae6d2253b3b4c7cf6ae509e0eca5710 (diff)
downloadgitlab-ce-c93744de25ad57e89454cfe60491d5802e56a37c.tar.gz
ESLint + Karma fixes
-rw-r--r--app/assets/javascripts/ide/components/editor_mode_dropdown.vue7
-rw-r--r--app/assets/javascripts/ide/ide_router.js16
-rw-r--r--app/assets/javascripts/ide/services/index.js5
-rw-r--r--app/assets/javascripts/ide/stores/actions/file.js32
-rw-r--r--app/assets/javascripts/ide/stores/getters.js16
-rw-r--r--app/assets/javascripts/ide/stores/utils.js32
-rw-r--r--spec/javascripts/ide/components/changed_file_icon_spec.js15
7 files changed, 40 insertions, 83 deletions
diff --git a/app/assets/javascripts/ide/components/editor_mode_dropdown.vue b/app/assets/javascripts/ide/components/editor_mode_dropdown.vue
index 42b00b5d9df..1b0526b9ea5 100644
--- a/app/assets/javascripts/ide/components/editor_mode_dropdown.vue
+++ b/app/assets/javascripts/ide/components/editor_mode_dropdown.vue
@@ -79,7 +79,12 @@ export default {
</span>
</a>
</li>
- <li v-if="hasMergeRequest" role="separator" class="divider"></li>
+ <li
+ v-if="hasMergeRequest"
+ role="separator"
+ class="divider"
+ >
+ </li>
<li>
<a
href="#"
diff --git a/app/assets/javascripts/ide/ide_router.js b/app/assets/javascripts/ide/ide_router.js
index 4f1c5988fc5..8f8f413e6cc 100644
--- a/app/assets/javascripts/ide/ide_router.js
+++ b/app/assets/javascripts/ide/ide_router.js
@@ -2,7 +2,6 @@ import Vue from 'vue';
import VueRouter from 'vue-router';
import flash from '~/flash';
import store from './stores';
-import { getTreeEntry } from './stores/utils';
Vue.use(VueRouter);
@@ -77,9 +76,7 @@ router.beforeEach((to, from, next) => {
.then(() => {
if (to.params[0]) {
const path =
- to.params[0].slice(-1) === '/'
- ? to.params[0].slice(0, -1)
- : to.params[0];
+ to.params[0].slice(-1) === '/' ? to.params[0].slice(0, -1) : to.params[0];
const treeEntry = store.state.entries[path];
if (treeEntry) {
store.dispatch('handleTreeEntryAction', treeEntry);
@@ -130,8 +127,7 @@ router.beforeEach((to, from, next) => {
})
.then(() => {
mrChanges.changes.forEach((change, ind) => {
- const changeTreeEntry =
- store.state.entries[change.new_path];
+ const changeTreeEntry = store.state.entries[change.new_path];
if (changeTreeEntry) {
store.dispatch('setFileMrChange', {
@@ -156,16 +152,12 @@ router.beforeEach((to, from, next) => {
});
})
.catch(e => {
- flash(
- 'Error while loading the merge request changes. Please try again.',
- );
+ flash('Error while loading the merge request changes. Please try again.');
throw e;
});
})
.catch(e => {
- flash(
- 'Error while loading the branch files. Please try again.',
- );
+ flash('Error while loading the branch files. Please try again.');
throw e;
});
})
diff --git a/app/assets/javascripts/ide/services/index.js b/app/assets/javascripts/ide/services/index.js
index b86a20e6abf..6e6ebf3169f 100644
--- a/app/assets/javascripts/ide/services/index.js
+++ b/app/assets/javascripts/ide/services/index.js
@@ -1,7 +1,6 @@
import Vue from 'vue';
import VueResource from 'vue-resource';
import Api from '~/api';
-import { version } from 'punycode';
Vue.use(VueResource);
@@ -21,9 +20,7 @@ export default {
return Promise.resolve(file.raw);
}
- return Vue.http
- .get(file.rawPath, { params: { format: 'json' } })
- .then(res => res.text());
+ return Vue.http.get(file.rawPath, { params: { format: 'json' } }).then(res => res.text());
},
getBaseRawFileData(file, sha) {
if (file.tempFile) {
diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js
index 79ae5568d57..d7701463605 100644
--- a/app/assets/javascripts/ide/stores/actions/file.js
+++ b/app/assets/javascripts/ide/stores/actions/file.js
@@ -1,11 +1,10 @@
import { normalizeHeaders } from '~/lib/utils/common_utils';
-import { parsePatch, applyPatches } from 'diff';
import flash from '~/flash';
import eventHub from '../../eventhub';
import service from '../../services';
import * as types from '../mutation_types';
import router from '../../ide_router';
-import { setPageTitle, createTemp, findIndexOfFile } from '../utils';
+import { setPageTitle } from '../utils';
export const closeFile = ({ commit, state, getters, dispatch }, path) => {
const indexOfClosedFile = state.openFiles.findIndex(f => f.path === path);
@@ -47,19 +46,14 @@ export const setFileActive = ({ commit, state, getters, dispatch }, path) => {
commit(types.SET_CURRENT_BRANCH, file.branchId);
};
-export const getFileData = (
- { state, commit, dispatch },
- { path, makeFileActive = true },
-) => {
+export const getFileData = ({ state, commit, dispatch }, { path, makeFileActive = true }) => {
const file = state.entries[path];
return new Promise((resolve, reject) => {
commit(types.TOGGLE_LOADING, { entry: file });
service
.getFileData(file.url)
.then(res => {
- const pageTitle = decodeURI(
- normalizeHeaders(res.headers)['PAGE-TITLE'],
- );
+ const pageTitle = decodeURI(normalizeHeaders(res.headers)['PAGE-TITLE']);
setPageTitle(pageTitle);
@@ -72,16 +66,8 @@ export const getFileData = (
commit(types.TOGGLE_LOADING, { entry: file });
})
.catch(err => {
- console.log('Error : ', err);
commit(types.TOGGLE_LOADING, { entry: file });
- flash(
- 'Error loading file data. Please try again.',
- 'alert',
- document,
- null,
- false,
- true,
- );
+ flash('Error loading file data. Please try again.', 'alert', document, null, false, true);
reject(err);
});
});
@@ -91,10 +77,7 @@ export const setFileMrChange = ({ state, commit }, { file, mrChange }) => {
commit(types.SET_FILE_MR_CHANGE, { file, mrChange });
};
-export const getRawFileData = (
- { state, commit, dispatch },
- { path, baseSha },
-) => {
+export const getRawFileData = ({ state, commit, dispatch }, { path, baseSha }) => {
const file = state.entries[path];
return new Promise((resolve, reject) => {
service
@@ -150,10 +133,7 @@ export const setFileEOL = ({ getters, commit }, { eol }) => {
}
};
-export const setEditorPosition = (
- { getters, commit },
- { editorRow, editorColumn },
-) => {
+export const setEditorPosition = ({ getters, commit }, { editorRow, editorColumn }) => {
if (getters.activeFile) {
commit(types.SET_FILE_POSITION, {
file: getters.activeFile,
diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js
index 3eea9e57056..a77cdbc13c8 100644
--- a/app/assets/javascripts/ide/stores/getters.js
+++ b/app/assets/javascripts/ide/stores/getters.js
@@ -1,10 +1,8 @@
-export const activeFile = state =>
- state.openFiles.find(file => file.active) || null;
+export const activeFile = state => state.openFiles.find(file => file.active) || null;
export const addedFiles = state => state.changedFiles.filter(f => f.tempFile);
-export const modifiedFiles = state =>
- state.changedFiles.filter(f => !f.tempFile);
+export const modifiedFiles = state => state.changedFiles.filter(f => !f.tempFile);
export const projectsWithTrees = state =>
Object.keys(state.projects).map(projectId => {
@@ -23,10 +21,12 @@ export const projectsWithTrees = state =>
};
});
-export const currentMergeRequest = state =>
- state.projects[state.currentProjectId].mergeRequests[
- state.currentMergeRequestId
- ];
+export const currentMergeRequest = state => {
+ if (state.projects[state.currentProjectId]) {
+ return state.projects[state.currentProjectId].mergeRequests[state.currentMergeRequestId];
+ }
+ return null;
+};
// eslint-disable-next-line no-confusing-arrow
export const currentIcon = state =>
diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js
index cb0b1354665..3389eeeaa2e 100644
--- a/app/assets/javascripts/ide/stores/utils.js
+++ b/app/assets/javascripts/ide/stores/utils.js
@@ -82,40 +82,10 @@ export const decorateData = entity => {
};
};
-/*
- Takes the multi-dimensional tree and returns a flattened array.
- This allows for the table to recursively render the table rows but keeps the data
- structure nested to make it easier to add new files/directories.
-*/
-export const treeList = (state, treeId) => {
- const baseTree = state.trees[treeId];
- if (baseTree) {
- const mapTree = arr =>
- !arr.tree || !arr.tree.length
- ? []
- : _.map(arr.tree, a => [a, mapTree(a)]);
-
- return _.chain(baseTree.tree)
- .map(arr => [arr, mapTree(arr)])
- .flatten()
- .value();
- }
- return [];
-};
-
-export const getTree = state => (namespace, projectId, branch) =>
- state.trees[`${namespace}/${projectId}/${branch}`];
-
-export const getTreeEntry = (store, treeId, path) => {
- const fileList = treeList(store.state, treeId);
- return fileList ? fileList.find(file => file.path === path) : null;
-};
-
export const findEntry = (tree, type, name, prop = 'name') =>
tree.find(f => f.type === type && f[prop] === name);
-export const findIndexOfFile = (state, file) =>
- state.findIndex(f => f.path === file.path);
+export const findIndexOfFile = (state, file) => state.findIndex(f => f.path === file.path);
export const setPageTitle = title => {
document.title = title;
diff --git a/spec/javascripts/ide/components/changed_file_icon_spec.js b/spec/javascripts/ide/components/changed_file_icon_spec.js
index 987aea7befc..1e3c8fa95c4 100644
--- a/spec/javascripts/ide/components/changed_file_icon_spec.js
+++ b/spec/javascripts/ide/components/changed_file_icon_spec.js
@@ -11,6 +11,7 @@ describe('IDE changed file icon', () => {
vm = createComponent(component, {
file: {
tempFile: false,
+ changed: true,
},
});
});
@@ -20,10 +21,16 @@ describe('IDE changed file icon', () => {
});
describe('changedIcon', () => {
- it('equals file-modified when not a temp file', () => {
+ it('equals file-modified when not a temp file and has changes', () => {
expect(vm.changedIcon).toBe('file-modified');
});
+ it('equals git-merge when not a temp file and has no changes', () => {
+ vm.file.changed = false;
+
+ expect(vm.changedIcon).toBe('git-merge');
+ });
+
it('equals file-addition when a temp file', () => {
vm.file.tempFile = true;
@@ -36,6 +43,12 @@ describe('IDE changed file icon', () => {
expect(vm.changedIconClass).toContain('multi-file-modified');
});
+ it('includes multi-git-merge when a mr changed file', () => {
+ vm.file.changed = false;
+
+ expect(vm.changedIconClass).toContain('multi-git-merge');
+ });
+
it('includes multi-file-addition when a temp file', () => {
vm.file.tempFile = true;