Commit f00a971a authored by Tim Zallmann's avatar Tim Zallmann

ESLint + Karma fixes

parent fa3b0241
......@@ -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="#"
......
......@@ -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;
});
})
......
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) {
......
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,
......
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 =>
......
......@@ -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;
......
......@@ -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;
......
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