summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pipelines/components/dag/dag_annotations.vue
blob: a1500166cdc585c124050122a44189fe559bc990 (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
<script>
import { GlButton } from '@gitlab/ui';
import { __ } from '~/locale';

export default {
  name: 'DagAnnotations',
  components: {
    GlButton,
  },
  props: {
    annotations: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      showList: true,
    };
  },
  computed: {
    linkText() {
      return this.showList ? __('Hide list') : __('Show list');
    },
    shouldShowLink() {
      return Object.keys(this.annotations).length > 1;
    },
    wrapperClasses() {
      return [
        'gl-display-flex',
        'gl-flex-direction-column',
        'gl-fixed',
        'gl-right-1',
        'gl-top-66vh',
        'gl-w-max-content',
        'gl-px-5',
        'gl-py-4',
        'gl-rounded-base',
        'gl-bg-white',
      ].join(' ');
    },
  },
  methods: {
    toggleList() {
      this.showList = !this.showList;
    },
  },
};
</script>
<template>
  <div :class="wrapperClasses">
    <div v-if="showList">
      <div
        v-for="note in annotations"
        :key="note.uid"
        class="gl-display-flex gl-align-items-center"
      >
        <div
          data-testid="dag-color-block"
          class="gl-w-6 gl-h-5"
          :style="{
            background: `linear-gradient(0.25turn, ${note.source.color} 40%, ${note.target.color} 60%)`,
          }"
        ></div>
        <div data-testid="dag-note-text" class="gl-px-2 gl-font-base gl-align-items-center">
          {{ note.source.name }} → {{ note.target.name }}
        </div>
      </div>
    </div>

    <gl-button v-if="shouldShowLink" variant="link" @click="toggleList">{{ linkText }}</gl-button>
  </div>
</template>