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