2020-04-08 14:13:33 +05:30
< script >
2020-10-24 23:57:45 +05:30
import { GlPopover , GlSprintf , GlButton } from '@gitlab/ui' ;
2020-04-22 19:07:51 +05:30
import { parseBoolean , scrollToElement , setCookie , getCookie } from '~/lib/utils/common_utils' ;
2020-04-08 14:13:33 +05:30
import { s _ _ } from '~/locale' ;
import Tracking from '~/tracking' ;
const trackingMixin = Tracking . mixin ( ) ;
const popoverStates = {
suggest _gitlab _ci _yml : {
title : s _ _ ( ` suggestPipeline|1/2: Choose a template ` ) ,
content : s _ _ (
2020-07-28 23:09:34 +05:30
` suggestPipeline|We’ re adding a GitLab CI configuration file to add a pipeline to the project. You could create it manually, but we recommend that you start with a GitLab template that works out of the box. ` ,
) ,
footer : s _ _ (
` suggestPipeline|Choose %{boldStart}Code Quality%{boldEnd} to add a pipeline that tests the quality of your code. ` ,
2020-04-08 14:13:33 +05:30
) ,
} ,
suggest _commit _first _project _gitlab _ci _yml : {
title : s _ _ ( ` suggestPipeline|2/2: Commit your changes ` ) ,
content : s _ _ (
2020-07-28 23:09:34 +05:30
` suggestPipeline|The template is ready! You can now commit it to create your first pipeline. ` ,
2020-04-08 14:13:33 +05:30
) ,
} ,
} ;
export default {
2020-04-22 19:07:51 +05:30
dismissTrackValue : 10 ,
clickTrackValue : 'click_button' ,
2020-04-08 14:13:33 +05:30
components : {
GlPopover ,
GlSprintf ,
2020-10-24 23:57:45 +05:30
GlButton ,
2020-04-08 14:13:33 +05:30
} ,
mixins : [ trackingMixin ] ,
props : {
target : {
type : String ,
required : true ,
} ,
trackLabel : {
type : String ,
required : true ,
} ,
dismissKey : {
type : String ,
required : true ,
} ,
humanAccess : {
type : String ,
required : true ,
} ,
2020-11-24 15:15:51 +05:30
mergeRequestPath : {
type : String ,
required : true ,
} ,
2020-04-08 14:13:33 +05:30
} ,
data ( ) {
return {
2020-04-22 19:07:51 +05:30
popoverDismissed : parseBoolean ( getCookie ( ` ${ this . trackLabel } _ ${ this . dismissKey } ` ) ) ,
2020-04-08 14:13:33 +05:30
tracking : {
label : this . trackLabel ,
property : this . humanAccess ,
} ,
} ;
} ,
computed : {
suggestTitle ( ) {
return popoverStates [ this . trackLabel ] . title || '' ;
} ,
suggestContent ( ) {
return popoverStates [ this . trackLabel ] . content || '' ;
} ,
2020-07-28 23:09:34 +05:30
suggestFooter ( ) {
return popoverStates [ this . trackLabel ] . footer || '' ;
} ,
2020-04-08 14:13:33 +05:30
emoji ( ) {
return popoverStates [ this . trackLabel ] . emoji || '' ;
} ,
2020-04-22 19:07:51 +05:30
dismissCookieName ( ) {
return ` ${ this . trackLabel } _ ${ this . dismissKey } ` ;
} ,
2020-04-08 14:13:33 +05:30
} ,
mounted ( ) {
2020-04-22 19:07:51 +05:30
if (
this . trackLabel === 'suggest_commit_first_project_gitlab_ci_yml' &&
! this . popoverDismissed
) {
2020-04-08 14:13:33 +05:30
scrollToElement ( document . querySelector ( this . target ) ) ;
2020-04-22 19:07:51 +05:30
}
2020-04-08 14:13:33 +05:30
this . trackOnShow ( ) ;
} ,
methods : {
onDismiss ( ) {
this . popoverDismissed = true ;
2020-04-22 19:07:51 +05:30
setCookie ( this . dismissCookieName , this . popoverDismissed ) ;
2020-04-08 14:13:33 +05:30
} ,
trackOnShow ( ) {
if ( ! this . popoverDismissed ) this . track ( ) ;
} ,
} ,
} ;
< / script >
< template >
< gl -popover
v - if = "!popoverDismissed"
show
: target = "target"
2021-02-22 17:27:13 +05:30
placement = "right"
2020-04-08 14:13:33 +05:30
trigger = "manual"
container = "viewport"
: css - classes = "['suggest-gitlab-ci-yml', 'ml-4']"
>
< template # title >
2020-11-24 15:15:51 +05:30
< span > { { suggestTitle } } < / span >
2020-04-08 14:13:33 +05:30
< span class = "ml-auto" >
2020-10-24 23:57:45 +05:30
< gl -button
2020-04-22 19:07:51 +05:30
: aria - label = "__('Close')"
class = "btn-blank"
name = "dismiss"
2020-10-24 23:57:45 +05:30
icon = "close"
2020-04-22 19:07:51 +05:30
: data - track - property = "humanAccess"
: data - track - value = "$options.dismissTrackValue"
: data - track - event = "$options.clickTrackValue"
: data - track - label = "trackLabel"
@ click = "onDismiss"
2020-10-24 23:57:45 +05:30
/ >
2020-04-08 14:13:33 +05:30
< / span >
< / template >
2020-07-28 23:09:34 +05:30
< gl -sprintf :message ="suggestContent" / >
< div class = "mt-3" >
< gl -sprintf :message ="suggestFooter" >
< template # bold = "{ content }" >
< strong > { { content } } < / strong >
< / template >
< / g l - s p r i n t f >
< / div >
2020-04-08 14:13:33 +05:30
< / g l - p o p o v e r >
< / template >