summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/getters.js
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-05-01 09:29:08 +0100
committerPhil Hughes <me@iamphill.com>2018-05-01 09:29:08 +0100
commitbec24d15813388440d172cf4f27d936130202a09 (patch)
tree97ad6b27ad2bb5434d6afcde10f8b94a95c1c933 /app/assets/javascripts/ide/stores/getters.js
parent87eb66e7b3823ed02f98d9d844717fedc06325d9 (diff)
downloadgitlab-ce-bec24d15813388440d172cf4f27d936130202a09.tar.gz
use getters to correctly get the counts for both unstaged & staged changes
Diffstat (limited to 'app/assets/javascripts/ide/stores/getters.js')
-rw-r--r--app/assets/javascripts/ide/stores/getters.js25
1 files changed, 25 insertions, 0 deletions
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 () => {};