2019-12-21 20:55:43 +05:30
< script >
2020-11-24 15:15:51 +05:30
/* eslint-disable vue/no-v-html */
2020-04-22 19:07:51 +05:30
import { mapState , mapActions , mapGetters } from 'vuex' ;
import { GlButton , GlFormInput , GlFormGroup } from '@gitlab/ui' ;
2019-12-21 20:55:43 +05:30
import { _ _ , sprintf } from '~/locale' ;
import MarkdownField from '~/vue_shared/components/markdown/field.vue' ;
2020-04-08 14:13:33 +05:30
import { BACK _URL _PARAM } from '~/releases/constants' ;
import { getParameterByName } from '~/lib/utils/common_utils' ;
2020-04-22 19:07:51 +05:30
import AssetLinksForm from './asset_links_form.vue' ;
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin' ;
2020-05-24 23:13:21 +05:30
import MilestoneCombobox from '~/milestones/project_milestone_combobox.vue' ;
2020-10-24 23:57:45 +05:30
import TagField from './tag_field.vue' ;
2019-12-21 20:55:43 +05:30
export default {
2020-10-24 23:57:45 +05:30
name : 'ReleaseEditNewApp' ,
2019-12-21 20:55:43 +05:30
components : {
GlFormInput ,
GlFormGroup ,
GlButton ,
MarkdownField ,
2020-04-22 19:07:51 +05:30
AssetLinksForm ,
2020-05-24 23:13:21 +05:30
MilestoneCombobox ,
2020-10-24 23:57:45 +05:30
TagField ,
2019-12-21 20:55:43 +05:30
} ,
2020-04-22 19:07:51 +05:30
mixins : [ glFeatureFlagsMixin ( ) ] ,
2019-12-21 20:55:43 +05:30
computed : {
2020-03-13 15:44:24 +05:30
... mapState ( 'detail' , [
2019-12-21 20:55:43 +05:30
'isFetchingRelease' ,
2020-04-22 19:07:51 +05:30
'isUpdatingRelease' ,
2019-12-21 20:55:43 +05:30
'fetchError' ,
'markdownDocsPath' ,
'markdownPreviewPath' ,
'releasesPagePath' ,
2019-12-26 22:10:19 +05:30
'updateReleaseApiDocsPath' ,
2020-05-24 23:13:21 +05:30
'release' ,
'newMilestonePath' ,
'manageMilestonesPath' ,
'projectId' ,
2019-12-21 20:55:43 +05:30
] ) ,
2020-10-24 23:57:45 +05:30
... mapGetters ( 'detail' , [ 'isValid' , 'isExistingRelease' ] ) ,
2019-12-21 20:55:43 +05:30
showForm ( ) {
2020-10-24 23:57:45 +05:30
return Boolean ( ! this . isFetchingRelease && ! this . fetchError && this . release ) ;
2019-12-21 20:55:43 +05:30
} ,
subtitleText ( ) {
return sprintf (
_ _ (
2020-04-22 19:07:51 +05:30
'Releases are based on Git tags. We recommend tags that use semantic versioning, for example %{codeStart}v1.0%{codeEnd}, %{codeStart}v2.0-pre%{codeEnd}.' ,
2019-12-21 20:55:43 +05:30
) ,
{
codeStart : '<code>' ,
codeEnd : '</code>' ,
} ,
false ,
) ;
} ,
releaseTitle : {
get ( ) {
2020-03-13 15:44:24 +05:30
return this . $store . state . detail . release . name ;
2019-12-21 20:55:43 +05:30
} ,
set ( title ) {
this . updateReleaseTitle ( title ) ;
} ,
} ,
releaseNotes : {
get ( ) {
2020-03-13 15:44:24 +05:30
return this . $store . state . detail . release . description ;
2019-12-21 20:55:43 +05:30
} ,
set ( notes ) {
this . updateReleaseNotes ( notes ) ;
} ,
} ,
2020-05-24 23:13:21 +05:30
releaseMilestones : {
get ( ) {
return this . $store . state . detail . release . milestones ;
} ,
set ( milestones ) {
this . updateReleaseMilestones ( milestones ) ;
} ,
} ,
2020-04-08 14:13:33 +05:30
cancelPath ( ) {
return getParameterByName ( BACK _URL _PARAM ) || this . releasesPagePath ;
} ,
2020-04-22 19:07:51 +05:30
showAssetLinksForm ( ) {
return this . glFeatures . releaseAssetLinkEditing ;
} ,
2020-10-24 23:57:45 +05:30
saveButtonLabel ( ) {
return this . isExistingRelease ? _ _ ( 'Save changes' ) : _ _ ( 'Create release' ) ;
} ,
isFormSubmissionDisabled ( ) {
2020-04-22 19:07:51 +05:30
return this . isUpdatingRelease || ! this . isValid ;
} ,
2020-05-24 23:13:21 +05:30
milestoneComboboxExtraLinks ( ) {
return [
{
text : _ _ ( 'Create new' ) ,
url : this . newMilestonePath ,
} ,
{
text : _ _ ( 'Manage milestones' ) ,
url : this . manageMilestonesPath ,
} ,
] ;
} ,
2019-12-21 20:55:43 +05:30
} ,
2020-10-24 23:57:45 +05:30
mounted ( ) {
// eslint-disable-next-line promise/catch-or-return
this . initializeRelease ( ) . then ( ( ) => {
// Focus the first non-disabled input element
this . $el . querySelector ( 'input:enabled' ) . focus ( ) ;
} ) ;
2019-12-21 20:55:43 +05:30
} ,
methods : {
2020-03-13 15:44:24 +05:30
... mapActions ( 'detail' , [
2020-10-24 23:57:45 +05:30
'initializeRelease' ,
'saveRelease' ,
2019-12-21 20:55:43 +05:30
'updateReleaseTitle' ,
'updateReleaseNotes' ,
2020-05-24 23:13:21 +05:30
'updateReleaseMilestones' ,
2019-12-21 20:55:43 +05:30
] ) ,
2020-10-24 23:57:45 +05:30
submitForm ( ) {
if ( ! this . isFormSubmissionDisabled ) {
this . saveRelease ( ) ;
}
} ,
2019-12-21 20:55:43 +05:30
} ,
} ;
< / script >
< template >
< div class = "d-flex flex-column" >
< p class = "pt-3 js-subtitle-text" v-html = "subtitleText" > < / p >
2020-10-24 23:57:45 +05:30
< form v-if = "showForm" class="js-quick-submit" @submit.prevent="submitForm" >
< tag-field / >
2019-12-21 20:55:43 +05:30
< gl-form-group >
< label for = "release-title" > { { _ _ ( 'Release title' ) } } < / label >
< gl-form-input
id = "release-title"
ref = "releaseTitleInput"
v - model = "releaseTitle"
type = "text"
class = "form-control"
/ >
< / gl-form-group >
2020-11-24 15:15:51 +05:30
< gl-form-group class = "w-50" data -testid = " milestones -field " >
2020-05-24 23:13:21 +05:30
< label > { { _ _ ( 'Milestones' ) } } < / label >
< div class = "d-flex flex-column col-md-6 col-sm-10 pl-0" >
< milestone-combobox
v - model = "releaseMilestones"
: project - id = "projectId"
: extra - links = "milestoneComboboxExtraLinks"
/ >
< / div >
< / gl-form-group >
2019-12-21 20:55:43 +05:30
< gl-form-group >
< label for = "release-notes" > { { _ _ ( 'Release notes' ) } } < / label >
< div class = "bordered-box pr-3 pl-3" >
< markdown-field
: can - attach - file = "true"
: markdown - preview - path = "markdownPreviewPath"
: markdown - docs - path = "markdownDocsPath"
: add - spacing - classes = "false"
2020-10-24 23:57:45 +05:30
class = "gl-mt-3 gl-mb-3"
2019-12-21 20:55:43 +05:30
>
2020-05-24 23:13:21 +05:30
< template # textarea >
< textarea
id = "release-notes"
v - model = "releaseNotes"
class = "note-textarea js-gfm-input js-autosize markdown-area"
dir = "auto"
data - supports - quick - actions = "false"
: aria - label = "__('Release notes')"
: placeholder = "__('Write your release notes or drag your files here…')"
> < / textarea >
< / template >
2019-12-21 20:55:43 +05:30
< / markdown-field >
< / div >
< / gl-form-group >
2020-04-22 19:07:51 +05:30
< asset-links-form v-if = "showAssetLinksForm" / >
2019-12-21 20:55:43 +05:30
< div class = "d-flex pt-3" >
< gl-button
2020-04-22 19:07:51 +05:30
class = "mr-auto js-no-auto-disable"
category = "primary"
2019-12-21 20:55:43 +05:30
variant = "success"
type = "submit"
2020-10-24 23:57:45 +05:30
: disabled = "isFormSubmissionDisabled"
data - testid = "submit-button"
2019-12-21 20:55:43 +05:30
>
2020-10-24 23:57:45 +05:30
{ { saveButtonLabel } }
< / gl-button >
2020-05-24 23:13:21 +05:30
< gl-button :href = "cancelPath" class = "js-cancel-button" > { { _ _ ( 'Cancel' ) } } < / gl-button >
2019-12-21 20:55:43 +05:30
< / div >
< / form >
< / div >
< / template >