Commit 5d5579b3 authored by Phil Hughes's avatar Phil Hughes

don't reload the full page

instead it just pushes a router & re-fetches what it needs
parent e815c68d
...@@ -4,7 +4,7 @@ import { __, sprintf } from '~/locale'; ...@@ -4,7 +4,7 @@ import { __, sprintf } from '~/locale';
import service from '../../services'; import service from '../../services';
import api from '../../../api'; import api from '../../../api';
import * as types from '../mutation_types'; import * as types from '../mutation_types';
import { refreshCurrentPage } from '../../../lib/utils/url_utility'; import router from '../../ide_router';
export const getProjectData = ({ commit, state }, { namespace, projectId, force = false } = {}) => export const getProjectData = ({ commit, state }, { namespace, projectId, force = false } = {}) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
...@@ -91,19 +91,24 @@ export const refreshLastCommitData = ({ commit }, { projectId, branchId } = {}) ...@@ -91,19 +91,24 @@ export const refreshLastCommitData = ({ commit }, { projectId, branchId } = {})
flash(__('Error loading last commit.'), 'alert', document, null, false, true); flash(__('Error loading last commit.'), 'alert', document, null, false, true);
}); });
export const createNewBranchFromDefault = ({ state, getters }, branch) => export const createNewBranchFromDefault = ({ state, dispatch, getters }, branch) =>
api api
.createBranch(state.currentProjectId, { .createBranch(state.currentProjectId, {
ref: getters.currentProject.default_branch, ref: getters.currentProject.default_branch,
branch, branch,
}) })
.then(() => { .then(() => {
refreshCurrentPage(); dispatch('setErrorMessage', null);
router.push(`${router.currentRoute.path}?${Date.now()}`);
// this forces the loading icon to spin whilst the page is reloading
return new Promise(() => {});
}) })
.catch(() => {}); .catch(() => {
dispatch('setErrorMessage', {
text: __('An error occured creating the new branch.'),
action: 'createNewBranchFromDefault',
actionText: __('Please try again'),
actionPayload: branch,
});
});
export const showBranchNotFoundError = ({ dispatch }, branchId) => { export const showBranchNotFoundError = ({ dispatch }, branchId) => {
dispatch('setErrorMessage', { dispatch('setErrorMessage', {
......
import { normalizeHeaders } from '~/lib/utils/common_utils'; import { normalizeHeaders } from '~/lib/utils/common_utils';
import flash from '~/flash'; import flash from '~/flash';
import { __ } from '../../../locale';
import service from '../../services'; import service from '../../services';
import * as types from '../mutation_types'; import * as types from '../mutation_types';
import { findEntry } from '../utils'; import { findEntry } from '../utils';
...@@ -64,7 +65,11 @@ export const getLastCommitData = ({ state, commit, dispatch }, tree = state) => ...@@ -64,7 +65,11 @@ export const getLastCommitData = ({ state, commit, dispatch }, tree = state) =>
export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } = {}) => export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } = {}) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
if (!state.trees[`${projectId}/${branchId}`]) { if (
!state.trees[`${projectId}/${branchId}`] ||
(state.trees[`${projectId}/${branchId}`].tree &&
state.trees[`${projectId}/${branchId}`].tree.length === 0)
) {
const selectedProject = state.projects[projectId]; const selectedProject = state.projects[projectId];
commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` }); commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` });
...@@ -102,7 +107,7 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } = ...@@ -102,7 +107,7 @@ export const getFiles = ({ state, commit, dispatch }, { projectId, branchId } =
dispatch('showBranchNotFoundError', branchId); dispatch('showBranchNotFoundError', branchId);
} else { } else {
flash( flash(
'Error loading tree data. Please try again.', __('Error loading tree data. Please try again.'),
'alert', 'alert',
document, document,
null, null,
......
...@@ -7,9 +7,9 @@ import { ...@@ -7,9 +7,9 @@ import {
getBranchData, getBranchData,
} from '~/ide/stores/actions'; } from '~/ide/stores/actions';
import store from '~/ide/stores'; import store from '~/ide/stores';
import projectActions from '~/ide/stores/actions/project';
import service from '~/ide/services'; import service from '~/ide/services';
import api from '~/api'; import api from '~/api';
import router from '~/ide/ide_router';
import { resetStore } from '../../helpers'; import { resetStore } from '../../helpers';
import testAction from '../../../helpers/vuex_action_helper'; import testAction from '../../../helpers/vuex_action_helper';
...@@ -124,7 +124,7 @@ describe('IDE store project actions', () => { ...@@ -124,7 +124,7 @@ describe('IDE store project actions', () => {
describe('createNewBranchFromDefault', () => { describe('createNewBranchFromDefault', () => {
it('calls API', done => { it('calls API', done => {
spyOn(api, 'createBranch').and.returnValue(Promise.resolve()); spyOn(api, 'createBranch').and.returnValue(Promise.resolve());
spyOnDependency(projectActions, 'refreshCurrentPage'); spyOn(router, 'push');
createNewBranchFromDefault( createNewBranchFromDefault(
{ {
...@@ -136,23 +136,24 @@ describe('IDE store project actions', () => { ...@@ -136,23 +136,24 @@ describe('IDE store project actions', () => {
default_branch: 'master', default_branch: 'master',
}, },
}, },
dispatch() {},
}, },
'new-branch-name', 'new-branch-name',
); )
.then(() => {
setTimeout(() => {
expect(api.createBranch).toHaveBeenCalledWith('project-path', { expect(api.createBranch).toHaveBeenCalledWith('project-path', {
ref: 'master', ref: 'master',
branch: 'new-branch-name', branch: 'new-branch-name',
}); });
})
done(); .then(done)
}); .catch(done.fail);
}); });
it('reloads window', done => { it('clears error message', done => {
const dispatchSpy = jasmine.createSpy('dispatch');
spyOn(api, 'createBranch').and.returnValue(Promise.resolve()); spyOn(api, 'createBranch').and.returnValue(Promise.resolve());
const refreshSpy = spyOnDependency(projectActions, 'refreshCurrentPage'); spyOn(router, 'push');
createNewBranchFromDefault( createNewBranchFromDefault(
{ {
...@@ -164,15 +165,40 @@ describe('IDE store project actions', () => { ...@@ -164,15 +165,40 @@ describe('IDE store project actions', () => {
default_branch: 'master', default_branch: 'master',
}, },
}, },
dispatch: dispatchSpy,
}, },
'new-branch-name', 'new-branch-name',
); )
.then(() => {
expect(dispatchSpy).toHaveBeenCalledWith('setErrorMessage', null);
})
.then(done)
.catch(done.fail);
});
setTimeout(() => { it('reloads window', done => {
expect(refreshSpy).toHaveBeenCalled(); spyOn(api, 'createBranch').and.returnValue(Promise.resolve());
spyOn(router, 'push');
done(); createNewBranchFromDefault(
}); {
state: {
currentProjectId: 'project-path',
},
getters: {
currentProject: {
default_branch: 'master',
},
},
dispatch() {},
},
'new-branch-name',
)
.then(() => {
expect(router.push).toHaveBeenCalled();
})
.then(done)
.catch(done.fail);
}); });
}); });
......
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