diff --git a/app/assets/javascripts/pages/groups/work_items/show/index.js b/app/assets/javascripts/pages/groups/work_items/show/index.js index c091fbcc2b2007fec536460e27771492a4f97e3f..0e8ee3aa7c162d493bc57ad0fa8e2c3743f7bc1c 100644 --- a/app/assets/javascripts/pages/groups/work_items/show/index.js +++ b/app/assets/javascripts/pages/groups/work_items/show/index.js @@ -1,4 +1,4 @@ import { WORKSPACE_GROUP } from '~/issues/constants'; import { initWorkItemsRoot } from '~/work_items'; -initWorkItemsRoot(WORKSPACE_GROUP); +initWorkItemsRoot({ workspaceType: WORKSPACE_GROUP }); diff --git a/app/assets/javascripts/work_items/index.js b/app/assets/javascripts/work_items/index.js index 0b7f9290d6e931a6babd463c31f883ca9d7b2a30..1ef5e851d4fde1321e59556cd1b21c54c5fefdab 100644 --- a/app/assets/javascripts/work_items/index.js +++ b/app/assets/javascripts/work_items/index.js @@ -4,12 +4,11 @@ import { WORKSPACE_GROUP } from '~/issues/constants'; import { parseBoolean } from '~/lib/utils/common_utils'; import { apolloProvider } from '~/graphql_shared/issuable_client'; import App from './components/app.vue'; -import WorkItemRoot from './pages/work_item_root.vue'; import { createRouter } from './router'; Vue.use(VueApollo); -export const initWorkItemsRoot = (workspace) => { +export const initWorkItemsRoot = ({ workItemType, workspaceType } = {}) => { const el = document.querySelector('#js-work-items'); if (!el) { @@ -30,16 +29,16 @@ export const initWorkItemsRoot = (workspace) => { reportAbusePath, } = el.dataset; - const Component = workspace === WORKSPACE_GROUP ? WorkItemRoot : App; + const isGroup = workspaceType === WORKSPACE_GROUP; return new Vue({ el, name: 'WorkItemsRoot', - router: createRouter(el.dataset.fullPath), + router: createRouter({ fullPath, workItemType, workspaceType }), apolloProvider, provide: { fullPath, - isGroup: workspace === WORKSPACE_GROUP, + isGroup, hasIssueWeightsFeature: parseBoolean(hasIssueWeightsFeature), hasOkrsFeature: parseBoolean(hasOkrsFeature), issuesListPath, @@ -51,9 +50,9 @@ export const initWorkItemsRoot = (workspace) => { reportAbusePath, }, render(createElement) { - return createElement(Component, { + return createElement(App, { props: { - iid: workspace === WORKSPACE_GROUP ? iid : undefined, + iid: isGroup ? iid : undefined, }, }); }, diff --git a/app/assets/javascripts/work_items/pages/create_work_item.vue b/app/assets/javascripts/work_items/pages/create_work_item.vue index 435a1233dce1f50739c5346b4113655aae98ea71..10c76cab8781d6b7eb40749f49c00a3fb1973f4e 100644 --- a/app/assets/javascripts/work_items/pages/create_work_item.vue +++ b/app/assets/javascripts/work_items/pages/create_work_item.vue @@ -9,6 +9,7 @@ import { sprintfWorkItem, } from '../constants'; import createWorkItemMutation from '../graphql/create_work_item.mutation.graphql'; +import groupWorkItemTypesQuery from '../graphql/group_work_item_types.query.graphql'; import projectWorkItemTypesQuery from '../graphql/project_work_item_types.query.graphql'; import groupWorkItemByIidQuery from '../graphql/group_work_item_by_iid.query.graphql'; import workItemByIidQuery from '../graphql/work_item_by_iid.query.graphql'; @@ -42,7 +43,9 @@ export default { }, apollo: { workItemTypes: { - query: projectWorkItemTypesQuery, + query() { + return this.isGroup ? groupWorkItemTypesQuery : projectWorkItemTypesQuery; + }, variables() { return { fullPath: this.fullPath, diff --git a/app/assets/javascripts/work_items/router/index.js b/app/assets/javascripts/work_items/router/index.js index 8d67bcaf84ff54db9f6e3332681a396c25dbea6a..dcf9dcb10f5fde7474fb6129adaeb585b358049d 100644 --- a/app/assets/javascripts/work_items/router/index.js +++ b/app/assets/javascripts/work_items/router/index.js @@ -1,16 +1,23 @@ import { GlToast } from '@gitlab/ui'; import Vue from 'vue'; import VueRouter from 'vue-router'; +import { WORKSPACE_GROUP, WORKSPACE_PROJECT } from '~/issues/constants'; import { joinPaths } from '~/lib/utils/url_utility'; import { routes } from './routes'; Vue.use(GlToast); Vue.use(VueRouter); -export function createRouter(fullPath) { +export function createRouter({ + fullPath, + workItemType = 'work_items', + workspaceType = WORKSPACE_PROJECT, +}) { + const workspacePath = workspaceType === WORKSPACE_GROUP ? '/groups' : ''; + return new VueRouter({ routes: routes(), mode: 'history', - base: joinPaths(gon?.relative_url_root, fullPath, '-', 'work_items'), + base: joinPaths(gon?.relative_url_root, workspacePath, fullPath, '-', workItemType), }); } diff --git a/spec/frontend/work_items/router_spec.js b/spec/frontend/work_items/router_spec.js index d4efcf781891039105f453355bc95f66121ed959..cb609fac882b04bbf6feea36592c9cd3d750639e 100644 --- a/spec/frontend/work_items/router_spec.js +++ b/spec/frontend/work_items/router_spec.js @@ -25,7 +25,7 @@ describe('Work items router', () => { .mockResolvedValue({ data: { workItemUpdated: null } }); const createComponent = async (routeArg) => { - const router = createRouter('/work_item'); + const router = createRouter({ fullPath: '/work_item' }); if (routeArg !== undefined) { await router.push(routeArg); } @@ -89,4 +89,23 @@ describe('Work items router', () => { expect(wrapper.findComponent(CreateWorkItem).exists()).toBe(true); }); + + it('includes relative_url_root', () => { + gon.relative_url_root = '/my-org'; + const router = createRouter({ fullPath: '/work_item' }); + + expect(router.options.base).toBe('/my-org/work_item/-/work_items'); + }); + + it('includes groups in path for groups', () => { + const router = createRouter({ fullPath: '/work_item', workspaceType: 'group' }); + + expect(router.options.base).toBe('/groups/work_item/-/work_items'); + }); + + it('includes workItemType if provided', () => { + const router = createRouter({ fullPath: '/work_item', workItemType: 'epics' }); + + expect(router.options.base).toBe('/work_item/-/epics'); + }); });