summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_merge_request_widget/components/widget/widget_content_row.vue
blob: b64f9c148d1250d0fe85fb9633189d30b0405741 (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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<script>
import { GlLink } from '@gitlab/ui';
import { __ } from '~/locale';
import HelpPopover from '~/vue_shared/components/help_popover.vue';
import SafeHtml from '~/vue_shared/directives/safe_html';
import { EXTENSION_ICONS } from '../../constants';
import { generateText } from '../extensions/utils';
import ActionButtons from './action_buttons.vue';
import StatusIcon from './status_icon.vue';

export default {
  components: {
    StatusIcon,
    HelpPopover,
    GlLink,
    ActionButtons,
  },
  directives: {
    SafeHtml,
  },
  props: {
    level: {
      type: Number,
      required: true,
      validator: (value) => value === 2 || value === 3,
    },
    statusIconName: {
      type: String,
      required: false,
      default: '',
      validator: (value) => value === '' || Object.keys(EXTENSION_ICONS).includes(value),
    },
    widgetName: {
      type: String,
      required: true,
    },
    header: {
      type: [String, Array],
      required: false,
      default: '',
    },
    /**
     * @typedef {Object} helpPopover
     * @property {Object} options
     * @property {String} options.title
     * @property {Object} content
     * @property {String} content.text
     * @property {String} content.learnMorePath
     */
    helpPopover: {
      type: Object,
      required: false,
      default: null,
    },
    actionButtons: {
      type: Array,
      required: false,
      default: () => [],
    },
  },
  computed: {
    generatedHeader() {
      return generateText(Array.isArray(this.header) ? this.header[0] : this.header);
    },
    generatedSubheader() {
      return Array.isArray(this.header) && this.header[1] ? generateText(this.header[1]) : '';
    },
    shouldShowHeaderActions() {
      return Boolean(this.helpPopover) || this.actionButtons?.length > 0;
    },
    hasActionButtons() {
      return this.actionButtons.length > 0;
    },
  },
  i18n: {
    learnMore: __('Learn more'),
  },
};
</script>
<template>
  <div
    class="gl-w-full gl-display-flex"
    :class="{
      'gl-border-t gl-py-3 gl-pl-7 gl-align-items-baseline': level === 2,
      'gl-align-items-center': level === 3,
    }"
  >
    <status-icon
      v-if="statusIconName && !header"
      :level="2"
      :name="widgetName"
      :icon-name="statusIconName"
    />
    <div class="gl-w-full">
      <div class="gl-display-flex">
        <slot name="header">
          <div v-if="header" class="gl-mb-2">
            <strong v-safe-html="generatedHeader" class="gl-display-block"></strong
            ><span
              v-if="generatedSubheader"
              v-safe-html="generatedSubheader"
              class="gl-display-block"
            ></span>
          </div>
        </slot>
        <div
          v-if="shouldShowHeaderActions"
          class="gl-ml-auto gl-display-flex gl-align-items-baseline"
        >
          <help-popover
            v-if="helpPopover"
            :options="helpPopover.options"
            :class="{ 'gl-mr-3': hasActionButtons }"
            icon="information-o"
          >
            <template v-if="helpPopover.content">
              <p
                v-if="helpPopover.content.text"
                v-safe-html="helpPopover.content.text"
                class="gl-mb-0"
              ></p>
              <gl-link
                v-if="helpPopover.content.learnMorePath"
                :href="helpPopover.content.learnMorePath"
                target="_blank"
                class="gl-font-sm"
                >{{ $options.i18n.learnMore }}</gl-link
              >
            </template>
          </help-popover>
          <action-buttons
            v-if="hasActionButtons"
            :widget="widgetName"
            :tertiary-buttons="actionButtons"
          />
        </div>
      </div>
      <div class="gl-display-flex gl-align-items-baseline gl-w-full">
        <status-icon
          v-if="statusIconName && header"
          :level="2"
          :name="widgetName"
          :icon-name="statusIconName"
        />
        <slot name="body"></slot>
      </div>
    </div>
  </div>
</template>