From a2f3658c31cbcaea8d73295ffff5a625b6926ba1 Mon Sep 17 00:00:00 2001 From: Thomas Randolph Date: Fri, 17 Jul 2020 11:49:36 -0600 Subject: [PATCH 1/5] Add Draft to WIP MRs Also, default to Draft when the dynamic link is clicked --- app/assets/javascripts/issuable_form.js | 25 ++++++++++- .../components/states/work_in_progress.vue | 44 +++++++------------ .../shared/issuable/form/_title.html.haml | 21 +++------ 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/app/assets/javascripts/issuable_form.js b/app/assets/javascripts/issuable_form.js index cf780556c8de90..2dcf5e6a0d66a5 100644 --- a/app/assets/javascripts/issuable_form.js +++ b/app/assets/javascripts/issuable_form.js @@ -48,7 +48,19 @@ export default class IssuableForm { this.renderWipExplanation = this.renderWipExplanation.bind(this); this.resetAutosave = this.resetAutosave.bind(this); this.handleSubmit = this.handleSubmit.bind(this); - this.wipRegex = /^\s*(\[WIP\]\s*|WIP:\s*|WIP\s+)+\s*/i; + /* eslint-disable @gitlab/require-i18n-strings */ + this.wipRegex = new RegExp( + '^\\s*(' + // Line start, then any amount of leading whitespace + 'draft\\s-\\s' + // Draft_-_ where "_" are *exactly* one whitespace + '|\\[(draft|wip)\\]\\s*' + // [Draft] or [WIP] and any following whitespace + '|(draft|wip):\\s*' + // Draft: or WIP: and any following whitespace + '|(draft|wip)\\s+' + // Draft_ or WIP_ where "_" is at least one whitespace + '|\\(draft\\)\\s*' + // (Draft) and any following whitespace + ')+' + // At least one repeated match of the preceding parenthetical + '\\s*', // Any amount of trailing whitespace + 'i', // Match any case(s) + ); + /* eslint-enable @gitlab/require-i18n-strings */ this.gfmAutoComplete = new GfmAutoComplete( gl.GfmAutoComplete && gl.GfmAutoComplete.dataSources, @@ -131,9 +143,18 @@ export default class IssuableForm { workInProgress() { return this.wipRegex.test(this.titleField.val()); } + titlePrefixContainsDraft() { + const prefix = this.titleField.val().match(this.wipRegex); + + return prefix && prefix[0].match(/draft/i); + } renderWipExplanation() { if (this.workInProgress()) { + // These strings are not "translatable" (the code is hard-coded to look for them) + this.$wipExplanation.find('code')[0].textContent = this.titlePrefixContainsDraft() + ? 'Draft' /* eslint-disable-line @gitlab/require-i18n-strings */ + : 'WIP'; this.$wipExplanation.show(); return this.$noWipExplanation.hide(); } @@ -156,7 +177,7 @@ export default class IssuableForm { } addWip() { - this.titleField.val(`WIP: ${this.titleField.val()}`); + this.titleField.val(`Draft: ${this.titleField.val()}`); } initTargetBranchDropdown() { diff --git a/app/assets/javascripts/vue_merge_request_widget/components/states/work_in_progress.vue b/app/assets/javascripts/vue_merge_request_widget/components/states/work_in_progress.vue index 118caac84b9cfb..6837545c681bdd 100644 --- a/app/assets/javascripts/vue_merge_request_widget/components/states/work_in_progress.vue +++ b/app/assets/javascripts/vue_merge_request_widget/components/states/work_in_progress.vue @@ -1,7 +1,7 @@