Коммит 209a1710 создал по автору Denys Mishunov's avatar Denys Mishunov
Просмотр файлов

Route to emptyState straight from router

As soon as we detect that the project is empty, we can route to empty
state immediately without the attempt to load a branch even if it's
specified in the URL.

This means that is we got to fetching a branch and it fails, we're in
non-empty repo and the branch really doesn't exist. Hence we should show
the error.
владелец 28a06117
......@@ -72,18 +72,22 @@ router.beforeEach((to, from, next) => {
namespace: to.params.namespace,
projectId: to.params.project,
})
.then(() => {
.then(data => {
const basePath = to.params.pathMatch || '';
const projectId = `${to.params.namespace}/${to.params.project}`;
const branchId = to.params.branchid;
const mergeRequestId = to.params.mrid;
if (branchId) {
store.dispatch('openBranch', {
projectId,
branchId,
basePath,
});
if (data.empty_repo) {
store.dispatch('showEmptyState', { projectId, branchId });
} else {
store.dispatch('openBranch', {
projectId,
branchId,
basePath,
});
}
} else if (mergeRequestId) {
store.dispatch('openMergeRequest', {
projectId,
......
......@@ -68,7 +68,8 @@ export const createNewBranchFromDefault = ({ state, dispatch, getters }, branch)
});
});
export const showBranchNotFoundError = ({ dispatch }, branchId) => {
export const showBranchNotFoundError = ({ dispatch, state, commit }, branchId) => {
commit(types.TOGGLE_LOADING, { entry: state, forceValue: true });
dispatch('setErrorMessage', {
text: sprintf(
__("Branch %{branchName} was not found in this project's repository."),
......@@ -83,14 +84,13 @@ export const showBranchNotFoundError = ({ dispatch }, branchId) => {
});
};
export const showEmptyState = ({ commit, state }, { err, projectId, branchId }) => {
if (err.response && err.response.status === 404) {
commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` });
commit(types.TOGGLE_LOADING, {
entry: state.trees[`${projectId}/${branchId}`],
forceValue: false,
});
}
export const showEmptyState = ({ commit, state, dispatch }, { projectId, branchId }) => {
dispatch('setCurrentBranchId', branchId);
commit(types.CREATE_TREE, { treePath: `${projectId}/${branchId}` });
commit(types.TOGGLE_LOADING, {
entry: state.trees[`${projectId}/${branchId}`],
forceValue: false,
});
};
export const openBranch = ({ dispatch, state }, { projectId, branchId, basePath }) => {
......@@ -131,8 +131,7 @@ export const openBranch = ({ dispatch, state }, { projectId, branchId, basePath
() => new Error(`An error occurred whilst getting files for - ${projectId}/${branchId}`),
);
})
.catch(err => {
// If branch doesn't exist we show empty-state view
dispatch('showEmptyState', { err, projectId, branchId });
.catch(() => {
dispatch('showBranchNotFoundError', branchId);
});
};
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать