summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/design_management/components/toolbar/index.vue
blob: 8d25d467d597cde29ad4bc9127276e6306095643 (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
<script>
import { GlButton, GlIcon } from '@gitlab/ui';
import { __, sprintf } from '~/locale';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import DesignNavigation from './design_navigation.vue';
import DeleteButton from '../delete_button.vue';
import permissionsQuery from '../../graphql/queries/design_permissions.query.graphql';
import { DESIGNS_ROUTE_NAME } from '../../router/constants';

export default {
  components: {
    GlButton,
    GlIcon,
    DesignNavigation,
    DeleteButton,
  },
  mixins: [timeagoMixin],
  props: {
    id: {
      type: String,
      required: true,
    },
    isDeleting: {
      type: Boolean,
      required: true,
    },
    filename: {
      type: String,
      required: false,
      default: '',
    },
    updatedAt: {
      type: String,
      required: false,
      default: null,
    },
    updatedBy: {
      type: Object,
      required: false,
      default: () => ({}),
    },
    isLatestVersion: {
      type: Boolean,
      required: true,
    },
    image: {
      type: String,
      required: true,
    },
  },
  data() {
    return {
      permissions: {
        createDesign: false,
      },
    };
  },
  inject: {
    projectPath: {
      default: '',
    },
    issueIid: {
      default: '',
    },
  },
  apollo: {
    permissions: {
      query: permissionsQuery,
      variables() {
        return {
          fullPath: this.projectPath,
          iid: this.issueIid,
        };
      },
      update: data => data.project.issue.userPermissions,
    },
  },
  computed: {
    updatedText() {
      return sprintf(__('Updated %{updated_at} by %{updated_by}'), {
        updated_at: this.timeFormatted(this.updatedAt),
        updated_by: this.updatedBy.name,
      });
    },
    canDeleteDesign() {
      return this.permissions.createDesign;
    },
  },
  DESIGNS_ROUTE_NAME,
};
</script>

<template>
  <header
    class="gl-display-flex gl-align-items-center gl-justify-content-space-between gl-bg-white gl-py-4 gl-pl-4 js-design-header"
  >
    <div class="gl-display-flex gl-align-items-center">
      <router-link
        :to="{
          name: $options.DESIGNS_ROUTE_NAME,
          query: $route.query,
        }"
        :aria-label="s__('DesignManagement|Go back to designs')"
        data-testid="close-design"
        class="gl-mr-5 gl-display-flex gl-align-items-center gl-justify-content-center text-plain"
      >
        <gl-icon name="close" />
      </router-link>
      <div class="gl-overflow-hidden gl-display-flex gl-align-items-center">
        <h2 class="gl-m-0 str-truncated-100 gl-font-base">{{ filename }}</h2>
        <small v-if="updatedAt" class="gl-text-gray-500">{{ updatedText }}</small>
      </div>
    </div>
    <design-navigation :id="id" class="gl-ml-auto gl-flex-shrink-0" />
    <gl-button :href="image" icon="download" />
    <delete-button
      v-if="isLatestVersion && canDeleteDesign"
      class="gl-ml-3"
      :is-deleting="isDeleting"
      button-variant="warning"
      button-icon="archive"
      button-category="secondary"
      @deleteSelectedDesigns="$emit('delete')"
    />
  </header>
</template>