summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/monitoring/components/graph_group.vue
blob: 08fcfa3bc56bfa21ad0785cc433009fc88884d3d (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
<script>
import Icon from '~/vue_shared/components/icon.vue';

export default {
  components: {
    Icon,
  },
  props: {
    name: {
      type: String,
      required: true,
    },
    showPanels: {
      type: Boolean,
      required: false,
      default: true,
    },
    /**
     * Initial value of collapse on mount.
     */
    collapseGroup: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  data() {
    return {
      isCollapsed: this.collapseGroup,
    };
  },
  computed: {
    caretIcon() {
      return this.isCollapsed ? 'angle-right' : 'angle-down';
    },
  },
  watch: {
    collapseGroup(val) {
      // Respond to changes in collapseGroup but do not
      // collapse it once was opened by the user.
      if (this.showPanels && !val) {
        this.isCollapsed = false;
      }
    },
  },
  methods: {
    collapse() {
      this.isCollapsed = !this.isCollapsed;
    },
  },
};
</script>

<template>
  <div v-if="showPanels" ref="graph-group" class="card prometheus-panel" tabindex="0">
    <div class="card-header d-flex align-items-center">
      <h4 class="flex-grow-1">{{ name }}</h4>
      <a
        data-testid="group-toggle-button"
        role="button"
        class="js-graph-group-toggle gl-text-gray-900"
        tabindex="0"
        @click="collapse"
        @keyup.enter="collapse"
      >
        <icon :size="16" :aria-label="__('Toggle collapse')" :name="caretIcon" />
      </a>
    </div>
    <div
      v-show="!isCollapsed"
      ref="graph-group-content"
      class="card-body prometheus-graph-group p-0"
    >
      <slot></slot>
    </div>
  </div>
  <div v-else ref="graph-group-content" class="prometheus-graph-group"><slot></slot></div>
</template>