From 029f7e6cd87ec0d59b85f12b57ee3c3a889dac1f Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Wed, 28 Mar 2018 13:05:26 +0100 Subject: [PATCH] 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 --- .../javascripts/ide/components/repo_tab.vue | 3 +- app/assets/javascripts/ide/ide_router.js | 14 +-- .../javascripts/ide/lib/diff/controller.js | 13 ++- .../javascripts/ide/lib/diff/diff_worker.js | 2 +- .../javascripts/ide/stores/actions/tree.js | 110 +++++++----------- app/assets/javascripts/ide/stores/getters.js | 6 +- .../javascripts/ide/stores/mutations/file.js | 8 +- app/assets/stylesheets/pages/repo.scss | 4 +- 8 files changed, 67 insertions(+), 93 deletions(-) diff --git a/app/assets/javascripts/ide/components/repo_tab.vue b/app/assets/javascripts/ide/components/repo_tab.vue index f82588219cc..6e65e55e1f6 100644 --- a/app/assets/javascripts/ide/components/repo_tab.vue +++ b/app/assets/javascripts/ide/components/repo_tab.vue @@ -87,8 +87,7 @@ export default {
diff --git a/app/assets/javascripts/ide/ide_router.js b/app/assets/javascripts/ide/ide_router.js index 25f55ac2f8a..a6013784677 100644 --- a/app/assets/javascripts/ide/ide_router.js +++ b/app/assets/javascripts/ide/ide_router.js @@ -77,16 +77,12 @@ router.beforeEach((to, from, next) => { if (to.params[0]) { const path = 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 file = store.state.entries[key]; - if (key === path && !file.pending) { - return file; - } + const treeEntryKey = Object.keys(store.state.entries).find( + key => key === path && !store.state.entries[key].pending, + ); + const treeEntry = store.state.entries[treeEntryKey]; - return acc; - }, {}); - - if (Object.keys(treeEntry).length) { + if (treeEntry) { store.dispatch('handleTreeEntryAction', treeEntry); } } diff --git a/app/assets/javascripts/ide/lib/diff/controller.js b/app/assets/javascripts/ide/lib/diff/controller.js index 1af358a6467..b136545ad11 100644 --- a/app/assets/javascripts/ide/lib/diff/controller.js +++ b/app/assets/javascripts/ide/lib/diff/controller.js @@ -3,7 +3,7 @@ import { throttle } from 'underscore'; import DirtyDiffWorker from './diff_worker'; import Disposable from '../common/disposable'; -export const getDiffChangeType = change => { +export const getDiffChangeType = (change) => { if (change.modified) { return 'modified'; } else if (change.added) { @@ -16,12 +16,15 @@ export const getDiffChangeType = 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: { isWholeLine: true, - linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType( - change, - )}`, + linesDecorationsClassName: `dirty-diff dirty-diff-${getDiffChangeType(change)}`, }, }); diff --git a/app/assets/javascripts/ide/lib/diff/diff_worker.js b/app/assets/javascripts/ide/lib/diff/diff_worker.js index ba9e270d5f0..e74c4046330 100644 --- a/app/assets/javascripts/ide/lib/diff/diff_worker.js +++ b/app/assets/javascripts/ide/lib/diff/diff_worker.js @@ -1,6 +1,6 @@ import { computeDiff } from './diff'; -self.addEventListener('message', e => { +self.addEventListener('message', (e) => { const data = e.data; self.postMessage({ diff --git a/app/assets/javascripts/ide/stores/actions/tree.js b/app/assets/javascripts/ide/stores/actions/tree.js index b3edce08c34..70a969a0325 100644 --- a/app/assets/javascripts/ide/stores/actions/tree.js +++ b/app/assets/javascripts/ide/stores/actions/tree.js @@ -2,7 +2,9 @@ import { normalizeHeaders } from '~/lib/utils/common_utils'; import flash from '~/flash'; import service from '../../services'; import * as types from '../mutation_types'; -import { findEntry } from '../utils'; +import { + findEntry, +} from '../utils'; import FilesDecoratorWorker from '../workers/files_decorator_worker'; export const toggleTreeOpen = ({ commit, dispatch }, path) => { @@ -23,29 +25,20 @@ export const handleTreeEntryAction = ({ commit, dispatch }, row) => { } }; -export const getLastCommitData = ( - { state, commit, dispatch, getters }, - tree = state, -) => { +export const getLastCommitData = ({ state, commit, dispatch, getters }, tree = state) => { if (!tree || tree.lastCommitPath === null || !tree.lastCommitPath) return; - service - .getTreeLastCommit(tree.lastCommitPath) - .then(res => { - const lastCommitPath = - normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null; + service.getTreeLastCommit(tree.lastCommitPath) + .then((res) => { + const lastCommitPath = normalizeHeaders(res.headers)['MORE-LOGS-URL'] || null; commit(types.SET_LAST_COMMIT_URL, { tree, url: lastCommitPath }); return res.json(); }) - .then(data => { - data.forEach(lastCommit => { - const entry = findEntry( - tree.tree, - lastCommit.type, - lastCommit.file_name, - ); + .then((data) => { + data.forEach((lastCommit) => { + const entry = findEntry(tree.tree, lastCommit.type, lastCommit.file_name); if (entry) { commit(types.SET_LAST_COMMIT_DATA, { entry, lastCommit }); @@ -54,62 +47,47 @@ export const getLastCommitData = ( dispatch('getLastCommitData', tree); }) - .catch(() => - flash('Error fetching log data.', 'alert', document, null, false, true), - ); + .catch(() => flash('Error fetching log data.', 'alert', document, null, false, true)); }; export const getFiles = ( { state, commit, dispatch }, { projectId, branchId } = {}, -) => - new Promise((resolve, reject) => { - if (!state.trees[`${projectId}/${branchId}`]) { - const selectedProject = state.projects[projectId]; - commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` }); +) => new Promise((resolve, reject) => { + if (!state.trees[`${projectId}/${branchId}`]) { + const selectedProject = state.projects[projectId]; + commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` }); - service - .getFiles(selectedProject.web_url, branchId) - .then(res => res.json()) - .then(data => { - const worker = new FilesDecoratorWorker(); - worker.addEventListener('message', e => { - const { entries, treeList } = e.data; - const selectedTree = state.trees[`${projectId}/${branchId}`]; + service + .getFiles(selectedProject.web_url, branchId) + .then(res => res.json()) + .then((data) => { + const worker = new FilesDecoratorWorker(); + worker.addEventListener('message', (e) => { + const { entries, treeList } = e.data; + const selectedTree = state.trees[`${projectId}/${branchId}`]; - commit(types.SET_ENTRIES, entries); - commit(types.SET_DIRECTORY_DATA, { - treePath: `${projectId}/${branchId}`, - data: treeList, - }); - commit(types.TOGGLE_LOADING, { - entry: selectedTree, - forceValue: false, - }); + commit(types.SET_ENTRIES, entries); + commit(types.SET_DIRECTORY_DATA, { treePath: `${projectId}/${branchId}`, data: treeList }); + commit(types.TOGGLE_LOADING, { entry: selectedTree, forceValue: false }); - worker.terminate(); + worker.terminate(); - resolve(); - }); - - worker.postMessage({ - data, - projectId, - branchId, - }); - }) - .catch(e => { - flash( - 'Error loading tree data. Please try again.', - 'alert', - document, - null, - false, - true, - ); - reject(e); + resolve(); }); - } else { - resolve(); - } - }); + + worker.postMessage({ + data, + projectId, + branchId, + }); + }) + .catch((e) => { + flash('Error loading tree data. Please try again.', 'alert', document, null, false, true); + reject(e); + }); + } else { + resolve(); + } +}); + diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js index a7e43a6dd2f..eba325a31df 100644 --- a/app/assets/javascripts/ide/stores/getters.js +++ b/app/assets/javascripts/ide/stores/getters.js @@ -1,8 +1,10 @@ -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 => { diff --git a/app/assets/javascripts/ide/stores/mutations/file.js b/app/assets/javascripts/ide/stores/mutations/file.js index f8d0262e120..db3893b97d4 100644 --- a/app/assets/javascripts/ide/stores/mutations/file.js +++ b/app/assets/javascripts/ide/stores/mutations/file.js @@ -8,13 +8,7 @@ export default { if (active && !state.entries[path].pending) { Object.assign(state, { - openFiles: state.openFiles.map(f => { - if (f.pending) { - return Object.assign(f, { active: false }); - } - - return f; - }), + openFiles: state.openFiles.map(f => Object.assign(f, { active: !(f.pending && f.active) })), }); } }, diff --git a/app/assets/stylesheets/pages/repo.scss b/app/assets/stylesheets/pages/repo.scss index fcb35e2e67f..65046f6665e 100644 --- a/app/assets/stylesheets/pages/repo.scss +++ b/app/assets/stylesheets/pages/repo.scss @@ -720,7 +720,9 @@ } .ide-view { - height: calc(100vh - #{$header-height + $performance-bar-height + $flash-height}); + height: calc( + 100vh - #{$header-height + $performance-bar-height + $flash-height} + ); } } }