Commit d07ae262 authored by Sean Arnold's avatar Sean Arnold Committed by Miguel Rincon

Ignore search param for autosave on issue new form

Changelog: changed
parent 81f5f80f
...@@ -12,6 +12,7 @@ import ZenMode from '~/zen_mode'; ...@@ -12,6 +12,7 @@ import ZenMode from '~/zen_mode';
const MR_SOURCE_BRANCH = 'merge_request[source_branch]'; const MR_SOURCE_BRANCH = 'merge_request[source_branch]';
const MR_TARGET_BRANCH = 'merge_request[target_branch]'; const MR_TARGET_BRANCH = 'merge_request[target_branch]';
const DATA_ISSUES_NEW_PATH = 'data-new-issue-path';
function organizeQuery(obj, isFallbackKey = false) { function organizeQuery(obj, isFallbackKey = false) {
if (!obj[MR_SOURCE_BRANCH] && !obj[MR_TARGET_BRANCH]) { if (!obj[MR_SOURCE_BRANCH] && !obj[MR_TARGET_BRANCH]) {
...@@ -68,6 +69,7 @@ export default class IssuableForm { ...@@ -68,6 +69,7 @@ export default class IssuableForm {
this.reviewersSelect = new UsersSelect(undefined, '.js-reviewer-search'); this.reviewersSelect = new UsersSelect(undefined, '.js-reviewer-search');
this.zenMode = new ZenMode(); this.zenMode = new ZenMode();
this.newIssuePath = form[0].getAttribute(DATA_ISSUES_NEW_PATH);
this.titleField = this.form.find('input[name*="[title]"]'); this.titleField = this.form.find('input[name*="[title]"]');
this.descriptionField = this.form.find('textarea[name*="[description]"]'); this.descriptionField = this.form.find('textarea[name*="[description]"]');
if (!(this.titleField.length && this.descriptionField.length)) { if (!(this.titleField.length && this.descriptionField.length)) {
...@@ -104,8 +106,8 @@ export default class IssuableForm { ...@@ -104,8 +106,8 @@ export default class IssuableForm {
} }
initAutosave() { initAutosave() {
const { search } = document.location; const { search, pathname } = document.location;
const searchTerm = format(search); const searchTerm = this.newIssuePath === pathname ? '' : format(search);
const fallbackKey = getFallbackKey(); const fallbackKey = getFallbackKey();
this.autosave = new Autosave( this.autosave = new Autosave(
......
...@@ -239,6 +239,12 @@ module IssuesHelper ...@@ -239,6 +239,12 @@ module IssuesHelper
) )
end end
def issues_form_data(project)
{
new_issue_path: new_project_issue_path(project)
}
end
# Overridden in EE # Overridden in EE
def scoped_labels_available?(parent) def scoped_labels_available?(parent)
false false
......
= form_for [@project, @issue], = form_for [@project, @issue],
html: { class: 'issue-form common-note-form gl-mt-3 js-quick-submit gl-show-field-errors' } do |f| html: { class: 'issue-form common-note-form gl-mt-3 js-quick-submit gl-show-field-errors', data: issues_form_data(@project) } do |f|
= render 'shared/issuable/form', f: f, issuable: @issue = render 'shared/issuable/form', f: f, issuable: @issue
import $ from 'jquery'; import $ from 'jquery';
import IssuableForm from '~/issuable/issuable_form'; import IssuableForm from '~/issuable/issuable_form';
import setWindowLocation from 'helpers/set_window_location_helper';
function createIssuable() {
const instance = new IssuableForm($(document.createElement('form')));
instance.titleField = $(document.createElement('input'));
return instance;
}
describe('IssuableForm', () => { describe('IssuableForm', () => {
let instance; let instance;
const createIssuable = (form) => {
instance = new IssuableForm(form);
};
beforeEach(() => { beforeEach(() => {
instance = createIssuable(); setFixtures(`
<form>
<input name="[title]" />
</form>
`);
createIssuable($('form'));
});
describe('initAutosave', () => {
it('creates autosave with the searchTerm included', () => {
setWindowLocation('https://gitlab.test/foo?bar=true');
const autosave = instance.initAutosave();
expect(autosave.key.includes('bar=true')).toBe(true);
});
it("creates autosave fields without the searchTerm if it's an issue new form", () => {
setFixtures(`
<form data-new-issue-path="/issues/new">
<input name="[title]" />
</form>
`);
createIssuable($('form'));
setWindowLocation('https://gitlab.test/issues/new?bar=true');
const autosave = instance.initAutosave();
expect(autosave.key.includes('bar=true')).toBe(false);
});
}); });
describe('removeWip', () => { describe('removeWip', () => {
......
...@@ -368,6 +368,16 @@ RSpec.describe IssuesHelper do ...@@ -368,6 +368,16 @@ RSpec.describe IssuesHelper do
end end
end end
describe '#issues_form_data' do
it 'returns expected result' do
expected = {
new_issue_path: new_project_issue_path(project)
}
expect(helper.issues_form_data(project)).to include(expected)
end
end
describe '#issue_manual_ordering_class' do describe '#issue_manual_ordering_class' do
context 'when sorting by relative position' do context 'when sorting by relative position' do
before do before do
......
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