summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores/getters.js
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-05-01 14:18:23 +0100
committerPhil Hughes <me@iamphill.com>2018-05-01 14:18:23 +0100
commit55b91d94415e0323ec7b2ff63df3f73d532b6971 (patch)
tree8a96405a1becf5f10e0f595253e1557bdc0f418b /app/assets/javascripts/ide/stores/getters.js
parentcac07a46e0bf5bad363f259973e532fc73351a8f (diff)
downloadgitlab-ce-55b91d94415e0323ec7b2ff63df3f73d532b6971.tar.gz
fixed staged files not being recognised
reduced code duplication
Diffstat (limited to 'app/assets/javascripts/ide/stores/getters.js')
-rw-r--r--app/assets/javascripts/ide/stores/getters.js22
1 files changed, 7 insertions, 15 deletions
diff --git a/app/assets/javascripts/ide/stores/getters.js b/app/assets/javascripts/ide/stores/getters.js
index d316d5571ff..212974c00fe 100644
--- a/app/assets/javascripts/ide/stores/getters.js
+++ b/app/assets/javascripts/ide/stores/getters.js
@@ -1,4 +1,5 @@
import { __ } from '~/locale';
+import { getChangesCountForState, filePathMatches } from './utils';
export const activeFile = state => state.openFiles.find(file => file.active) || null;
@@ -59,28 +60,19 @@ export const getChangedFile = state => path => state.changedFiles.find(f => f.pa
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 changedFilesCount = state.changedFiles.filter(f => filePathMatches(f, path)).length;
const stagedFilesCount = state.stagedFiles.filter(
- f => filePathMatches(f) && !getChangedFile(state, f.path),
+ f => filePathMatches(f, path) && !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;
+export const getUnstagedFilesCountForPath = state => path =>
+ getChangesCountForState(state.changesFiles, path);
- 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;
-};
+export const getStagedFilesCountForPath = state => path =>
+ getChangesCountForState(state.stagedFiles, path);
// prevent babel-plugin-rewire from generating an invalid default during karma tests
export default () => {};