summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/dashboard/projects/index/components/customize_homepage_banner.vue
blob: 99461475af0e004ed3631f576a0a1877fba7fb2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<script>
import { GlBanner } from '@gitlab/ui';
import axios from '~/lib/utils/axios_utils';
import { s__ } from '~/locale';
import Tracking from '~/tracking';

const trackingMixin = Tracking.mixin();

export default {
  components: {
    GlBanner,
  },
  mixins: [trackingMixin],
  inject: {
    svgPath: {
      default: '',
    },
    preferencesBehaviorPath: {
      default: '',
    },
    calloutsPath: {
      default: '',
    },
    calloutsFeatureId: {
      default: '',
    },
    trackLabel: {
      default: '',
    },
  },
  i18n: {
    title: s__('CustomizeHomepageBanner|Do you want to customize this page?'),
    body: s__(
      'CustomizeHomepageBanner|This page shows a list of your projects by default but it can be changed to show projects\' activity, groups, your to-do list, assigned issues, assigned merge requests, and more. You can change this under "Homepage content" in your preferences',
    ),
    button_text: s__('CustomizeHomepageBanner|Go to preferences'),
  },
  data() {
    return {
      visible: true,
      tracking: {
        label: this.trackLabel,
      },
    };
  },
  created() {
    this.$nextTick(() => {
      this.addTrackingAttributesToButton();
    });
  },
  mounted() {
    this.trackOnShow();
  },
  methods: {
    handleClose() {
      axios
        .post(this.calloutsPath, {
          feature_name: this.calloutsFeatureId,
        })
        .catch((e) => {
          // eslint-disable-next-line @gitlab/require-i18n-strings, no-console
          console.error('Failed to dismiss banner.', e);
        });

      this.visible = false;
      this.track('click_dismiss');
    },
    trackOnShow() {
      if (this.visible) this.track('show_home_page_banner');
    },
    addTrackingAttributesToButton() {
      // we can't directly add these on the button like we need to due to
      // button not being modifiable currently
      // https://gitlab.com/gitlab-org/gitlab-ui/-/blob/9209ec424e5cca14bc8a1b5c9fa12636d8c83dad/src/components/base/banner/banner.vue#L60
      const button = this.$refs.banner.$el.querySelector(
        `[href='${this.preferencesBehaviorPath}']`,
      );

      if (button) {
        button.setAttribute('data-track-action', 'click_go_to_preferences');
        button.setAttribute('data-track-label', this.trackLabel);
      }
    },
  },
};
</script>

<template>
  <gl-banner
    v-if="visible"
    ref="banner"
    :title="$options.i18n.title"
    :button-text="$options.i18n.button_text"
    :button-link="preferencesBehaviorPath"
    :svg-path="svgPath"
    @close="handleClose"
  >
    <p>
      {{ $options.i18n.body }}
    </p>
  </gl-banner>
</template>