Commit e08ce52a authored by Phil Hughes's avatar Phil Hughes

Improve Web IDE commit form

Closes #47307
parent e055cb47
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
...mapState(['changedFiles', 'stagedFiles', 'currentActivityView', 'lastCommitMsg']), ...mapState(['changedFiles', 'stagedFiles', 'currentActivityView', 'lastCommitMsg']),
...mapState('commit', ['commitMessage', 'submitCommitLoading']), ...mapState('commit', ['commitMessage', 'submitCommitLoading']),
...mapGetters(['hasChanges']), ...mapGetters(['hasChanges']),
...mapGetters('commit', ['commitButtonDisabled', 'discardDraftButtonDisabled']), ...mapGetters('commit', ['discardDraftButtonDisabled']),
overviewText() { overviewText() {
return sprintf( return sprintf(
__( __(
...@@ -36,6 +36,9 @@ export default { ...@@ -36,6 +36,9 @@ export default {
}, },
); );
}, },
commitButtonText() {
return this.stagedFiles.length ? __('Commit') : __('Stage & Commit');
},
}, },
watch: { watch: {
currentActivityView() { currentActivityView() {
...@@ -142,8 +145,7 @@ export default { ...@@ -142,8 +145,7 @@ export default {
<actions /> <actions />
<loading-button <loading-button
:loading="submitCommitLoading" :loading="submitCommitLoading"
:disabled="commitButtonDisabled" :label="commitButtonText"
:label="__('Commit')"
container-class="btn btn-success btn-sm float-left" container-class="btn btn-success btn-sm float-left"
@click="commitChanges" @click="commitChanges"
/> />
......
...@@ -28,7 +28,7 @@ export default { ...@@ -28,7 +28,7 @@ export default {
]), ]),
...mapState('commit', ['commitMessage', 'submitCommitLoading']), ...mapState('commit', ['commitMessage', 'submitCommitLoading']),
...mapGetters(['lastOpenedFile', 'hasChanges', 'someUncommitedChanges', 'activeFile']), ...mapGetters(['lastOpenedFile', 'hasChanges', 'someUncommitedChanges', 'activeFile']),
...mapGetters('commit', ['commitButtonDisabled', 'discardDraftButtonDisabled']), ...mapGetters('commit', ['discardDraftButtonDisabled']),
showStageUnstageArea() { showStageUnstageArea() {
return !!(this.someUncommitedChanges || this.lastCommitMsg || !this.unusedSeal); return !!(this.someUncommitedChanges || this.lastCommitMsg || !this.unusedSeal);
}, },
......
...@@ -109,11 +109,14 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo ...@@ -109,11 +109,14 @@ export const commitChanges = ({ commit, state, getters, dispatch, rootState, roo
state, state,
rootState, rootState,
}); });
const stageFilesPromise = rootState.stagedFiles.length
? Promise.resolve()
: dispatch('stageAllChanges', null, { root: true });
commit(types.UPDATE_LOADING, true); commit(types.UPDATE_LOADING, true);
return service return stageFilesPromise
.commit(rootState.currentProjectId, payload) .then(() => service.commit(rootState.currentProjectId, payload))
.then(({ data }) => { .then(({ data }) => {
commit(types.UPDATE_LOADING, false); commit(types.UPDATE_LOADING, false);
......
...@@ -5,9 +5,6 @@ const BRANCH_SUFFIX_COUNT = 5; ...@@ -5,9 +5,6 @@ const BRANCH_SUFFIX_COUNT = 5;
export const discardDraftButtonDisabled = state => export const discardDraftButtonDisabled = state =>
state.commitMessage === '' || state.submitCommitLoading; state.commitMessage === '' || state.submitCommitLoading;
export const commitButtonDisabled = (state, getters, rootState) =>
getters.discardDraftButtonDisabled || !rootState.stagedFiles.length;
export const newBranchName = (state, _, rootState) => export const newBranchName = (state, _, rootState) =>
`${gon.current_username}-${rootState.currentBranchId}-patch-${`${new Date().getTime()}`.substr( `${gon.current_username}-${rootState.currentBranchId}-patch-${`${new Date().getTime()}`.substr(
-BRANCH_SUFFIX_COUNT, -BRANCH_SUFFIX_COUNT,
......
...@@ -29,46 +29,6 @@ describe('IDE commit module getters', () => { ...@@ -29,46 +29,6 @@ describe('IDE commit module getters', () => {
}); });
}); });
describe('commitButtonDisabled', () => {
const localGetters = {
discardDraftButtonDisabled: false,
};
const rootState = {
stagedFiles: ['a'],
};
it('returns false when discardDraftButtonDisabled is false & stagedFiles is not empty', () => {
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeFalsy();
});
it('returns true when discardDraftButtonDisabled is false & stagedFiles is empty', () => {
rootState.stagedFiles.length = 0;
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeTruthy();
});
it('returns true when discardDraftButtonDisabled is true', () => {
localGetters.discardDraftButtonDisabled = true;
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeTruthy();
});
it('returns true when discardDraftButtonDisabled is false & changedFiles is not empty', () => {
localGetters.discardDraftButtonDisabled = false;
rootState.stagedFiles.length = 0;
expect(
getters.commitButtonDisabled(state, localGetters, rootState),
).toBeTruthy();
});
});
describe('newBranchName', () => { describe('newBranchName', () => {
it('includes username, currentBranchId, patch & random number', () => { it('includes username, currentBranchId, patch & random number', () => {
gon.current_username = 'username'; gon.current_username = 'username';
...@@ -108,9 +68,7 @@ describe('IDE commit module getters', () => { ...@@ -108,9 +68,7 @@ describe('IDE commit module getters', () => {
}); });
it('uses newBranchName when not empty', () => { it('uses newBranchName when not empty', () => {
expect(getters.branchName(state, localGetters, rootState)).toBe( expect(getters.branchName(state, localGetters, rootState)).toBe('state-newBranchName');
'state-newBranchName',
);
}); });
it('uses getters newBranchName when state newBranchName is empty', () => { it('uses getters newBranchName when state newBranchName is empty', () => {
...@@ -118,9 +76,7 @@ describe('IDE commit module getters', () => { ...@@ -118,9 +76,7 @@ describe('IDE commit module getters', () => {
newBranchName: '', newBranchName: '',
}); });
expect(getters.branchName(state, localGetters, rootState)).toBe( expect(getters.branchName(state, localGetters, rootState)).toBe('newBranchName');
'newBranchName',
);
}); });
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment