Commit 6302b664 authored by Miguel Rincon's avatar Miguel Rincon

Merge branch '331831-persist-fields-on-issue-type-change' into 'master'

Ignore search param for autosave on issue new form

See merge request gitlab-org/gitlab!82568
parents e1242733 d07ae262
......@@ -12,6 +12,7 @@ import ZenMode from '~/zen_mode';
const MR_SOURCE_BRANCH = 'merge_request[source_branch]';
const MR_TARGET_BRANCH = 'merge_request[target_branch]';
const DATA_ISSUES_NEW_PATH = 'data-new-issue-path';
function organizeQuery(obj, isFallbackKey = false) {
if (!obj[MR_SOURCE_BRANCH] && !obj[MR_TARGET_BRANCH]) {
......@@ -68,6 +69,7 @@ export default class IssuableForm {
this.reviewersSelect = new UsersSelect(undefined, '.js-reviewer-search');
this.zenMode = new ZenMode();
this.newIssuePath = form[0].getAttribute(DATA_ISSUES_NEW_PATH);
this.titleField = this.form.find('input[name*="[title]"]');
this.descriptionField = this.form.find('textarea[name*="[description]"]');
if (!(this.titleField.length && this.descriptionField.length)) {
......@@ -104,8 +106,8 @@ export default class IssuableForm {
}
initAutosave() {
const { search } = document.location;
const searchTerm = format(search);
const { search, pathname } = document.location;
const searchTerm = this.newIssuePath === pathname ? '' : format(search);
const fallbackKey = getFallbackKey();
this.autosave = new Autosave(
......
......@@ -239,6 +239,12 @@ module IssuesHelper
)
end
def issues_form_data(project)
{
new_issue_path: new_project_issue_path(project)
}
end
# Overridden in EE
def scoped_labels_available?(parent)
false
......
= 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
import $ from 'jquery';
import IssuableForm from '~/issuable/issuable_form';
function createIssuable() {
const instance = new IssuableForm($(document.createElement('form')));
instance.titleField = $(document.createElement('input'));
return instance;
}
import setWindowLocation from 'helpers/set_window_location_helper';
describe('IssuableForm', () => {
let instance;
const createIssuable = (form) => {
instance = new IssuableForm(form);
};
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', () => {
......
......@@ -368,6 +368,16 @@ RSpec.describe IssuesHelper do
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
context 'when sorting by relative position' 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