Commit 8e9da0cf authored by Kushal Pandya's avatar Kushal Pandya

Merge branch 'fix-design-management-router' into 'master'

Fix design management router

Closes gitlab-ce#64667

See merge request gitlab-org/gitlab-ee!14741
parents d1495996 58aaa9c9
...@@ -500,6 +500,10 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do ...@@ -500,6 +500,10 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :realtime_changes get :realtime_changes
post :create_merge_request post :create_merge_request
get :discussions, format: :json get :discussions, format: :json
Gitlab.ee do
get 'designs(/*vueroute)', to: 'issues#show', format: false
end
end end
collection do collection do
......
import $ from 'jquery'; import $ from 'jquery';
import Vue from 'vue'; import Vue from 'vue';
import router from './router'; import createRouter from './router';
import App from './components/app.vue'; import App from './components/app.vue';
import apolloProvider from './graphql'; import apolloProvider from './graphql';
import allDesigns from './queries/allDesigns.graphql'; import allDesigns from './queries/allDesigns.graphql';
...@@ -8,7 +8,8 @@ import allDesigns from './queries/allDesigns.graphql'; ...@@ -8,7 +8,8 @@ import allDesigns from './queries/allDesigns.graphql';
export default () => { export default () => {
const el = document.getElementById('js-design-management'); const el = document.getElementById('js-design-management');
const badge = document.querySelector('.js-designs-count'); const badge = document.querySelector('.js-designs-count');
const { issueIid, projectPath } = el.dataset; const { issueIid, projectPath, issuePath } = el.dataset;
const router = createRouter(issuePath);
$('.js-issue-tabs').on('shown.bs.tab', ({ target: { id } }) => { $('.js-issue-tabs').on('shown.bs.tab', ({ target: { id } }) => {
if (id === 'designs' && router.currentRoute.name === 'root') { if (id === 'designs' && router.currentRoute.name === 'root') {
......
import $ from 'jquery'; import $ from 'jquery';
import _ from 'underscore';
import Vue from 'vue'; import Vue from 'vue';
import VueRouter from 'vue-router'; import VueRouter from 'vue-router';
import Home from './pages/index.vue'; import Home from './pages/index.vue';
...@@ -7,52 +6,57 @@ import DesignDetail from './pages/design/index.vue'; ...@@ -7,52 +6,57 @@ import DesignDetail from './pages/design/index.vue';
Vue.use(VueRouter); Vue.use(VueRouter);
const router = new VueRouter({ export default function createRouter(base) {
base: window.location.pathname, const router = new VueRouter({
routes: [ base,
{ mode: 'history',
name: 'root', routes: [
path: '/', {
component: Home, name: 'root',
meta: { path: '/',
el: 'discussion', component: Home,
}, meta: {
}, el: 'discussion',
{ },
name: 'designs',
path: '/designs',
component: Home,
meta: {
el: 'designs',
}, },
children: [ {
{ name: 'designs',
name: 'design', path: '/designs',
path: ':id', component: Home,
component: DesignDetail, meta: {
meta: { el: 'designs',
el: 'designs', },
}, children: [
beforeEnter( {
{ name: 'design',
params: { id }, path: ':id',
component: DesignDetail,
meta: {
el: 'designs',
}, },
from, beforeEnter(
next, {
) { params: { id },
if (_.isString(id)) next(); },
from,
next,
) {
if (typeof id === 'string') {
next();
}
},
props: ({ params: { id } }) => ({ id }),
}, },
props: ({ params: { id } }) => ({ id }), ],
}, },
], ],
}, });
],
});
router.beforeEach(({ meta: { el } }, from, next) => { router.beforeEach(({ meta: { el } }, from, next) => {
$(`#${el}`).tab('show'); $(`#${el}`).tab('show');
next(); next();
}); });
export default router; return router;
}
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
#discussion-tab.tab-pane.show.active{ role: 'tabpanel', 'aria-labelledby': 'discussion' } #discussion-tab.tab-pane.show.active{ role: 'tabpanel', 'aria-labelledby': 'discussion' }
= render_ce 'projects/issues/discussion' = render_ce 'projects/issues/discussion'
#designs-tab.tab-pane{ role: 'tabpanel', 'aria-labelledby': 'designs' } #designs-tab.tab-pane{ role: 'tabpanel', 'aria-labelledby': 'designs' }
#js-design-management{ data: { project_path: @project.full_path, issue_iid: @issue.iid } } #js-design-management{ data: { project_path: @project.full_path, issue_iid: @issue.iid, issue_path: project_issue_path(@project, @issue) } }
- else - else
= render_ce 'projects/issues/discussion' = render_ce 'projects/issues/discussion'
...@@ -3,11 +3,12 @@ import VueRouter from 'vue-router'; ...@@ -3,11 +3,12 @@ import VueRouter from 'vue-router';
import App from 'ee/design_management/components/app.vue'; import App from 'ee/design_management/components/app.vue';
import Designs from 'ee/design_management/pages/index.vue'; import Designs from 'ee/design_management/pages/index.vue';
import DesignDetail from 'ee/design_management/pages/design/index.vue'; import DesignDetail from 'ee/design_management/pages/design/index.vue';
import router from 'ee/design_management/router'; import createRouter from 'ee/design_management/router';
import '~/commons/bootstrap'; import '~/commons/bootstrap';
describe('Design management router', () => { describe('Design management router', () => {
let vm; let vm;
let router;
function factory() { function factory() {
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -16,6 +17,8 @@ describe('Design management router', () => { ...@@ -16,6 +17,8 @@ describe('Design management router', () => {
window.gon = { sprite_icons: '' }; window.gon = { sprite_icons: '' };
router = createRouter('/');
vm = mount(App, { vm = mount(App, {
localVue, localVue,
router, router,
......
...@@ -251,15 +251,13 @@ describe Projects::IssuesController do ...@@ -251,15 +251,13 @@ describe Projects::IssuesController do
end end
end end
describe 'Redirect after sign in' do # This spec runs as a request-style spec in order to invoke the
# Rails router. A controller-style spec matches the wrong route, and
# session['user_return_to'] becomes incorrect.
describe 'Redirect after sign in', type: :request do
context 'with an AJAX request' do context 'with an AJAX request' do
it 'does not store the visited URL' do it 'does not store the visited URL' do
get :show, params: { get project_issue_path(project, issue), xhr: true
format: :json,
namespace_id: project.namespace,
project_id: project,
id: issue.iid
}, xhr: true
expect(session['user_return_to']).to be_blank expect(session['user_return_to']).to be_blank
end end
...@@ -267,14 +265,9 @@ describe Projects::IssuesController do ...@@ -267,14 +265,9 @@ describe Projects::IssuesController do
context 'without an AJAX request' do context 'without an AJAX request' do
it 'stores the visited URL' do it 'stores the visited URL' do
get :show, get project_issue_path(project, issue)
params: {
namespace_id: project.namespace.to_param,
project_id: project,
id: issue.iid
}
expect(session['user_return_to']).to eq("/#{project.namespace.to_param}/#{project.to_param}/issues/#{issue.iid}") expect(session['user_return_to']).to eq(project_issue_path(project, issue))
end end
end end
end end
......
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