Commit 029f7e6c authored by Phil Hughes's avatar Phil Hughes

removed file changes that have no changes to make diff easier

simplified SET_FILE_ACTIVE openFiles map
use .find in router so that it returns early instead of looping all the
values
parent af20c442
...@@ -87,8 +87,7 @@ export default { ...@@ -87,8 +87,7 @@ export default {
<div <div
class="multi-file-tab" class="multi-file-tab"
:class="{ :class="{
active: tab.active, active: tab.active
pending: tab.pending
}" }"
:title="tab.url" :title="tab.url"
> >
......
...@@ -77,16 +77,12 @@ router.beforeEach((to, from, next) => { ...@@ -77,16 +77,12 @@ router.beforeEach((to, from, next) => {
if (to.params[0]) { if (to.params[0]) {
const path = 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 = Object.keys(store.state.entries).reduce((acc, key) => { const treeEntryKey = Object.keys(store.state.entries).find(
const file = store.state.entries[key]; key => key === path && !store.state.entries[key].pending,
if (key === path && !file.pending) { );
return file; const treeEntry = store.state.entries[treeEntryKey];
}
return acc;
}, {});
if (Object.keys(treeEntry).length) { if (treeEntry) {
store.dispatch('handleTreeEntryAction', treeEntry); store.dispatch('handleTreeEntryAction', treeEntry);
} }
} }
......
...@@ -3,7 +3,7 @@ import { throttle } from 'underscore'; ...@@ -3,7 +3,7 @@ import { throttle } from 'underscore';
import DirtyDiffWorker from './diff_worker'; import DirtyDiffWorker from './diff_worker';
import Disposable from '../common/disposable'; import Disposable from '../common/disposable';
export const getDiffChangeType = change => { export const getDiffChangeType = (change) => {
if (change.modified) { if (change.modified) {
return 'modified'; return 'modified';
} else if (change.added) { } else if (change.added) {
...@@ -16,12 +16,15 @@ export const getDiffChangeType = change => { ...@@ -16,12 +16,15 @@ export const getDiffChangeType = change => {
}; };
export const getDecorator = change => ({ export const getDecorator = change => ({
range: new monaco.Range(change.lineNumber, 1, change.endLineNumber, 1), range: new monaco.Range(
change.lineNumber,
1,
change.endLineNumber,
1,
),
options: { options: {
isWholeLine: true, isWholeLine: true,
linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType( linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType(change)}`,
change,
)}`,
}, },
}); });
......
import { computeDiff } from './diff'; import { computeDiff } from './diff';
self.addEventListener('message', e => { self.addEventListener('message', (e) => {
const data = e.data; const data = e.data;
self.postMessage({ self.postMessage({
......
...@@ -2,7 +2,9 @@ import { normalizeHeaders } from '~/lib/utils/common_utils'; ...@@ -2,7 +2,9 @@ import { normalizeHeaders } from '~/lib/utils/common_utils';
import flash from '~/flash'; import flash from '~/flash';
import service from '../../services'; import service from '../../services';
import * as types from '../mutation_types'; import * as types from '../mutation_types';
import { findEntry } from '../utils'; import {
findEntry,
} from '../utils';
import FilesDecoratorWorker from '../workers/files_decorator_worker'; import FilesDecoratorWorker from '../workers/files_decorator_worker';
export const toggleTreeOpen = ({ commit, dispatch }, path) => { export const toggleTreeOpen = ({ commit, dispatch }, path) => {
...@@ -23,29 +25,20 @@ export const handleTreeEntryAction = ({ commit, dispatch }, row) => { ...@@ -23,29 +25,20 @@ export const handleTreeEntryAction = ({ commit, dispatch }, row) => {
} }
}; };
export const getLastCommitData = ( export const getLastCommitData = ({ state, commit, dispatch, getters }, tree = state) => {
{ state, commit, dispatch, getters },
tree = state,
) => {
if (!tree || tree.lastCommitPath === null || !tree.lastCommitPath) return; if (!tree || tree.lastCommitPath === null || !tree.lastCommitPath) return;
service service.getTreeLastCommit(tree.lastCommitPath)
.getTreeLastCommit(tree.lastCommitPath) .then((res) => {
.then(res => { const lastCommitPath = normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null;
const lastCommitPath =
normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null;
commit(types.SET_LAST_COMMIT_URL, { tree, url: lastCommitPath }); commit(types.SET_LAST_COMMIT_URL, { tree, url: lastCommitPath });
return res.json(); return res.json();
}) })
.then(data => { .then((data) => {
data.forEach(lastCommit => { data.forEach((lastCommit) => {
const entry = findEntry( const entry = findEntry(tree.tree, lastCommit.type, lastCommit.file_name);
tree.tree,
lastCommit.type,
lastCommit.file_name,
);
if (entry) { if (entry) {
commit(types.SET_LAST_COMMIT_DATA, { entry, lastCommit }); commit(types.SET_LAST_COMMIT_DATA, { entry, lastCommit });
...@@ -54,16 +47,13 @@ export const getLastCommitData = ( ...@@ -54,16 +47,13 @@ export const getLastCommitData = (
dispatch('getLastCommitData', tree); dispatch('getLastCommitData', tree);
}) })
.catch(() => .catch(() => flash('Error fetching log data.', 'alert', document, null, false, true));
flash('Error fetching log data.', 'alert', document, null, false, true),
);
}; };
export const getFiles = ( export const getFiles = (
{ state, commit, dispatch }, { state, commit, dispatch },
{ projectId, branchId } = {}, { projectId, branchId } = {},
) => ) => new Promise((resolve, reject) => {
new Promise((resolve, reject) => {
if (!state.trees[`${projectId}/${branchId}`]) { if (!state.trees[`${projectId}/${branchId}`]) {
const selectedProject = state.projects[projectId]; const selectedProject = state.projects[projectId];
commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` }); commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` });
...@@ -71,21 +61,15 @@ export const getFiles = ( ...@@ -71,21 +61,15 @@ export const getFiles = (
service service
.getFiles(selectedProject.web_url, branchId) .getFiles(selectedProject.web_url, branchId)
.then(res => res.json()) .then(res => res.json())
.then(data => { .then((data) => {
const worker = new FilesDecoratorWorker(); const worker = new FilesDecoratorWorker();
worker.addEventListener('message', e => { worker.addEventListener('message', (e) => {
const { entries, treeList } = e.data; const { entries, treeList } = e.data;
const selectedTree = state.trees[`${projectId}/${branchId}`]; const selectedTree = state.trees[`${projectId}/${branchId}`];
commit(types.SET_ENTRIES, entries); commit(types.SET_ENTRIES, entries);
commit(types.SET_DIRECTORY_DATA, { commit(types.SET_DIRECTORY_DATA, { treePath: `${projectId}/${branchId}`, data: treeList });
treePath: `${projectId}/${branchId}`, commit(types.TOGGLE_LOADING, { entry: selectedTree, forceValue: false });
data: treeList,
});
commit(types.TOGGLE_LOADING, {
entry: selectedTree,
forceValue: false,
});
worker.terminate(); worker.terminate();
...@@ -98,18 +82,12 @@ export const getFiles = ( ...@@ -98,18 +82,12 @@ export const getFiles = (
branchId, branchId,
}); });
}) })
.catch(e => { .catch((e) => {
flash( flash('Error loading tree data. Please try again.', 'alert', document, null, false, true);
'Error loading tree data. Please try again.',
'alert',
document,
null,
false,
true,
);
reject(e); reject(e);
}); });
} else { } else {
resolve(); resolve();
} }
}); });
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 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 => export const projectsWithTrees = state =>
Object.keys(state.projects).map(projectId => { Object.keys(state.projects).map(projectId => {
......
...@@ -8,13 +8,7 @@ export default { ...@@ -8,13 +8,7 @@ export default {
if (active && !state.entries[path].pending) { if (active && !state.entries[path].pending) {
Object.assign(state, { Object.assign(state, {
openFiles: state.openFiles.map(f => { openFiles: state.openFiles.map(f => Object.assign(f, { active: !(f.pending && f.active) })),
if (f.pending) {
return Object.assign(f, { active: false });
}
return f;
}),
}); });
} }
}, },
......
...@@ -720,7 +720,9 @@ ...@@ -720,7 +720,9 @@
} }
.ide-view { .ide-view {
height: calc(100vh - #{$header-height + $performance-bar-height + $flash-height}); height: calc(
100vh - #{$header-height + $performance-bar-height + $flash-height}
);
} }
} }
} }
......
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