summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/stores
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-06-14 18:03:17 +0100
committerPhil Hughes <me@iamphill.com>2018-06-27 10:44:12 +0100
commite5d42a0f177c0ce2bc922064cfa162e50287815a (patch)
treeb7c9c6db9024716aa55cc3de0155accae9ba0cc5 /app/assets/javascripts/ide/stores
parent2452f1a73e8dcf646311c6069a077ab66be5ce51 (diff)
downloadgitlab-ce-e5d42a0f177c0ce2bc922064cfa162e50287815a.tar.gz
Improve branch 404 error in Web IDE
Part of #47323
Diffstat (limited to 'app/assets/javascripts/ide/stores')
-rw-r--r--app/assets/javascripts/ide/stores/actions/project.js65
-rw-r--r--app/assets/javascripts/ide/stores/actions/tree.js13
2 files changed, 66 insertions, 12 deletions
diff --git a/app/assets/javascripts/ide/stores/actions/project.js b/app/assets/javascripts/ide/stores/actions/project.js
index 0b99bce4a8e..e597351f4d3 100644
--- a/app/assets/javascripts/ide/stores/actions/project.js
+++ b/app/assets/javascripts/ide/stores/actions/project.js
@@ -1,6 +1,7 @@
import flash from '~/flash';
-import { __ } from '~/locale';
+import { __, sprintf } from '~/locale';
import service from '../../services';
+import api from '../../../api';
import * as types from '../mutation_types';
export const getProjectData = ({ commit, state }, { namespace, projectId, force = false } = {}) =>
@@ -32,7 +33,10 @@ export const getProjectData = ({ commit, state }, { namespace, projectId, force
}
});
-export const getBranchData = ({ commit, state }, { projectId, branchId, force = false } = {}) =>
+export const getBranchData = (
+ { commit, dispatch, state },
+ { projectId, branchId, force = false } = {},
+) =>
new Promise((resolve, reject) => {
if (
typeof state.projects[`${projectId}`] === 'undefined' ||
@@ -51,15 +55,21 @@ export const getBranchData = ({ commit, state }, { projectId, branchId, force =
commit(types.SET_BRANCH_WORKING_REFERENCE, { projectId, branchId, reference: id });
resolve(data);
})
- .catch(() => {
- flash(
- __('Error loading branch data. Please try again.'),
- 'alert',
- document,
- null,
- false,
- true,
- );
+ .catch(e => {
+ let flashMessage = __('Error loading branch data. Please try again.');
+
+ if (e.response.status === 404) {
+ dispatch('showBranchNotFoundError', branchId);
+ } else {
+ flash(
+ __('Error loading branch data. Please try again.'),
+ 'alert',
+ document,
+ null,
+ false,
+ true,
+ );
+ }
reject(new Error(`Branch not loaded - ${projectId}/${branchId}`));
});
} else {
@@ -80,3 +90,36 @@ export const refreshLastCommitData = ({ commit }, { projectId, branchId } = {})
.catch(() => {
flash(__('Error loading last commit.'), 'alert', document, null, false, true);
});
+
+export const createNewBranchFromDefault = ({ state, getters }, branch) => {
+ api
+ .createBranch(state.currentProjectId, {
+ ref: getters.currentProject.default_branch,
+ branch,
+ })
+ .then(() => {
+ location.reload();
+ })
+ .catch(() => {});
+};
+
+export const showBranchNotFoundError = ({ dispatch }, branchId) => {
+ flash(
+ sprintf(__('Branch %{branchName} was not found in project.'), {
+ branchName: branchId,
+ }),
+ 'alert',
+ document,
+ {
+ href: '#',
+ title: 'Create branch',
+ clickHandler(e) {
+ e.stopPropagation();
+ e.preventDefault();
+ dispatch('createNewBranchFromDefault', branchId);
+ },
+ },
+ false,
+ true,
+ );
+};
diff --git a/app/assets/javascripts/ide/stores/actions/tree.js b/app/assets/javascripts/ide/stores/actions/tree.js
index 2fbc9990fa2..817dbdbdfa1 100644
--- a/app/assets/javascripts/ide/stores/actions/tree.js
+++ b/app/assets/javascripts/ide/stores/actions/tree.js
@@ -99,7 +99,18 @@ export const getFiles = ({ state, commit }, { projectId, branchId } = {}) =>
});
})
.catch(e => {
- flash('Error loading tree data. Please try again.', 'alert', document, null, false, true);
+ if (e.response.status === 404) {
+ dispatch('showBranchNotFoundError', branchId);
+ } else {
+ flash(
+ 'Error loading tree data. Please try again.',
+ 'alert',
+ document,
+ null,
+ false,
+ true,
+ );
+ }
reject(e);
});
} else {