summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/work_items/components/work_item_created_updated.vue
blob: d1a707f2a8a8619ef8a789e72b08ca50c2e88097 (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
<script>
import { GlAvatarLink, GlSprintf } from '@gitlab/ui';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
import { getWorkItemQuery } from '../utils';

export default {
  components: {
    GlAvatarLink,
    GlSprintf,
    TimeAgoTooltip,
  },
  props: {
    fetchByIid: {
      type: Boolean,
      required: true,
    },
    workItemId: {
      type: String,
      required: false,
      default: null,
    },
    workItemIid: {
      type: String,
      required: false,
      default: null,
    },
    fullPath: {
      type: String,
      required: false,
      default: null,
    },
  },
  computed: {
    createdAt() {
      return this.workItem?.createdAt || '';
    },
    updatedAt() {
      return this.workItem?.updatedAt || '';
    },
    author() {
      return this.workItem?.author ?? {};
    },
    authorId() {
      return getIdFromGraphQLId(this.author.id);
    },
    queryVariables() {
      return this.fetchByIid
        ? {
            fullPath: this.fullPath,
            iid: this.workItemIid,
          }
        : {
            id: this.workItemId,
          };
    },
  },
  apollo: {
    workItem: {
      query() {
        return getWorkItemQuery(this.fetchByIid);
      },
      variables() {
        return this.queryVariables;
      },
      skip() {
        return !this.workItemId && !this.workItemIid;
      },
      update(data) {
        const workItem = this.fetchByIid ? data.workspace.workItems.nodes[0] : data.workItem;
        return workItem ?? {};
      },
    },
  },
};
</script>

<template>
  <div class="gl-mb-3">
    <span data-testid="work-item-created">
      <gl-sprintf v-if="author.name" :message="__('Created %{timeAgo} by %{author}')">
        <template #timeAgo>
          <time-ago-tooltip :time="createdAt" />
        </template>
        <template #author>
          <gl-avatar-link
            class="js-user-link gl-text-body gl-font-weight-bold"
            :title="author.name"
            :data-user-id="authorId"
            :href="author.webUrl"
          >
            {{ author.name }}
          </gl-avatar-link>
        </template>
      </gl-sprintf>
      <gl-sprintf v-else-if="createdAt" :message="__('Created %{timeAgo}')">
        <template #timeAgo>
          <time-ago-tooltip :time="createdAt" />
        </template>
      </gl-sprintf>
    </span>

    <span
      v-if="updatedAt"
      class="gl-ml-5 gl-display-none gl-sm-display-inline-block"
      data-testid="work-item-updated"
    >
      <gl-sprintf :message="__('Updated %{timeAgo}')">
        <template #timeAgo>
          <time-ago-tooltip :time="updatedAt" />
        </template>
      </gl-sprintf>
    </span>
  </div>
</template>