Commit d64452eb authored by Phil Hughes's avatar Phil Hughes

Merge branch '57984-store-branch-name' into 'master'

Resolves "Branch name is lost if I change commit mode in Web IDE"

Closes #57984

See merge request gitlab-org/gitlab-ce!26180
parents 9e98ccf1 a72241f4
...@@ -38,8 +38,8 @@ export default { ...@@ -38,8 +38,8 @@ export default {
}, },
}, },
computed: { computed: {
...mapState('commit', ['commitAction']), ...mapState('commit', ['commitAction', 'newBranchName']),
...mapGetters('commit', ['newBranchName']), ...mapGetters('commit', ['placeholderBranchName']),
tooltipTitle() { tooltipTitle() {
return this.disabled ? this.title : ''; return this.disabled ? this.title : '';
}, },
...@@ -73,7 +73,8 @@ export default { ...@@ -73,7 +73,8 @@ export default {
</label> </label>
<div v-if="commitAction === value && showInput" class="ide-commit-new-branch"> <div v-if="commitAction === value && showInput" class="ide-commit-new-branch">
<input <input
:placeholder="newBranchName" :placeholder="placeholderBranchName"
:value="newBranchName"
type="text" type="text"
class="form-control monospace" class="form-control monospace"
@input="updateBranchName($event.target.value)" @input="updateBranchName($event.target.value)"
......
...@@ -14,7 +14,7 @@ const createTranslatedTextForFiles = (files, text) => { ...@@ -14,7 +14,7 @@ const createTranslatedTextForFiles = (files, text) => {
export const discardDraftButtonDisabled = state => export const discardDraftButtonDisabled = state =>
state.commitMessage === '' || state.submitCommitLoading; state.commitMessage === '' || state.submitCommitLoading;
export const newBranchName = (state, _, rootState) => export const placeholderBranchName = (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,
)}`; )}`;
...@@ -25,7 +25,7 @@ export const branchName = (state, getters, rootState) => { ...@@ -25,7 +25,7 @@ export const branchName = (state, getters, rootState) => {
state.commitAction === consts.COMMIT_TO_NEW_BRANCH_MR state.commitAction === consts.COMMIT_TO_NEW_BRANCH_MR
) { ) {
if (state.newBranchName === '') { if (state.newBranchName === '') {
return getters.newBranchName; return getters.placeholderBranchName;
} }
return state.newBranchName; return state.newBranchName;
......
---
title: Resolves Branch name is lost if I change commit mode in Web IDE
merge_request: 26180
author:
type: fixed
...@@ -76,6 +76,7 @@ describe('IDE commit sidebar radio group', () => { ...@@ -76,6 +76,7 @@ describe('IDE commit sidebar radio group', () => {
const Component = Vue.extend(radioGroup); const Component = Vue.extend(radioGroup);
store.state.commit.commitAction = '1'; store.state.commit.commitAction = '1';
store.state.commit.newBranchName = 'test-123';
vm = createComponentWithStore(Component, store, { vm = createComponentWithStore(Component, store, {
value: '1', value: '1',
...@@ -113,6 +114,12 @@ describe('IDE commit sidebar radio group', () => { ...@@ -113,6 +114,12 @@ describe('IDE commit sidebar radio group', () => {
done(); done();
}); });
}); });
it('renders newBranchName if present', () => {
const input = vm.$el.querySelector('.form-control');
expect(input.value).toBe('test-123');
});
}); });
describe('tooltipTitle', () => { describe('tooltipTitle', () => {
......
...@@ -396,7 +396,7 @@ describe('IDE commit module actions', () => { ...@@ -396,7 +396,7 @@ describe('IDE commit module actions', () => {
.then(() => { .then(() => {
expect(visitUrl).toHaveBeenCalledWith( expect(visitUrl).toHaveBeenCalledWith(
`webUrl/merge_requests/new?merge_request[source_branch]=${ `webUrl/merge_requests/new?merge_request[source_branch]=${
store.getters['commit/newBranchName'] store.getters['commit/placeholderBranchName']
}&merge_request[target_branch]=master`, }&merge_request[target_branch]=master`,
); );
......
...@@ -29,11 +29,11 @@ describe('IDE commit module getters', () => { ...@@ -29,11 +29,11 @@ describe('IDE commit module getters', () => {
}); });
}); });
describe('newBranchName', () => { describe('placeholderBranchName', () => {
it('includes username, currentBranchId, patch & random number', () => { it('includes username, currentBranchId, patch & random number', () => {
gon.current_username = 'username'; gon.current_username = 'username';
const branch = getters.newBranchName(state, null, { const branch = getters.placeholderBranchName(state, null, {
currentBranchId: 'testing', currentBranchId: 'testing',
}); });
...@@ -46,7 +46,7 @@ describe('IDE commit module getters', () => { ...@@ -46,7 +46,7 @@ describe('IDE commit module getters', () => {
currentBranchId: 'master', currentBranchId: 'master',
}; };
const localGetters = { const localGetters = {
newBranchName: 'newBranchName', placeholderBranchName: 'newBranchName',
}; };
beforeEach(() => { beforeEach(() => {
...@@ -71,7 +71,7 @@ describe('IDE commit module getters', () => { ...@@ -71,7 +71,7 @@ describe('IDE commit module getters', () => {
expect(getters.branchName(state, localGetters, rootState)).toBe('state-newBranchName'); expect(getters.branchName(state, localGetters, rootState)).toBe('state-newBranchName');
}); });
it('uses getters newBranchName when state newBranchName is empty', () => { it('uses placeholderBranchName when state newBranchName is empty', () => {
Object.assign(state, { Object.assign(state, {
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