Commit 0d7257f5 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'dmishunov-joinpaths-refactor' into 'master'

Use joinPaths to build URL

See merge request gitlab-org/gitlab!40439
parents 41057ab0 6be9ede5
...@@ -4,7 +4,7 @@ import { GlButton, GlLoadingIcon } from '@gitlab/ui'; ...@@ -4,7 +4,7 @@ import { GlButton, GlLoadingIcon } from '@gitlab/ui';
import { deprecatedCreateFlash as Flash } from '~/flash'; import { deprecatedCreateFlash as Flash } from '~/flash';
import { __, sprintf } from '~/locale'; import { __, sprintf } from '~/locale';
import TitleField from '~/vue_shared/components/form/title.vue'; import TitleField from '~/vue_shared/components/form/title.vue';
import { redirectTo } from '~/lib/utils/url_utility'; import { redirectTo, joinPaths } from '~/lib/utils/url_utility';
import FormFooterActions from '~/vue_shared/components/form/form_footer_actions.vue'; import FormFooterActions from '~/vue_shared/components/form/form_footer_actions.vue';
import UpdateSnippetMutation from '../mutations/updateSnippet.mutation.graphql'; import UpdateSnippetMutation from '../mutations/updateSnippet.mutation.graphql';
...@@ -88,9 +88,7 @@ export default { ...@@ -88,9 +88,7 @@ export default {
}, },
cancelButtonHref() { cancelButtonHref() {
if (this.newSnippet) { if (this.newSnippet) {
return this.projectPath return joinPaths('/', gon.relative_url_root, this.projectPath, '-/snippets');
? `${gon.relative_url_root}${this.projectPath}/-/snippets`
: `${gon.relative_url_root}/-/snippets`;
} }
return this.snippet.webUrl; return this.snippet.webUrl;
}, },
......
...@@ -17,6 +17,7 @@ import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue'; ...@@ -17,6 +17,7 @@ import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import DeleteSnippetMutation from '../mutations/deleteSnippet.mutation.graphql'; import DeleteSnippetMutation from '../mutations/deleteSnippet.mutation.graphql';
import CanCreatePersonalSnippet from '../queries/userPermissions.query.graphql'; import CanCreatePersonalSnippet from '../queries/userPermissions.query.graphql';
import CanCreateProjectSnippet from '../queries/projectPermissions.query.graphql'; import CanCreateProjectSnippet from '../queries/projectPermissions.query.graphql';
import { joinPaths } from '~/lib/utils/url_utility';
export default { export default {
components: { components: {
...@@ -96,8 +97,8 @@ export default { ...@@ -96,8 +97,8 @@ export default {
condition: this.canCreateSnippet, condition: this.canCreateSnippet,
text: __('New snippet'), text: __('New snippet'),
href: this.snippet.project href: this.snippet.project
? `${this.snippet.project.webUrl}/-/snippets/new` ? joinPaths(this.snippet.project.webUrl, '-/snippets/new')
: `${gon.relative_url_root}/-/snippets/new`, : joinPaths('/', gon.relative_url_root, '/-/snippets/new'),
variant: 'success', variant: 'success',
category: 'secondary', category: 'secondary',
cssClass: 'ml-2', cssClass: 'ml-2',
......
...@@ -200,8 +200,8 @@ describe('Snippet Edit app', () => { ...@@ -200,8 +200,8 @@ describe('Snippet Edit app', () => {
it.each` it.each`
projectPath | snippetArg | expectation projectPath | snippetArg | expectation
${''} | ${[]} | ${`${relativeUrlRoot}/-/snippets`} ${''} | ${[]} | ${urlUtils.joinPaths('/', relativeUrlRoot, '-', 'snippets')}
${'project/path'} | ${[]} | ${`${relativeUrlRoot}project/path/-/snippets`} ${'project/path'} | ${[]} | ${urlUtils.joinPaths('/', relativeUrlRoot, 'project/path/-', 'snippets')}
${''} | ${[createTestSnippet()]} | ${TEST_WEB_URL} ${''} | ${[createTestSnippet()]} | ${TEST_WEB_URL}
${'project/path'} | ${[createTestSnippet()]} | ${TEST_WEB_URL} ${'project/path'} | ${[createTestSnippet()]} | ${TEST_WEB_URL}
`( `(
......
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