Commit 445bbc77 authored by Phil Hughes's avatar Phil Hughes

Fixed new blob and directory form actions in Vue file listing refactor

Updates the form actions to correctly reflect the new routes
parent 0a016946
...@@ -124,7 +124,7 @@ export default { ...@@ -124,7 +124,7 @@ export default {
}, },
{ {
attrs: { attrs: {
href: this.newBlobPath, href: `${this.newBlobPath}${this.currentPath}`,
class: 'qa-new-file-option', class: 'qa-new-file-option',
}, },
text: __('New file'), text: __('New file'),
......
...@@ -7,6 +7,7 @@ import TreeActionLink from './components/tree_action_link.vue'; ...@@ -7,6 +7,7 @@ import TreeActionLink from './components/tree_action_link.vue';
import DirectoryDownloadLinks from './components/directory_download_links.vue'; import DirectoryDownloadLinks from './components/directory_download_links.vue';
import apolloProvider from './graphql'; import apolloProvider from './graphql';
import { setTitle } from './utils/title'; import { setTitle } from './utils/title';
import { updateFormAction } from './utils/dom';
import { parseBoolean } from '../lib/utils/common_utils'; import { parseBoolean } from '../lib/utils/common_utils';
import { webIDEUrl } from '../lib/utils/url_utility'; import { webIDEUrl } from '../lib/utils/url_utility';
import { __ } from '../locale'; import { __ } from '../locale';
...@@ -42,8 +43,15 @@ export default function setupVueRepositoryList() { ...@@ -42,8 +43,15 @@ export default function setupVueRepositoryList() {
forkNewBlobPath, forkNewBlobPath,
forkNewDirectoryPath, forkNewDirectoryPath,
forkUploadBlobPath, forkUploadBlobPath,
uploadPath,
newDirPath,
} = breadcrumbEl.dataset; } = breadcrumbEl.dataset;
router.afterEach(({ params: { pathMatch = '/' } }) => {
updateFormAction('.js-upload-blob-form', uploadPath, pathMatch);
updateFormAction('.js-create-dir-form', newDirPath, pathMatch);
});
// eslint-disable-next-line no-new // eslint-disable-next-line no-new
new Vue({ new Vue({
el: breadcrumbEl, el: breadcrumbEl,
......
// eslint-disable-next-line import/prefer-default-export
export const updateElementsVisibility = (selector, isVisible) => { export const updateElementsVisibility = (selector, isVisible) => {
document.querySelectorAll(selector).forEach(elem => elem.classList.toggle('hidden', !isVisible)); document.querySelectorAll(selector).forEach(elem => elem.classList.toggle('hidden', !isVisible));
}; };
export const updateFormAction = (selector, basePath, path) => {
const form = document.querySelector(selector);
if (form) {
form.action = `${basePath}${path}`;
}
};
...@@ -158,7 +158,9 @@ module TreeHelper ...@@ -158,7 +158,9 @@ module TreeHelper
def breadcrumb_data_attributes def breadcrumb_data_attributes
attrs = { attrs = {
can_collaborate: can_collaborate_with_project?(@project).to_s, can_collaborate: can_collaborate_with_project?(@project).to_s,
new_blob_path: project_new_blob_path(@project, @id), new_blob_path: project_new_blob_path(@project, @ref),
upload_path: project_create_blob_path(@project, @ref),
new_dir_path: project_create_dir_path(@project, @ref),
new_branch_path: new_project_branch_path(@project), new_branch_path: new_project_branch_path(@project),
new_tag_path: new_project_tag_path(@project), new_tag_path: new_project_tag_path(@project),
can_edit_tree: can_edit_tree?.to_s can_edit_tree: can_edit_tree?.to_s
......
import { setHTMLFixture } from '../../helpers/fixtures'; import { setHTMLFixture } from '../../helpers/fixtures';
import { updateElementsVisibility } from '~/repository/utils/dom'; import { updateElementsVisibility, updateFormAction } from '~/repository/utils/dom';
describe('updateElementsVisibility', () => { describe('updateElementsVisibility', () => {
it('adds hidden class', () => { it('adds hidden class', () => {
...@@ -18,3 +18,13 @@ describe('updateElementsVisibility', () => { ...@@ -18,3 +18,13 @@ describe('updateElementsVisibility', () => {
expect(document.querySelector('.js-test').classList).not.toContain('hidden'); expect(document.querySelector('.js-test').classList).not.toContain('hidden');
}); });
}); });
describe('updateFormAction', () => {
it('updates form action', () => {
setHTMLFixture('<form class="js-test" action="/"></form>');
updateFormAction('.js-test', '/gitlab/create', '/test');
expect(document.querySelector('.js-test').action).toBe('http://localhost/gitlab/create/test');
});
});
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