2018-10-15 14:42:47 +05:30
|
|
|
import { getChangesCountForFiles, filePathMatches } from './utils';
|
2018-11-18 11:00:15 +05:30
|
|
|
import { activityBarViews, packageJsonPath } from '../constants';
|
2018-10-15 14:42:47 +05:30
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
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 projectsWithTrees = state =>
|
|
|
|
Object.keys(state.projects).map(projectId => {
|
|
|
|
const project = state.projects[projectId];
|
|
|
|
|
|
|
|
return {
|
|
|
|
...project,
|
|
|
|
branches: Object.keys(project.branches).map(branchId => {
|
|
|
|
const branch = project.branches[branchId];
|
|
|
|
|
|
|
|
return {
|
|
|
|
...branch,
|
|
|
|
tree: state.trees[branch.treeId],
|
|
|
|
};
|
|
|
|
}),
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
export const currentMergeRequest = state => {
|
2019-05-30 16:15:17 +05:30
|
|
|
if (state.projects[state.currentProjectId]) {
|
2018-05-09 12:01:36 +05:30
|
|
|
return state.projects[state.currentProjectId].mergeRequests[state.currentMergeRequestId];
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
export const currentProject = state => state.projects[state.currentProjectId];
|
|
|
|
|
|
|
|
export const currentTree = state =>
|
|
|
|
state.trees[`${state.currentProjectId}/${state.currentBranchId}`];
|
2018-05-09 12:01:36 +05:30
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
export const hasChanges = state => !!state.changedFiles.length || !!state.stagedFiles.length;
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
export const hasMergeRequest = state => !!state.currentMergeRequestId;
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
export const allBlobs = state =>
|
|
|
|
Object.keys(state.entries)
|
|
|
|
.reduce((acc, key) => {
|
|
|
|
const entry = state.entries[key];
|
|
|
|
|
|
|
|
if (entry.type === 'blob') {
|
|
|
|
acc.push(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}, [])
|
|
|
|
.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 lastOpenedFile = state =>
|
|
|
|
[...state.changedFiles, ...state.stagedFiles].sort((a, b) => b.lastOpenedAt - a.lastOpenedAt)[0];
|
|
|
|
|
|
|
|
export const isEditModeActive = state => state.currentActivityView === activityBarViews.edit;
|
|
|
|
export const isCommitModeActive = state => state.currentActivityView === activityBarViews.commit;
|
|
|
|
export const isReviewModeActive = state => state.currentActivityView === activityBarViews.review;
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
export const someUncommittedChanges = state =>
|
2018-10-15 14:42:47 +05:30
|
|
|
!!(state.changedFiles.length || state.stagedFiles.length);
|
|
|
|
|
|
|
|
export const getChangesInFolder = state => path => {
|
2018-11-18 11:00:15 +05:30
|
|
|
const changedFilesCount = state.changedFiles.filter(f => filePathMatches(f.path, path)).length;
|
2018-10-15 14:42:47 +05:30
|
|
|
const stagedFilesCount = state.stagedFiles.filter(
|
2018-11-18 11:00:15 +05:30
|
|
|
f => filePathMatches(f.path, path) && !getChangedFile(state)(f.path),
|
2018-10-15 14:42:47 +05:30
|
|
|
).length;
|
|
|
|
|
|
|
|
return changedFilesCount + stagedFilesCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getUnstagedFilesCountForPath = state => path =>
|
|
|
|
getChangesCountForFiles(state.changedFiles, path);
|
|
|
|
|
|
|
|
export const getStagedFilesCountForPath = state => path =>
|
|
|
|
getChangesCountForFiles(state.stagedFiles, path);
|
|
|
|
|
|
|
|
export const lastCommit = (state, getters) => {
|
2018-11-08 19:23:39 +05:30
|
|
|
const branch = getters.currentProject && getters.currentBranch;
|
2018-10-15 14:42:47 +05:30
|
|
|
|
|
|
|
return branch ? branch.commit : null;
|
|
|
|
};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
export const currentBranch = (state, getters) =>
|
|
|
|
getters.currentProject && getters.currentProject.branches[state.currentBranchId];
|
|
|
|
|
2018-11-18 11:00:15 +05:30
|
|
|
export const packageJson = state => state.entries[packageJsonPath];
|
|
|
|
|
2018-10-15 14:42:47 +05:30
|
|
|
// prevent babel-plugin-rewire from generating an invalid default during karma tests
|
|
|
|
export default () => {};
|