diff options
Diffstat (limited to 'app/assets/javascripts/ide/stores')
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/file.js | 11 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/actions/tree.js | 10 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/getters.js | 25 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/mutation_types.js | 1 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/mutations/tree.js | 5 | ||||
-rw-r--r-- | app/assets/javascripts/ide/stores/utils.js | 2 |
6 files changed, 25 insertions, 29 deletions
diff --git a/app/assets/javascripts/ide/stores/actions/file.js b/app/assets/javascripts/ide/stores/actions/file.js index 288cb66515c..10c48e0a359 100644 --- a/app/assets/javascripts/ide/stores/actions/file.js +++ b/app/assets/javascripts/ide/stores/actions/file.js @@ -126,15 +126,8 @@ export const changeFileContent = ({ state, commit, dispatch, getters }, { path, if (file.changed && indexOfChangedFile === -1) { commit(types.ADD_FILE_TO_CHANGED, path); - - if (!stagedFile) { - dispatch('updateChangesCount', { path, count: +1 }); - } } else if (!file.changed && indexOfChangedFile !== -1) { commit(types.REMOVE_FILE_FROM_CHANGED, path); - if (!stagedFile) { - dispatch('updateChangesCount', { path, count: -1 }); - } } }; @@ -170,10 +163,6 @@ export const discardFileChanges = ({ dispatch, state, commit, getters }, path) = commit(types.DISCARD_FILE_CHANGES, path); commit(types.REMOVE_FILE_FROM_CHANGED, path); - if (!getters.getStagedFile(path)) { - dispatch('updateChangesCount', { path, count: -1 }); - } - if (file.tempFile && file.opened) { commit(types.TOGGLE_FILE_OPEN, path); } else if (getters.activeFile && file.path === getters.activeFile.path) { diff --git a/app/assets/javascripts/ide/stores/actions/tree.js b/app/assets/javascripts/ide/stores/actions/tree.js index 240f4d46c5a..6536be04f0a 100644 --- a/app/assets/javascripts/ide/stores/actions/tree.js +++ b/app/assets/javascripts/ide/stores/actions/tree.js @@ -93,13 +93,3 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } = resolve(); } }); - -export const updateChangesCount = ({ commit, dispatch, state }, { path, count }) => { - commit(types.UPDATE_FOLDER_CHANGE_COUNT, { path, count }); - - const parentPath = state.entries[path].parentPath; - - if (parentPath) { - dispatch('updateChangesCount', { path: parentPath, count }); - } -}; diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js index ec1ea155aee..d316d5571ff 100644 --- a/app/assets/javascripts/ide/stores/getters.js +++ b/app/assets/javascripts/ide/stores/getters.js @@ -55,7 +55,32 @@ export const allBlobs = state => }, []) .sort((a, b) => b.lastOpenedAt - a.lastOpenedAt); +export const getChangedFile = state => path => state.changedFiles.find(f => f.path === path); export const getStagedFile = state => path => state.stagedFiles.find(f => f.path === path); +export const getChangesInFolder = state => path => { + const filePathMatches = f => f.path.replace(new RegExp(`/${f.name}$`), '').indexOf(path) === 0; + const changedFilesCount = state.changedFiles.filter(f => filePathMatches(f)).length; + const stagedFilesCount = state.stagedFiles.filter( + f => filePathMatches(f) && !getChangedFile(state, f.path), + ).length; + + return changedFilesCount + stagedFilesCount; +}; + +export const getUnstagedFilesCountForPath = state => path => { + const filePathMatches = f => f.path.replace(new RegExp(`/${f.name}$`), '').indexOf(path) === 0; + const changedFilesCount = state.changedFiles.filter(f => filePathMatches(f)).length; + + return changedFilesCount; +}; + +export const getStagedFilesCountForPath = state => path => { + const filePathMatches = f => f.path.replace(new RegExp(`/${f.name}$`), '').indexOf(path) === 0; + const stagedFilesCount = state.stagedFiles.filter(f => filePathMatches(f)).length; + + return stagedFilesCount; +}; + // prevent babel-plugin-rewire from generating an invalid default during karma tests export default () => {}; diff --git a/app/assets/javascripts/ide/stores/mutation_types.js b/app/assets/javascripts/ide/stores/mutation_types.js index ae48035a291..f5c12db6db0 100644 --- a/app/assets/javascripts/ide/stores/mutation_types.js +++ b/app/assets/javascripts/ide/stores/mutation_types.js @@ -28,7 +28,6 @@ export const TOGGLE_TREE_OPEN = 'TOGGLE_TREE_OPEN'; export const SET_LAST_COMMIT_URL = 'SET_LAST_COMMIT_URL'; export const CREATE_TREE = 'CREATE_TREE'; export const REMOVE_ALL_CHANGES_FILES = 'REMOVE_ALL_CHANGES_FILES'; -export const UPDATE_FOLDER_CHANGE_COUNT = 'UPDATE_FOLDER_CHANGE_COUNT'; // File mutation types export const SET_FILE_DATA = 'SET_FILE_DATA'; diff --git a/app/assets/javascripts/ide/stores/mutations/tree.js b/app/assets/javascripts/ide/stores/mutations/tree.js index d8cf950a783..1176c040fb9 100644 --- a/app/assets/javascripts/ide/stores/mutations/tree.js +++ b/app/assets/javascripts/ide/stores/mutations/tree.js @@ -31,9 +31,4 @@ export default { changedFiles: [], }); }, - [types.UPDATE_FOLDER_CHANGE_COUNT](state, { path, count }) { - Object.assign(state.entries[path], { - changesCount: state.entries[path].changesCount + count, - }); - }, }; diff --git a/app/assets/javascripts/ide/stores/utils.js b/app/assets/javascripts/ide/stores/utils.js index 74f77bf678d..67d013fe3c4 100644 --- a/app/assets/javascripts/ide/stores/utils.js +++ b/app/assets/javascripts/ide/stores/utils.js @@ -33,7 +33,6 @@ export const dataStructure = () => ({ raw: '', content: '', parentTreeUrl: '', - parentPath: '', renderError: false, base64: false, editorRow: 1, @@ -44,7 +43,6 @@ export const dataStructure = () => ({ previewMode: null, size: 0, parentPath: null, - changesCount: 0, lastOpenedAt: 0, }); |