debian-mirror-gitlab/app/assets/javascripts/blob/suggest_gitlab_ci_yml/components/popover.vue

142 lines
3.6 KiB
Vue
Raw Normal View History

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|Were 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>
</gl-sprintf>
</div>
2020-04-08 14:13:33 +05:30
</gl-popover>
</template>